[GITEA] Allow release creation on commit

- The code and tests are already there to allow releases to be created
on commits.
- This patch modifies the web code to take into account that an commitID
could've been passed as target.
- Added unit test.
- Resolves https://codeberg.org/forgejo/forgejo/issues/1196

(cherry picked from commit 90863e0ab5)
(cherry picked from commit c805aa23b5)
(cherry picked from commit cf45567ca6)
(cherry picked from commit 672a2b91e5)
(cherry picked from commit 82c930152c)
(cherry picked from commit 95ac2508b3)
(cherry picked from commit b13a81ab98)
(cherry picked from commit 9f463a7c1f)
(cherry picked from commit 758ce84dc5)

Conflicts:
	tests/integration/release_test.go
	https://codeberg.org/forgejo/forgejo/pulls/1550
(cherry picked from commit edf0531aee)
(cherry picked from commit 44b29f3a1d)
(cherry picked from commit b851b67419)
(cherry picked from commit 37b408f5aa)
(cherry picked from commit e81dbedb88)
(cherry picked from commit d5fa6be6ec)
(cherry picked from commit b8c4be2529)
(cherry picked from commit f23ce2843c)
(cherry picked from commit 8b7bcabae2)
(cherry picked from commit 2d6e52dda9)
(cherry picked from commit 42e4f3ffdd)
(cherry picked from commit 39a1f689d8)
(cherry picked from commit 553d4872f8)
(cherry picked from commit df37433725)
(cherry picked from commit d67eac487b)
(cherry picked from commit 28cb0b1912)
This commit is contained in:
Gusted 2023-08-05 14:47:09 +02:00 committed by Earl Warren
parent 0ce04d93a8
commit 031c04c579
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 19 additions and 2 deletions

View file

@ -397,7 +397,11 @@ func NewReleasePost(ctx *context.Context) {
return return
} }
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) { objectFormat, _ := ctx.Repo.GitRepo.GetObjectFormat()
// form.Target can be a branch name or a full commitID.
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) &&
len(form.Target) == objectFormat.FullLength() && !ctx.Repo.GitRepo.IsCommitExist(form.Target) {
ctx.RenderWithErr(ctx.Tr("form.target_branch_not_exist"), tplReleaseNew, &form) ctx.RenderWithErr(ctx.Tr("form.target_branch_not_exist"), tplReleaseNew, &form)
return return
} }

View file

@ -21,6 +21,10 @@ import (
) )
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) { func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
createNewReleaseTarget(t, session, repoURL, tag, title, "master", preRelease, draft)
}
func createNewReleaseTarget(t *testing.T, session *TestSession, repoURL, tag, title, target string, preRelease, draft bool) {
req := NewRequest(t, "GET", repoURL+"/releases/new") req := NewRequest(t, "GET", repoURL+"/releases/new")
resp := session.MakeRequest(t, req, http.StatusOK) resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body) htmlDoc := NewHTMLParser(t, resp.Body)
@ -31,7 +35,7 @@ func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title st
postData := map[string]string{ postData := map[string]string{
"_csrf": htmlDoc.GetCSRF(), "_csrf": htmlDoc.GetCSRF(),
"tag_name": tag, "tag_name": tag,
"tag_target": "master", "tag_target": target,
"title": title, "title": title,
"content": "", "content": "",
} }
@ -217,6 +221,15 @@ func TestViewReleaseListLogin(t *testing.T) {
}, links) }, links)
} }
func TestReleaseOnCommit(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
createNewReleaseTarget(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", "65f1bf27bc3bf70f64657658635e66094edbcb4d", false, false)
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.stable"), 4)
}
func TestViewTagsList(t *testing.T) { func TestViewTagsList(t *testing.T) {
defer tests.PrepareTestEnv(t)() defer tests.PrepareTestEnv(t)()