Skip to content

Commit a08b484

Browse files
wolfogrewxiaoguang
andauthored
Tag list should include draft releases with existing tags (#21263)
Before, a tag for a draft release disappeared in the tag list, fix #21262. Co-authored-by: wxiaoguang <[email protected]>
1 parent af849ac commit a08b484

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
117117
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived
118118

119119
opts := repo_model.FindReleasesOptions{
120-
ListOptions: listOptions,
121-
IncludeDrafts: writeAccess && !isTagList,
122-
IncludeTags: isTagList,
120+
ListOptions: listOptions,
121+
}
122+
if isTagList {
123+
// for the tags list page, show all releases with real tags (having real commit-id),
124+
// the drafts should also be included because a real tag might be used as a draft.
125+
opts.IncludeDrafts = true
126+
opts.IncludeTags = true
127+
opts.HasSha1 = util.OptionalBoolTrue
128+
} else {
129+
// only show draft releases for users who can write, read-only users shouldn't see draft releases.
130+
opts.IncludeDrafts = writeAccess
123131
}
124132

125133
releases, err := repo_model.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)

templates/repo/release/list.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,12 @@
7777
<span class="ui green label">{{$.locale.Tr "repo.release.stable"}}</span>
7878
{{end}}
7979
<span class="tag text blue">
80-
<a class="df ac je" href="{{if .IsDraft}}#{{else}}{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "mr-2"}}{{.TagName}}</a>
80+
<a class="df ac je" href="{{if not .Sha1}}#{{else}}{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "mr-2"}}{{.TagName}}</a>
8181
</span>
82-
{{if not .IsDraft}}
82+
{{if .Sha1}}
8383
<span class="commit">
8484
<a class="mono" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "mr-2"}}{{ShortSha .Sha1}}</a>
8585
</span>
86-
{{end}}
87-
{{if .Sha1}}
8886
{{template "repo/branch_dropdown" dict "root" $ "release" .}}
8987
{{end}}
9088
{{end}}

0 commit comments

Comments
 (0)