Skip to content

Commit deafc1a

Browse files
committed
add tag list
1 parent 35cb786 commit deafc1a

File tree

6 files changed

+123
-49
lines changed

6 files changed

+123
-49
lines changed

routers/web/repo/release.go

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/models/db"
14+
"code.gitea.io/gitea/models/perm"
1415
repo_model "code.gitea.io/gitea/models/repo"
1516
"code.gitea.io/gitea/models/unit"
1617
user_model "code.gitea.io/gitea/models/user"
@@ -31,6 +32,7 @@ import (
3132
const (
3233
tplReleases base.TplName = "repo/release/list"
3334
tplReleaseNew base.TplName = "repo/release/new"
35+
tplTagsList base.TplName = "repo/tag/list"
3436
)
3537

3638
// calReleaseNumCommitsBehind calculates given release has how many commits behind release target.
@@ -68,7 +70,11 @@ func Releases(ctx *context.Context) {
6870

6971
// TagsList render tags list page
7072
func TagsList(ctx *context.Context) {
71-
releasesOrTags(ctx, true)
73+
if ctx.Repo.CanAccess(perm.AccessModeRead, unit.TypeReleases) {
74+
releasesOrTags(ctx, true)
75+
} else {
76+
tags(ctx)
77+
}
7278
}
7379

7480
func releasesOrTags(ctx *context.Context, isTagList bool) {
@@ -200,6 +206,51 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
200206
ctx.HTML(http.StatusOK, tplReleases)
201207
}
202208

209+
// tags render the tags list if repo's release is disabled.
210+
func tags(ctx *context.Context) {
211+
ctx.Data["PageIsTagList"] = true
212+
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
213+
214+
listOptions := db.ListOptions{
215+
Page: ctx.FormInt("page"),
216+
PageSize: ctx.FormInt("limit"),
217+
}
218+
if listOptions.PageSize == 0 {
219+
listOptions.PageSize = setting.Repository.Release.DefaultPagingNum
220+
}
221+
if listOptions.PageSize > setting.API.MaxResponseItems {
222+
listOptions.PageSize = setting.API.MaxResponseItems
223+
}
224+
225+
opts := repo_model.FindReleasesOptions{
226+
ListOptions: listOptions,
227+
IncludeDrafts: true,
228+
IncludeTags: true,
229+
HasSha1: util.OptionalBoolTrue,
230+
}
231+
232+
releases, err := repo_model.GetReleasesByRepoID(ctx, ctx.Repo.Repository.ID, opts)
233+
if err != nil {
234+
ctx.ServerError("GetReleasesByRepoID", err)
235+
return
236+
}
237+
238+
count, err := repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, opts)
239+
if err != nil {
240+
ctx.ServerError("GetReleaseCountByRepoID", err)
241+
return
242+
}
243+
244+
ctx.Data["Releases"] = releases
245+
ctx.Data["ReleasesNum"] = len(releases)
246+
247+
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
248+
pager.SetDefaultParams(ctx)
249+
ctx.Data["Page"] = pager
250+
251+
ctx.HTML(http.StatusOK, tplTagsList)
252+
}
253+
203254
// ReleasesFeedRSS get feeds for releases in RSS format
204255
func ReleasesFeedRSS(ctx *context.Context) {
205256
releasesOrTagsFeed(ctx, true, "rss")

routers/web/web.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ func RegisterRoutes(m *web.Route) {
11681168
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
11691169
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
11701170

1171-
// Releases
1171+
// Tags
11721172
m.Group("/{username}/{reponame}", func() {
11731173
m.Group("/tags", func() {
11741174
m.Get("", repo.TagsList)
@@ -1177,6 +1177,10 @@ func RegisterRoutes(m *web.Route) {
11771177
}, func(ctx *context.Context) {
11781178
ctx.Data["EnableFeed"] = setting.EnableFeed
11791179
}, repo.MustBeNotEmpty, reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag, true))
1180+
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
1181+
1182+
// Releases
1183+
m.Group("/{username}/{reponame}", func() {
11801184
m.Group("/releases", func() {
11811185
m.Get("/", repo.Releases)
11821186
m.Get("/tag/*", repo.SingleRelease)

templates/repo/release/list.tmpl

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,7 @@
2121
{{end}}
2222
{{if .PageIsTagList}}
2323
<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}}/releases/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}}
24+
{{template "repo/tag/table" .}}
7025
{{else}}
7126
<ul id="release-list">
7227
{{range $idx, $release := .Releases}}

templates/repo/sub_menu.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a 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 href="{{.RepoLink}}/tags">{{svg "octicon-tag"}} <b>{{.NumTags}}</b> {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
1515
</div>
1616
{{end}}

templates/repo/tag/list.tmpl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{/* This template is only used to show tags list when repo's release setting is disabled. */}}
2+
{{template "base/head" .}}
3+
<div role="main" aria-label="{{.Title}}" class="page-content repository release">
4+
{{template "repo/header" .}}
5+
<div class="ui container">
6+
{{template "base/alert" .}}
7+
{{template "repo/sub_menu" .}}
8+
<div class="gt-mt-4">
9+
{{template "repo/tag/table" .}}
10+
</div>
11+
</div>
12+
</div>
13+
{{template "base/footer" .}}

templates/repo/tag/table.tmpl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{if gt .ReleasesNum 0}}
2+
<h4 class="ui top attached header">
3+
<div class="five wide column gt-df gt-ac">
4+
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
5+
</div>
6+
</h4>
7+
<div class="ui attached table segment">
8+
<table class="ui very basic striped fixed table single line" id="tags-table">
9+
<tbody class="tag-list">
10+
{{range $idx, $release := .Releases}}
11+
<tr>
12+
<td class="tag">
13+
<h3 class="release-tag-name gt-mb-3">
14+
{{if $.Permission.CanRead $.UnitTypeReleases}}
15+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
16+
{{else}}
17+
<a class="gt-df gt-ac" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
18+
{{end}}
19+
</h3>
20+
<div class="download gt-df gt-ac">
21+
{{if $.Permission.CanRead $.UnitTypeCode}}
22+
{{if .CreatedUnix}}
23+
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
24+
{{end}}
25+
<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>
26+
{{if not $.DisableDownloadSourceArchives}}
27+
<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>
28+
<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>
29+
{{end}}
30+
{{if $.Permission.CanRead $.UnitTypeReleases}}
31+
{{if (and $.CanCreateRelease $release.IsTag)}}
32+
<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>
33+
{{end}}
34+
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
35+
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
36+
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
37+
</a>
38+
{{end}}
39+
{{if (not $release.IsTag)}}
40+
<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>
41+
{{end}}
42+
{{end}}
43+
{{end}}
44+
</div>
45+
</td>
46+
</tr>
47+
{{end}}
48+
</tbody>
49+
</table>
50+
</div>
51+
{{end}}

0 commit comments

Comments
 (0)