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 the tag list page to the release page #12096

Merged
merged 40 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a3cf5ee
Add the tag list page to the release page
a1012112796 Jul 3, 2020
39b758d
Merge branch 'master' into delet_tag
a1012112796 Jul 3, 2020
769ec24
Apply suggestions from code review
a1012112796 Jul 13, 2020
933f054
Apply suggestions from code review
a1012112796 Aug 1, 2020
6ae860d
Merge branch 'master' into delet_tag
a1012112796 Aug 2, 2020
5d9acc1
fix ui
a1012112796 Aug 2, 2020
9671577
Merge branch 'master' into delet_tag
a1012112796 Sep 6, 2020
631cf72
Add to header
a1012112796 Sep 12, 2020
21e7a0d
Merge branch 'master' into delet_tag
a1012112796 Sep 12, 2020
ac123b3
Merge branch 'master' into delet_tag
zeripath Sep 13, 2020
574e175
ui
a1012112796 Sep 15, 2020
b792dfe
Merge branch 'master' into delet_tag
a1012112796 Sep 15, 2020
65f9514
permission
a1012112796 Sep 17, 2020
0846ca9
ui
a1012112796 Sep 17, 2020
3b6d6d8
Merge branch 'master' into delet_tag
a1012112796 Sep 17, 2020
b633378
Update options/locale/locale_en-US.ini
a1012112796 Sep 20, 2020
5f3e713
Merge branch 'master' into delet_tag
a1012112796 Sep 20, 2020
f90cabf
tweaks
silverwind Sep 20, 2020
333f6bd
monospace commit hashes
silverwind Sep 20, 2020
125d730
Merge branch 'silverwind/delet_tag' into delet_tag
a1012112796 Sep 20, 2020
a04e626
Merge branch 'master' into delet_tag
a1012112796 Sep 21, 2020
e6e2338
Merge branch 'master' into delet_tag
lafriks Sep 21, 2020
4d15d6b
Merge branch 'master' into delet_tag
zeripath Sep 29, 2020
1a3962a
Merge branch 'master' into delet_tag
a1012112796 Oct 3, 2020
d848526
Add read permission check
a1012112796 Oct 3, 2020
8612e71
Merge branch 'master' into delet_tag
a1012112796 Oct 22, 2020
58d14a5
fix permission
a1012112796 Oct 22, 2020
cc92b0a
fix nit
a1012112796 Oct 22, 2020
e8d8307
Update web_src/less/_base.less
zeripath Oct 22, 2020
abe54bf
Merge branch 'master' into delet_tag
a1012112796 Nov 1, 2020
74a04ac
ui fixes
silverwind Nov 1, 2020
71aa21e
title tweaks
silverwind Nov 1, 2020
28d6979
Merge remote-tracking branch 'silverwind/delet_tag' into delet_tag
a1012112796 Nov 2, 2020
e861787
Merge branch 'master' into delet_tag
a1012112796 Nov 2, 2020
0b5d6a9
fix lint
a1012112796 Nov 2, 2020
c1b5144
fix test
a1012112796 Nov 2, 2020
84525ce
fix test and some ui nits
a1012112796 Nov 2, 2020
4cd0000
Merge branch 'master' into delet_tag
lafriks Nov 2, 2020
37071c8
Apply suggestions from code review
a1012112796 Nov 2, 2020
e6baba6
Merge branch 'master' into delet_tag
lafriks Nov 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions integrations/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, ver
htmlDoc := NewHTMLParser(t, resp.Body)
labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
assert.EqualValues(t, label, labelText)
titleText := htmlDoc.doc.Find("#release-list > li .detail h3 a").First().Text()
titleText := htmlDoc.doc.Find("#release-list > li .detail h4 a").First().Text()
assert.EqualValues(t, version, titleText)

releaseList := htmlDoc.doc.Find("#release-list > li")
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestCreateRelease(t *testing.T) {
session := loginUser(t, "user2")
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)

checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 3)
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 2)
}

func TestCreateReleasePreRelease(t *testing.T) {
Expand All @@ -92,7 +92,7 @@ func TestCreateReleasePreRelease(t *testing.T) {
session := loginUser(t, "user2")
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)

checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 3)
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 2)
}

func TestCreateReleaseDraft(t *testing.T) {
Expand All @@ -101,7 +101,7 @@ func TestCreateReleaseDraft(t *testing.T) {
session := loginUser(t, "user2")
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)

checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 3)
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 2)
}

func TestCreateReleasePaging(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ func (r *Release) loadAttributes(e Engine) error {
if r.Publisher == nil {
r.Publisher, err = getUserByID(e, r.PublisherID)
if err != nil {
return err
if IsErrUserNotExist(err) {
r.Publisher = NewGhostUser()
} else {
return err
}
}
}
return getReleaseAttachments(e, r)
Expand Down
10 changes: 9 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,9 @@ org_labels_desc_manage = manage
milestones = Milestones
commits = Commits
commit = Commit
release = Release
releases = Releases
released_this = released this
file_raw = Raw
file_history = History
file_view_raw = View Raw
Expand Down Expand Up @@ -1796,6 +1798,8 @@ diff.protected = Protected

releases.desc = Track project versions and downloads.
release.releases = Releases
release.detail = Release details
release.tags = Tags
release.new_release = New Release
release.draft = Draft
release.prerelease = Pre-Release
Expand All @@ -1818,11 +1822,15 @@ release.publish = Publish Release
release.save_draft = Save Draft
release.edit_release = Update Release
release.delete_release = Delete Release
release.delete_tag = Delete Tag
release.deletion = Delete Release
release.deletion_desc = Deleting a release removes its Git tag from the repository. Repository contents and history remain unchanged. Continue?
release.deletion_desc = Deleting a release only removes it from Gitea. Git tag, repository contents and history remain unchanged. Continue?
release.deletion_success = The release has been deleted.
release.deletion_tag_desc = Will delete this tag from repository. Repository contents and history remain unchanged. Continue?
release.deletion_tag_success = The tag has been deleted.
release.tag_name_already_exist = A release with this tag name already exists.
release.tag_name_invalid = The tag name is not valid.
release.tag_already_exist = This tag name already exists.
release.downloads = Downloads
release.download_count = Downloads: %s

Expand Down
62 changes: 56 additions & 6 deletions routers/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,26 @@ func calReleaseNumCommitsBehind(repoCtx *context.Repository, release *models.Rel

// Releases render releases list page
func Releases(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
releasesOrTags(ctx, false)
}

// TagsList render tags list page
func TagsList(ctx *context.Context) {
releasesOrTags(ctx, true)
}

func releasesOrTags(ctx *context.Context, isTagList bool) {
ctx.Data["PageIsReleaseList"] = true
ctx.Data["DefaultBranch"] = ctx.Repo.Repository.DefaultBranch

if isTagList {
ctx.Data["Title"] = ctx.Tr("repo.release.tags")
ctx.Data["PageIsTagList"] = true
} else {
ctx.Data["Title"] = ctx.Tr("repo.release.releases")
ctx.Data["PageIsTagList"] = false
}

writeAccess := ctx.Repo.CanWrite(models.UnitTypeReleases)
ctx.Data["CanCreateRelease"] = writeAccess && !ctx.Repo.Repository.IsArchived

Expand All @@ -68,7 +84,7 @@ func Releases(ctx *context.Context) {
PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
},
IncludeDrafts: writeAccess,
IncludeTags: true,
IncludeTags: isTagList,
}

releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, opts)
Expand All @@ -83,8 +99,7 @@ func Releases(ctx *context.Context) {
return
}

err = models.GetReleaseAttachments(releases...)
if err != nil {
if err = models.GetReleaseAttachments(releases...); err != nil {
ctx.ServerError("GetReleaseAttachments", err)
return
}
Expand Down Expand Up @@ -118,6 +133,7 @@ func Releases(ctx *context.Context) {
}

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

pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
pager.SetDefaultParams(ctx)
Expand Down Expand Up @@ -194,6 +210,20 @@ func NewRelease(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
if tagName := ctx.Query("tag"); len(tagName) > 0 {
rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)
if err != nil && !models.IsErrReleaseNotExist(err) {
ctx.ServerError("GetRelease", err)
return
}

if rel != nil {
ctx.Data["tag_name"] = rel.TagName
ctx.Data["tag_target"] = rel.Target
ctx.Data["title"] = rel.Title
ctx.Data["content"] = rel.Note
}
}
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
upload.AddUploadContext(ctx, "release")
ctx.HTML(200, tplReleaseNew)
Expand Down Expand Up @@ -354,10 +384,30 @@ func EditReleasePost(ctx *context.Context, form auth.EditReleaseForm) {

// DeleteRelease delete a release
func DeleteRelease(ctx *context.Context) {
if err := releaseservice.DeleteReleaseByID(ctx.QueryInt64("id"), ctx.User, true); err != nil {
deleteReleaseOrTag(ctx, false)
}

// DeleteTag delete a tag
func DeleteTag(ctx *context.Context) {
deleteReleaseOrTag(ctx, true)
}

func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
if err := releaseservice.DeleteReleaseByID(ctx.QueryInt64("id"), ctx.User, isDelTag); err != nil {
ctx.Flash.Error("DeleteReleaseByID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
if isDelTag {
ctx.Flash.Success(ctx.Tr("repo.release.deletion_tag_success"))
} else {
ctx.Flash.Success(ctx.Tr("repo.release.deletion_success"))
}
}

if isDelTag {
ctx.JSON(200, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/tags",
})
return
}

ctx.JSON(200, map[string]interface{}{
Expand Down
6 changes: 5 additions & 1 deletion routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,19 +896,23 @@ func RegisterRoutes(m *macaron.Macaron) {

// Releases
m.Group("/:username/:reponame", func() {
m.Get("/tags", repo.TagsList, repo.MustBeNotEmpty,
reqRepoCodeReader, context.RepoRefByType(context.RepoRefTag))
m.Group("/releases", func() {
m.Get("/", repo.Releases)
m.Get("/tag/*", repo.SingleRelease)
m.Get("/latest", repo.LatestRelease)
m.Get("/attachments/:uuid", repo.GetAttachment)
}, repo.MustBeNotEmpty, context.RepoRefByType(context.RepoRefTag))
}, repo.MustBeNotEmpty, reqRepoReleaseReader, context.RepoRefByType(context.RepoRefTag))
m.Group("/releases", func() {
m.Get("/new", repo.NewRelease)
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
m.Post("/delete", repo.DeleteRelease)
m.Post("/attachments", repo.UploadReleaseAttachment)
m.Post("/attachments/remove", repo.DeleteAttachment)
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, context.RepoRef())
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
m.Group("/releases", func() {
m.Get("/edit/*", repo.EditRelease)
m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
Expand Down
4 changes: 0 additions & 4 deletions services/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ func DeleteReleaseByID(id int64, doer *models.User, delTag bool) error {
}
} else {
rel.IsTag = true
rel.IsDraft = false
rel.IsPrerelease = false
rel.Title = ""
rel.Note = ""

if err = models.UpdateRelease(models.DefaultDBContext(), rel); err != nil {
return fmt.Errorf("Update: %v", err)
Expand Down
Loading