Skip to content

Commit e301e26

Browse files
authored
Add tags list for repos whose release setting is disabled (#23465) (#24369)
Backport #23465 Close #23427 Co-Author: @wxiaoguang If a repo's release setting is enabled, the logic has't changed. Clicking the "Tags" button will jump to `/{user}/{repo}/tags` and `templates/repo/release/list.tmpl` template will be used. <img src="https://user-images.githubusercontent.com/15528715/224939362-bd8974fd-08b0-4f79-a114-3389d15847ca.png" width="600px" /> If the release setting is disabled, clicking the "Tags" button will still jump to `/{user}/{repo}/tags` but a new template `templates/repo/tag/list.tmpl` will be used. <img src="https://user-images.githubusercontent.com/15528715/233834564-74741e49-f4e9-47c8-ac12-e306642798dc.png" width="600px" /> Since both templates above need to render the tags list, I moved the tags list to a shared template located in `templates/repo/tag/table.tmpl`.
1 parent d2efd2b commit e301e26

File tree

9 files changed

+280
-231
lines changed

9 files changed

+280
-231
lines changed

routers/web/repo/release.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import (
2929
)
3030

3131
const (
32-
tplReleases base.TplName = "repo/release/list"
33-
tplReleaseNew base.TplName = "repo/release/new"
32+
tplReleasesList base.TplName = "repo/release/list"
33+
tplReleaseNew base.TplName = "repo/release/new"
34+
tplTagsList base.TplName = "repo/tag/list"
3435
)
3536

3637
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
@@ -58,31 +59,26 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *repo_model
5859

5960
// Releases render releases list page
6061
func Releases(ctx *context.Context) {
62+
ctx.Data["PageIsReleaseList"] = true
63+
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
6164
releasesOrTags(ctx, false)
6265
}
6366

6467
// TagsList render tags list page
6568
func TagsList(ctx *context.Context) {
69+
ctx.Data["PageIsTagList"] = true
70+
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
6671
releasesOrTags(ctx, true)
6772
}
6873

6974
func releasesOrTags(ctx *context.Context, isTagList bool) {
70-
ctx.Data["PageIsReleaseList"] = true
7175
ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch
7276
ctx.Data["IsViewBranch"] = false
7377
ctx.Data["IsViewTag"] = true
7478
// Disable the showCreateNewBranch form in the dropdown on this page.
7579
ctx.Data["CanCreateBranch"] = false
7680
ctx.Data["HideBranchesInDropdown"] = true
7781

78-
if isTagList {
79-
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
80-
ctx.Data["PageIsTagList"] = true
81-
} else {
82-
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
83-
ctx.Data["PageIsTagList"] = false
84-
}
85-
8682
listOptions := db.ListOptions{
8783
Page: ctx.FormInt("page"),
8884
PageSize: ctx.FormInt("limit"),
@@ -192,7 +188,11 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
192188
pager.SetDefaultParams(ctx)
193189
ctx.Data["Page"] = pager
194190

195-
ctx.HTML(http.StatusOK, tplReleases)
191+
if isTagList {
192+
ctx.HTML(http.StatusOK, tplTagsList)
193+
} else {
194+
ctx.HTML(http.StatusOK, tplReleasesList)
195+
}
196196
}
197197

198198
// ReleasesFeedRSS get feeds for releases in RSS format
@@ -270,7 +270,7 @@ func SingleRelease(ctx *context.Context) {
270270
}
271271

272272
ctx.Data["Releases"] = []*repo_model.Release{release}
273-
ctx.HTML(http.StatusOK, tplReleases)
273+
ctx.HTML(http.StatusOK, tplReleasesList)
274274
}
275275

276276
// LatestRelease redirects to the latest release

routers/web/web.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ func RegisterRoutes(m *web.Route) {
12151215
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
12161216
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
12171217

1218-
// Releases
1218+
// Tags
12191219
m.Group("/{username}/{reponame}", func() {
12201220
m.Group("/tags", func() {
12211221
m.Get("", repo.TagsList)
@@ -1224,6 +1224,12 @@ func RegisterRoutes(m *web.Route) {
12241224
}, func(ctx *context.Context) {
12251225
ctx.Data["EnableFeed"] = setting.EnableFeed
12261226
}, repo.MustBeNotEmpty, reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag, true))
1227+
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
1228+
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
1229+
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
1230+
1231+
// Releases
1232+
m.Group("/{username}/{reponame}", func() {
12271233
m.Group("/releases", func() {
12281234
m.Get("/", repo.Releases)
12291235
m.Get("/tag/*", repo.SingleRelease)
@@ -1241,8 +1247,6 @@ func RegisterRoutes(m *web.Route) {
12411247
m.Post("/attachments", repo.UploadReleaseAttachment)
12421248
m.Post("/attachments/remove", repo.DeleteAttachment)
12431249
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, context.RepoRef())
1244-
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
1245-
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
12461250
m.Group("/releases", func() {
12471251
m.Get("/edit/*", repo.EditRelease)
12481252
m.Post("/edit/*", web.Bind(forms.EditReleaseForm{}), repo.EditReleasePost)

templates/repo/release/list.tmpl

+5-63
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,15 @@
11
{{template "base/head" .}}
2-
<div role="main" aria-label="{{.Title}}" class="page-content repository release">
2+
<div role="main" aria-label="{{.Title}}" class="page-content repository releases">
33
{{template "repo/header" .}}
44
<div class="ui container">
55
{{template "base/alert" .}}
6-
<h2 class="ui compact small menu header">
7-
{{if .Permission.CanRead $.UnitTypeReleases}}
8-
<a class="{{if (not .PageIsTagList)}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.Tr "repo.release.releases"}}</a>
9-
{{end}}
10-
{{if .Permission.CanRead $.UnitTypeCode}}
11-
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.Tr "repo.release.tags"}}</a>
12-
{{end}}
13-
</h2>
14-
{{if .EnableFeed}}
15-
<a href="{{.RepoLink}}/{{if .PageIsTagList}}tags{{else}}releases{{end}}.rss"><i class="ui grey icon tooltip gt-ml-3" data-content="{{.locale.Tr "rss_feed"}}" data-position="top center">{{svg "octicon-rss" 18}}</i></a>
16-
{{end}}
17-
{{if (and .CanCreateRelease (not .PageIsTagList))}}
6+
{{template "repo/sub_menu_release_tag" .}}
7+
8+
{{if .CanCreateRelease}}
189
<a class="ui right small green button" href="{{$.RepoLink}}/releases/new">
1910
{{.locale.Tr "repo.release.new_release"}}
2011
</a>
2112
{{end}}
22-
{{if .PageIsTagList}}
23-
<div class="ui divider"></div>
24-
{{if gt .ReleasesNum 0}}
25-
<h4 class="ui top attached header">
26-
<div class="five wide column gt-df gt-ac">
27-
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
28-
</div>
29-
</h4>
30-
<div class="ui attached table segment">
31-
<table class="ui very basic striped fixed table single line" id="tags-table">
32-
<thead></thead>
33-
<tbody class="tag-list">
34-
{{range $idx, $release := .Releases}}
35-
<tr>
36-
<td class="tag">
37-
<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>
39-
</h3>
40-
<div class="download gt-df gt-ac">
41-
{{if $.Permission.CanRead $.UnitTypeCode}}
42-
{{if .CreatedUnix}}
43-
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
44-
{{end}}
45-
<a class="gt-mr-3 gt-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
46-
{{if not $.DisableDownloadSourceArchives}}
47-
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}ZIP</a>
48-
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}TAR.GZ</a>
49-
{{end}}
50-
{{if (and $.CanCreateRelease $release.IsTag)}}
51-
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/new?tag={{.TagName}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.new_release"}}</a>
52-
{{end}}
53-
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
54-
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
55-
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
56-
</a>
57-
{{end}}
58-
{{if (not $release.IsTag)}}
59-
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.detail"}}</a>
60-
{{end}}
61-
{{end}}
62-
</div>
63-
</td>
64-
</tr>
65-
{{end}}
66-
</tbody>
67-
</table>
68-
</div>
69-
{{end}}
70-
{{else}}
7113
<ul id="release-list">
7214
{{range $idx, $release := .Releases}}
7315
<li class="ui grid">
@@ -196,7 +138,7 @@
196138
</li>
197139
{{end}}
198140
</ul>
199-
{{end}}
141+
200142
{{template "base/paginate" .}}
201143
</div>
202144
</div>

templates/repo/sub_menu.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a class="ui" href="{{.RepoLink}}/branches">{{svg "octicon-git-branch"}} <b>{{.BranchesCount}}</b> {{.locale.TrN .BranchesCount "repo.branch" "repo.branches"}}</a>
1111
</div>
1212
{{if $.Permission.CanRead $.UnitTypeCode}}
13-
<div class="item">
13+
<div class="item{{if .PageIsTagList}} active{{end}}">
1414
<a class="ui" href="{{.RepoLink}}/tags">{{svg "octicon-tag"}} <b>{{.NumTags}}</b> {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
1515
</div>
1616
{{end}}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{$canReadReleases := $.Permission.CanRead $.UnitTypeReleases}}
2+
{{$canReadCode := $.Permission.CanRead $.UnitTypeCode}}
3+
4+
{{if $canReadReleases}}
5+
<h2 class="ui compact small menu header">
6+
<a class="{{if .PageIsReleaseList}}active {{end}}item" href="{{.RepoLink}}/releases">{{.locale.Tr "repo.release.releases"}}</a>
7+
{{if $canReadCode}}
8+
<a class="{{if .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/tags">{{.locale.Tr "repo.release.tags"}}</a>
9+
{{end}}
10+
</h2>
11+
12+
{{if .EnableFeed}}
13+
<a href="{{.RepoLink}}/{{if .PageIsTagList}}tags{{else}}releases{{end}}.rss"><i class="ui grey icon gt-ml-3" data-tooltip-content="{{.locale.Tr "rss_feed"}}">{{svg "octicon-rss" 18}}</i></a>
14+
{{end}}
15+
{{else if $canReadCode}}
16+
{{template "repo/sub_menu" .}}
17+
{{end}}

templates/repo/tag/list.tmpl

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{{template "base/head" .}}
2+
3+
<div role="main" aria-label="{{.Title}}" class="page-content repository tags">
4+
{{template "repo/header" .}}
5+
<div class="ui container">
6+
{{template "base/alert" .}}
7+
{{template "repo/sub_menu_release_tag" .}}
8+
9+
<div class="ui divider"></div>
10+
11+
<h4 class="ui top attached header">
12+
<div class="five wide column gt-df gt-ac">
13+
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
14+
</div>
15+
</h4>
16+
17+
{{$canReadReleases := $.Permission.CanRead $.UnitTypeReleases}}
18+
19+
<div class="ui attached table segment">
20+
<table class="ui very basic striped fixed table single line" id="tags-table">
21+
<tbody class="tag-list">
22+
{{range $idx, $release := .Releases}}
23+
<tr>
24+
<td class="tag">
25+
<h3 class="release-tag-name gt-mb-3">
26+
{{if $canReadReleases}}
27+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
28+
{{else}}
29+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
30+
{{end}}
31+
</h3>
32+
<div class="download gt-df gt-ac">
33+
{{if $.Permission.CanRead $.UnitTypeCode}}
34+
{{if .CreatedUnix}}
35+
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
36+
{{end}}
37+
38+
<a class="gt-mr-3 gt-mono muted" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
39+
40+
{{if not $.DisableDownloadSourceArchives}}
41+
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.zip" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}ZIP</a>
42+
<a class="archive-link gt-mr-3 muted" href="{{$.RepoLink}}/archive/{{.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "gt-mr-2"}}TAR.GZ</a>
43+
{{end}}
44+
45+
{{if (and $canReadReleases $.CanCreateRelease $release.IsTag)}}
46+
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/new?tag={{.TagName}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.new_release"}}</a>
47+
{{end}}
48+
49+
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
50+
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
51+
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
52+
</a>
53+
{{end}}
54+
55+
{{if and $canReadReleases (not $release.IsTag)}}
56+
<a class="gt-mr-3 muted" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}">{{svg "octicon-tag" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.detail"}}</a>
57+
{{end}}
58+
{{end}}
59+
</div>
60+
</td>
61+
</tr>
62+
{{end}}
63+
</tbody>
64+
</table>
65+
</div>
66+
67+
{{template "base/paginate" .}}
68+
</div>
69+
</div>
70+
71+
{{if $.Permission.CanWrite $.UnitTypeCode}}
72+
<div class="ui small basic delete modal">
73+
<div class="ui header">
74+
{{svg "octicon-trash" 16 "gt-mr-2"}}
75+
{{.locale.Tr "repo.release.delete_tag"}}
76+
</div>
77+
<div class="content">
78+
<p>{{.locale.Tr "repo.release.deletion_tag_desc"}}</p>
79+
</div>
80+
{{template "base/delete_modal_actions" .}}
81+
</div>
82+
{{end}}
83+
84+
85+
{{template "base/footer" .}}

web_src/css/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@import "./install.css";
2929
@import "./form.css";
3030
@import "./repository.css";
31+
@import "./repository-release-tag.css";
3132
@import "./editor.css";
3233
@import "./organization.css";
3334
@import "./user.css";

0 commit comments

Comments
 (0)