Skip to content

Commit b78c955

Browse files
authored
Fix tags view (#23243)
This PR fixes several issues reported in #23221. It does three things: 1. Fixes the `DefaultBranch` variable that has not been set. 2. Sets `Title` and `Message` for newly created tags from the Tag message. This makes it easier to create releases from tags that have messages and for those that don't it doesn't have any effect. 3. Makes UI changes so that tags look more like proper releases. Before: ![2023-03-02-12-31-19](https://user-images.githubusercontent.com/1718963/222416890-941a74d4-9cd0-4c45-a59e-199d2580cd8c.png) After: ![2023-03-02-12-31-31](https://user-images.githubusercontent.com/1718963/222416919-abce2009-8955-4cd0-9bed-1374582e04f7.png) I purposefully didn't reformat the template so that the diff is cleaner but can do so if that's welcome. Thanks for your time! --------- Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
1 parent 22fec16 commit b78c955

File tree

4 files changed

+38
-43
lines changed

4 files changed

+38
-43
lines changed

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ release = Release
10681068
releases = Releases
10691069
tag = Tag
10701070
released_this = released this
1071+
tagged_this = tagged this
10711072
file.title = %s at %s
10721073
file_raw = Raw
10731074
file_history = History
@@ -2287,6 +2288,7 @@ release.compare = Compare
22872288
release.edit = edit
22882289
release.ahead.commits = <strong>%d</strong> commits
22892290
release.ahead.target = to %s since this release
2291+
tag.ahead.target = to %s since this tag
22902292
release.source_code = Source Code
22912293
release.new_subheader = Releases organize project versions.
22922294
release.edit_subheader = Releases organize project versions.

routers/web/repo/release.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ func releasesOrTagsFeed(ctx *context.Context, isReleasesOnly bool, formatType st
226226

227227
// SingleRelease renders a single release's page
228228
func SingleRelease(ctx *context.Context) {
229-
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
230229
ctx.Data["PageIsReleaseList"] = true
230+
ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch
231231

232232
writeAccess := ctx.Repo.CanWrite(unit.TypeReleases)
233233
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived
@@ -241,6 +241,12 @@ func SingleRelease(ctx *context.Context) {
241241
ctx.ServerError("GetReleasesByRepoID", err)
242242
return
243243
}
244+
ctx.Data["PageIsSingleTag"] = release.IsTag
245+
if release.IsTag {
246+
ctx.Data["Title"] = release.TagName
247+
} else {
248+
ctx.Data["Title"] = release.Title
249+
}
244250

245251
err = repo_model.GetReleaseAttachments(ctx, release)
246252
if err != nil {

services/repository/push.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,20 @@ func pushUpdateAddTags(ctx context.Context, repo *repo_model.Repository, gitRepo
374374
rel, has := relMap[lowerTag]
375375

376376
if !has {
377+
parts := strings.SplitN(tag.Message, "\n", 2)
378+
note := ""
379+
if len(parts) > 1 {
380+
note = parts[1]
381+
}
377382
rel = &repo_model.Release{
378383
RepoID: repo.ID,
379-
Title: "",
384+
Title: parts[0],
380385
TagName: tags[i],
381386
LowerTagName: lowerTag,
382387
Target: "",
383388
Sha1: commit.ID.String(),
384389
NumCommits: commitsCount,
385-
Note: "",
390+
Note: note,
386391
IsDraft: false,
387392
IsPrerelease: false,
388393
IsTag: true,

templates/repo/release/list.tmpl

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
{{template "base/alert" .}}
66
<h2 class="ui compact small menu header">
77
{{if .Permission.CanRead $.UnitTypeReleases}}
8-
<a class="{{if (not .PageIsTagList)}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.Tr "repo.release.releases"}}</a>
8+
<a class="{{if (and (not .PageIsSingleTag) (not .PageIsTagList))}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.Tr "repo.release.releases"}}</a>
99
{{end}}
1010
{{if .Permission.CanRead $.UnitTypeCode}}
11-
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.Tr "repo.release.tags"}}</a>
11+
<a class="{{if (or .PageIsSingleTag .PageIsTagList)}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.Tr "repo.release.tags"}}</a>
1212
{{end}}
1313
</h2>
1414
{{if .EnableFeed}}
@@ -35,7 +35,7 @@
3535
<tr>
3636
<td class="tag">
3737
<h3 class="release-tag-name gt-mb-3">
38-
<a class="gt-df gt-ac" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
38+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
3939
</h3>
4040
<div class="download gt-df gt-ac">
4141
{{if $.Permission.CanRead $.UnitTypeCode}}
@@ -69,51 +69,15 @@
6969
{{range $idx, $release := .Releases}}
7070
<li class="ui grid">
7171
<div class="ui four wide column meta gt-mt-2">
72-
{{if .IsTag}}
73-
{{if .CreatedUnix}}<span class="time">{{TimeSinceUnix .CreatedUnix $.locale}}</span>{{end}}
74-
{{else}}
7572
<a class="gt-df gt-ac gt-je muted" href="{{if not .Sha1}}#{{else}}{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}}</a>
7673
{{if .Sha1}}
7774
<span class="commit">
7875
<a class="gt-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
7976
</span>
8077
{{template "repo/branch_dropdown" dict "root" $ "release" .}}
8178
{{end}}
82-
{{end}}
8379
</div>
8480
<div class="ui twelve wide column detail">
85-
{{if .IsTag}}
86-
<div class="gt-df gt-ac gt-sb gt-fw gt-mb-3">
87-
<h4 class="release-list-title gt-df gt-ac">
88-
<a class="gt-df gt-ac" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{svg "octicon-tag" 24 "gt-mr-3"}}{{.TagName}}</a>
89-
</h4>
90-
</div>
91-
<p class="text grey">
92-
{{if gt .Publisher.ID 0}}
93-
<span class="author">
94-
{{avatar $.Context .Publisher 20}}
95-
<a href="{{.Publisher.HomeLink}}">{{.Publisher.Name}}</a>
96-
</span>
97-
<span class="released">
98-
{{$.locale.Tr "repo.released_this"}}
99-
</span>
100-
{{if .CreatedUnix}}
101-
<span class="time">{{TimeSinceUnix .CreatedUnix $.locale}}</span>
102-
{{end}}
103-
|
104-
{{end}}
105-
<span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}{{if .Target}}...{{.Target | PathEscapeSegments}}{{end}}">{{$.locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{$.locale.Tr "repo.release.ahead.target" $.DefaultBranch}}</span>
106-
</p>
107-
<div class="download">
108-
{{if $.Permission.CanRead $.UnitTypeCode}}
109-
<a class="gt-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
110-
{{if not $.DisableDownloadSourceArchives}}
111-
<a class="archive-link muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.zip" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;ZIP</a>
112-
<a class="archive-link muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;TAR.GZ</a>
113-
{{end}}
114-
{{end}}
115-
</div>
116-
{{else}}
11781
<div class="gt-df gt-ac gt-sb gt-fw gt-mb-3">
11882
<h4 class="release-list-title gt-df gt-ac">
11983
<a href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}">{{.Title}}</a>
@@ -133,6 +97,24 @@
13397
{{end}}
13498
</div>
13599
</div>
100+
{{if .IsTag}}
101+
<p class="text grey">
102+
{{if gt .Publisher.ID 0}}
103+
<span class="author">
104+
{{avatar $.Context .Publisher 20}}
105+
<a href="{{.Publisher.HomeLink}}">{{.Publisher.Name}}</a>
106+
</span>
107+
<span class="released">
108+
{{$.locale.Tr "repo.tagged_this"}}
109+
</span>
110+
{{if .CreatedUnix}}
111+
<span class="time">{{TimeSinceUnix .CreatedUnix $.locale}}</span>
112+
{{end}}
113+
|
114+
{{end}}
115+
<span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}{{if .Target}}...{{.Target | PathEscapeSegments}}{{end}}">{{$.locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{$.locale.Tr "repo.tag.ahead.target" $.DefaultBranch}}</span>
116+
</p>
117+
{{else}}
136118
<p class="text grey">
137119
<span class="author">
138120
{{if .OriginalAuthor}}
@@ -154,6 +136,7 @@
154136
| <span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}...{{.Target | PathEscapeSegments}}">{{$.locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{$.locale.Tr "repo.release.ahead.target" .Target}}</span>
155137
{{end}}
156138
</p>
139+
{{end}}
157140
<div class="markup desc">
158141
{{Str2html .Note}}
159142
</div>
@@ -187,7 +170,6 @@
187170
{{end}}
188171
</ul>
189172
</details>
190-
{{end}}
191173
<span class="dot">&nbsp;</span>
192174
</div>
193175
</li>

0 commit comments

Comments
 (0)