Skip to content

Commit 8e51fbc

Browse files
committed
fix: contains draft releases when listing tags
1 parent ec0a06e commit 8e51fbc

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

models/repo/release.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ type FindReleasesOptions struct {
200200
IsPreRelease util.OptionalBool
201201
IsDraft util.OptionalBool
202202
TagNames []string
203+
HasSha1 util.OptionalBool // useful to find draft releases which are created with existing tags
203204
}
204205

205206
func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
@@ -221,6 +222,13 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
221222
if !opts.IsDraft.IsNone() {
222223
cond = cond.And(builder.Eq{"is_draft": opts.IsDraft.IsTrue()})
223224
}
225+
if !opts.HasSha1.IsNone() {
226+
if opts.HasSha1.IsTrue() {
227+
cond = cond.And(builder.Neq{"sha1": ""})
228+
} else {
229+
cond = cond.And(builder.Eq{"sha1": ""})
230+
}
231+
}
224232
return cond
225233
}
226234

modules/context/repo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
524524
}
525525

526526
ctx.Data["NumTags"], err = repo_model.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{
527-
IncludeTags: true,
527+
IncludeDrafts: true,
528+
IncludeTags: true,
529+
HasSha1: util.OptionalBoolTrue, // only draft releases which are created with existing tags
528530
})
529531
if err != nil {
530532
ctx.ServerError("GetReleaseCountByRepoID", err)

routers/web/repo/release.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
118118

119119
opts := repo_model.FindReleasesOptions{
120120
ListOptions: listOptions,
121-
IncludeDrafts: writeAccess && !isTagList,
121+
IncludeDrafts: isTagList || writeAccess,
122122
IncludeTags: isTagList,
123123
}
124+
if isTagList {
125+
opts.HasSha1 = util.OptionalBoolTrue // only draft releases which are created with existing tags
126+
}
124127

125128
releases, err := repo_model.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
126129
if err != nil {

0 commit comments

Comments
 (0)