mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-12 22:10:25 +00:00
fix(api): default new release 'title' field to label name, if not provided (#10925)
## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. *The decision if the pull request will be shown in the release notes is up to the mergers / release team.* The content of the `release-notes/<pull request number>.md` file will serve as the basis for the release notes. If the file does not exist, the title of the pull request will be used instead. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10925 Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org> Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org> Co-authored-by: emilycares <emilydoescare@gmail.com> Co-committed-by: emilycares <emilydoescare@gmail.com>
This commit is contained in:
parent
374b3d9f4d
commit
3595e1e830
2 changed files with 28 additions and 2 deletions
|
|
@ -230,6 +230,10 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusUnprocessableEntity, "RepoIsEmpty", errors.New("repo is empty"))
|
||||
return
|
||||
}
|
||||
title := form.Title
|
||||
if len(title) == 0 {
|
||||
title = form.TagName
|
||||
}
|
||||
rel, err := repo_model.GetRelease(ctx, ctx.Repo.Repository.ID, form.TagName)
|
||||
if err != nil {
|
||||
if !repo_model.IsErrReleaseNotExist(err) {
|
||||
|
|
@ -246,7 +250,7 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
Publisher: ctx.Doer,
|
||||
TagName: form.TagName,
|
||||
Target: form.Target,
|
||||
Title: form.Title,
|
||||
Title: title,
|
||||
Note: form.Note,
|
||||
IsDraft: form.IsDraft,
|
||||
IsPrerelease: form.IsPrerelease,
|
||||
|
|
@ -272,7 +276,7 @@ func CreateRelease(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
rel.Title = form.Title
|
||||
rel.Title = title
|
||||
rel.Note = form.Note
|
||||
rel.IsDraft = form.IsDraft
|
||||
rel.IsPrerelease = form.IsPrerelease
|
||||
|
|
|
|||
|
|
@ -497,6 +497,28 @@ func TestAPIReleaseMissingAsset(t *testing.T) {
|
|||
MakeRequest(t, req, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
func TestAPIReleaseMissingTitle(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||
session := loginUser(t, owner.LowerName)
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
|
||||
require.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
err = gitRepo.CreateTag("v0.0.1", "master")
|
||||
require.NoError(t, err)
|
||||
|
||||
target, err := gitRepo.GetTagCommitID("v0.0.1")
|
||||
require.NoError(t, err)
|
||||
|
||||
r := createNewReleaseUsingAPI(t, token, owner, repo, target, "", "", "")
|
||||
assert.Equal(t, r.Title, target)
|
||||
}
|
||||
|
||||
func TestAPIReleaseGithubFormat(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue