Skip to content

Commit ef6ad26

Browse files
committed
Add tag name in the commits list
1 parent 2ced31e commit ef6ad26

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Diff for: models/repo/release.go

+13
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,16 @@ func InsertReleases(ctx context.Context, rels ...*Release) error {
563563

564564
return committer.Commit()
565565
}
566+
567+
func FindTagsByCommitIDs(ctx context.Context, repoID int64, commitIDs ...string) (map[string][]*Release, error) {
568+
releases := make([]*Release, 0, len(commitIDs))
569+
if err := db.GetEngine(ctx).Where("repo_id=?", repoID).
570+
In("sha1", commitIDs).Find(&releases); err != nil {
571+
return nil, err
572+
}
573+
res := make(map[string][]*Release, len(releases))
574+
for _, r := range releases {
575+
res[r.Sha1] = append(res[r.Sha1], r)
576+
}
577+
return res, nil
578+
}

Diff for: routers/web/repo/commit.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,18 @@ func Commits(ctx *context.Context) {
8181
ctx.ServerError("CommitsByRange", err)
8282
return
8383
}
84-
ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
8584

85+
ctx.Data["Commits"] = git_model.ConvertFromGitCommit(ctx, commits, ctx.Repo.Repository)
86+
commitIDs := make([]string, 0, len(commits))
87+
for _, c := range commits {
88+
commitIDs = append(commitIDs, c.ID.String())
89+
}
90+
commitsTagsMap, err := repo_model.FindTagsByCommitIDs(ctx, ctx.Repo.Repository.ID, commitIDs...)
91+
if err != nil {
92+
ctx.ServerError("CommitsByRange", err)
93+
return
94+
}
95+
ctx.Data["CommitsTagsMap"] = commitsTagsMap
8696
ctx.Data["Username"] = ctx.Repo.Owner.Name
8797
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
8898
ctx.Data["CommitCount"] = commitsCount

Diff for: templates/repo/commits_list.tmpl

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
{{if IsMultilineCommitMessage .Message}}
7373
<pre class="commit-body tw-hidden">{{RenderCommitBody $.Context .Message ($.Repository.ComposeMetas ctx)}}</pre>
7474
{{end}}
75+
{{range (index $.CommitsTagsMap .ID.String)}}
76+
<span class="ui label">{{.TagName}}</span>
77+
{{end}}
7578
</td>
7679
{{if .Committer}}
7780
<td class="text right aligned">{{TimeSince .Committer.When ctx.Locale}}</td>

0 commit comments

Comments
 (0)