Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags list for repos whose release setting is disabled #23465

Merged
merged 16 commits into from
Apr 25, 2023
53 changes: 52 additions & 1 deletion routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
Expand All @@ -31,6 +32,7 @@ import (
const (
tplReleases base.TplName = "repo/release/list"
tplReleaseNew base.TplName = "repo/release/new"
tplTagsList base.TplName = "repo/tag/list"
)

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

// TagsList render tags list page
func TagsList(ctx *context.Context) {
releasesOrTags(ctx, true)
if ctx.Repo.CanAccess(perm.AccessModeRead, unit.TypeReleases) {
releasesOrTags(ctx, true)
} else {
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
tags(ctx)
}
}

func releasesOrTags(ctx *context.Context, isTagList bool) {
Expand Down Expand Up @@ -200,6 +206,51 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
ctx.HTML(http.StatusOK, tplReleases)
}

// tags render the tags list if repo's release is disabled.
func tags(ctx *context.Context) {
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["PageIsTagList"] = true
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["Title"] = ctx.Tr("repo.release.tags")

listOptions := db.ListOptions{
Page: ctx.FormInt("page"),
PageSize: ctx.FormInt("limit"),
}
if listOptions.PageSize == 0 {
listOptions.PageSize = setting.Repository.Release.DefaultPagingNum
}
if listOptions.PageSize > setting.API.MaxResponseItems {
listOptions.PageSize = setting.API.MaxResponseItems
}

opts := repo_model.FindReleasesOptions{
ListOptions: listOptions,
IncludeDrafts: true,
IncludeTags: true,
HasSha1: util.OptionalBoolTrue,
}

releases, err := repo_model.GetReleasesByRepoID(ctx, ctx.Repo.Repository.ID, opts)
if err != nil {
ctx.ServerError("GetReleasesByRepoID", err)
return
}

count, err := repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, opts)
if err != nil {
ctx.ServerError("GetReleaseCountByRepoID", err)
return
}

ctx.Data["Releases"] = releases
ctx.Data["ReleasesNum"] = len(releases)

pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager

ctx.HTML(http.StatusOK, tplTagsList)
}

// ReleasesFeedRSS get feeds for releases in RSS format
func ReleasesFeedRSS(ctx *context.Context) {
releasesOrTagsFeed(ctx, true, "rss")
Expand Down
6 changes: 5 additions & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ func RegisterRoutes(m *web.Route) {
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
}, reqSignIn, context.RepoAssignment, context.UnitTypes())

// Releases
// Tags
m.Group("/{username}/{reponame}", func() {
m.Group("/tags", func() {
m.Get("", repo.TagsList)
Expand All @@ -1177,6 +1177,10 @@ func RegisterRoutes(m *web.Route) {
}, func(ctx *context.Context) {
ctx.Data["EnableFeed"] = setting.EnableFeed
}, repo.MustBeNotEmpty, reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag, true))
}, reqSignIn, context.RepoAssignment, context.UnitTypes())
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved

// Releases
m.Group("/{username}/{reponame}", func() {
m.Group("/releases", func() {
m.Get("/", repo.Releases)
m.Get("/tag/*", repo.SingleRelease)
Expand Down
47 changes: 1 addition & 46 deletions templates/repo/release/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,7 @@
{{end}}
{{if .PageIsTagList}}
<div class="ui divider"></div>
{{if gt .ReleasesNum 0}}
<h4 class="ui top attached header">
<div class="five wide column gt-df gt-ac">
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
</div>
</h4>
<div class="ui attached table segment">
<table class="ui very basic striped fixed table single line" id="tags-table">
<thead></thead>
<tbody class="tag-list">
{{range $idx, $release := .Releases}}
<tr>
<td class="tag">
<h3 class="release-tag-name gt-mb-3">
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
</h3>
<div class="download gt-df gt-ac">
{{if $.Permission.CanRead $.UnitTypeCode}}
{{if .CreatedUnix}}
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
{{end}}
<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>
{{if not $.DisableDownloadSourceArchives}}
<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>
<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>
{{end}}
{{if (and $.CanCreateRelease $release.IsTag)}}
<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>
{{end}}
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
</a>
{{end}}
{{if (not $release.IsTag)}}
<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>
{{end}}
{{end}}
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{end}}
{{template "repo/tag/table" .}}
{{else}}
<ul id="release-list">
{{range $idx, $release := .Releases}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/sub_menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a href="{{.RepoLink}}/branches">{{svg "octicon-git-branch"}} <b>{{.BranchesCount}}</b> {{.locale.TrN .BranchesCount "repo.branch" "repo.branches"}}</a>
</div>
{{if $.Permission.CanRead $.UnitTypeCode}}
<div class="item">
<div class="item{{if .PageIsTagList}} active{{end}}">
<a href="{{.RepoLink}}/tags">{{svg "octicon-tag"}} <b>{{.NumTags}}</b> {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
</div>
{{end}}
Expand Down
13 changes: 13 additions & 0 deletions templates/repo/tag/list.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{/* This template is only used to show tags list when repo's release setting is disabled. */}}
Zettat123 marked this conversation as resolved.
Show resolved Hide resolved
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository release">
{{template "repo/header" .}}
<div class="ui container">
{{template "base/alert" .}}
{{template "repo/sub_menu" .}}
<div class="gt-mt-4">
{{template "repo/tag/table" .}}
</div>
</div>
</div>
{{template "base/footer" .}}
51 changes: 51 additions & 0 deletions templates/repo/tag/table.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{if gt .ReleasesNum 0}}
<h4 class="ui top attached header">
<div class="five wide column gt-df gt-ac">
{{svg "octicon-tag" 16 "gt-mr-2"}}{{.locale.Tr "repo.release.tags"}}
</div>
</h4>
<div class="ui attached table segment">
<table class="ui very basic striped fixed table single line" id="tags-table">
<tbody class="tag-list">
{{range $idx, $release := .Releases}}
<tr>
<td class="tag">
<h3 class="release-tag-name gt-mb-3">
{{if $.Permission.CanRead $.UnitTypeReleases}}
<a class="gt-df gt-ac" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
{{else}}
<a class="gt-df gt-ac" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
{{end}}
</h3>
<div class="download gt-df gt-ac">
{{if $.Permission.CanRead $.UnitTypeCode}}
{{if .CreatedUnix}}
<span class="gt-mr-3">{{svg "octicon-clock" 16 "gt-mr-2"}}{{TimeSinceUnix .CreatedUnix $.locale}}</span>
{{end}}
<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>
{{if not $.DisableDownloadSourceArchives}}
<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>
<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>
{{end}}
{{if $.Permission.CanRead $.UnitTypeReleases}}
{{if (and $.CanCreateRelease $release.IsTag)}}
<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>
{{end}}
{{if (and ($.Permission.CanWrite $.UnitTypeCode) $release.IsTag)}}
<a class="ui delete-button gt-mr-3 muted" data-url="{{$.RepoLink}}/tags/delete" data-id="{{.ID}}">
{{svg "octicon-trash" 16 "gt-mr-2"}}{{$.locale.Tr "repo.release.delete_tag"}}
</a>
{{end}}
{{if (not $release.IsTag)}}
<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>
{{end}}
{{end}}
{{end}}
</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{end}}