Skip to content

Commit 0d7b4f9

Browse files
committed
Update tag commits count when necessary
1 parent aac26aa commit 0d7b4f9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

models/repo/release.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func UpdateRelease(ctx context.Context, rel *Release) error {
161161
return err
162162
}
163163

164+
func UpdateReleaseNumCommits(ctx context.Context, rel *Release) error {
165+
_, err := db.GetEngine(ctx).ID(rel.ID).Cols("num_commits").Update(rel)
166+
return err
167+
}
168+
164169
// AddReleaseAttachments adds a release attachments
165170
func AddReleaseAttachments(ctx context.Context, releaseID int64, attachmentUUIDs []string) (err error) {
166171
// Check attachments

services/context/repo.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,15 @@ func RepoRefByType(detectRefType git.RefType) func(*Context) {
936936
ctx.ServerError("GetCommitsCount", err)
937937
return
938938
}
939+
if ctx.Repo.RefFullName.IsTag() {
940+
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, ctx.Repo.RefFullName.TagName())
941+
if err == nil && rel.NumCommits <= 0 {
942+
rel.NumCommits = ctx.Repo.CommitsCount
943+
if err := repo_model.UpdateReleaseNumCommits(ctx, rel); err != nil {
944+
log.Error("UpdateReleaseNumCommits", err)
945+
}
946+
}
947+
}
939948
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
940949
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
941950
}

templates/repo/release/list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
{{if $release.CreatedUnix}}
6262
<span class="time">{{DateUtils.TimeSince $release.CreatedUnix}}</span>
6363
{{end}}
64-
{{if and (not $release.IsDraft) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
64+
{{if and (gt $release.NumCommits 0) (not $release.IsDraft) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
6565
| <span class="ahead"><a href="{{$.RepoLink}}/compare/{{$release.TagName | PathEscapeSegments}}...{{$release.TargetBehind | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.release.ahead.commits" $release.NumCommitsBehind}}</a> {{ctx.Locale.Tr "repo.release.ahead.target" $release.TargetBehind}}</span>
6666
{{end}}
6767
</p>

0 commit comments

Comments
 (0)