mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
fix: do not fail when release or wiki is set in /repos/migrate
API (#8155)
* convert updateRepoUnits to not rely on ctx to retrieve the repo * Add integration test * do not activate releases if `wiki: true`. This is unexpected and there is no evidence it is necessary. Refs https://codeberg.org/forgejo/forgejo/issues/8082 --- The test is minimal for the sake of backporting. It is verified to reproduce the bug if the fix is not present. ```sh $ make TAGS='sqlite sqlite_unlock_notify' 'test-sqlite#TestAPIRepoMigrate' ... === TestAPIRepoMigrate (tests/integration/api_repo_test.go:388) --- FAIL: TestAPIRepoMigrate (1.12s) testlogger.go:411: 2025/06/11 17:38:22 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /home/earl-warren/software/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/06/11 17:38:22 ...eb/routing/logger.go:102:func1() [I] router: completed GET /user/login for test-mock:12345, 200 OK in 2.1ms @ auth/auth.go:145(auth.SignIn) testlogger.go:411: 2025/06/11 17:38:22 ...eb/routing/logger.go:102:func1() [I] router: completed POST /user/login for test-mock:12345, 303 See Other in 2.1ms @ auth/auth.go:179(auth.SignInPost) testlogger.go:411: 2025/06/11 17:38:22 ...eb/routing/logger.go:102:func1() [I] router: completed GET /user/settings/applications for test-mock:12345, 200 OK in 3.8ms @ setting/applications.go:25(setting.Applications) testlogger.go:411: 2025/06/11 17:38:22 ...eb/routing/logger.go:102:func1() [I] router: completed POST /user/settings/applications for test-mock:12345, 303 See Other in 5.1ms @ setting/applications.go:35(setting.ApplicationsPost) testlogger.go:411: 2025/06/11 17:38:22 ...eb/routing/logger.go:102:func1() [I] router: completed GET /user/settings/applications for test-mock:12345, 200 OK in 2.9ms @ setting/applications.go:25(setting.Applications) testlogger.go:411: 2025/06/11 17:38:23 ...eb/routing/logger.go:102:func1() [I] router: completed POST /api/v1/repos/migrate for test-mock:12345, 0 in 992.0ms @ repo/migrate.go:38(repo.Migrate) api_repo_test.go:400: Error Trace: /home/earl-warren/software/forgejo/tests/integration/api_repo_test.go:400 Error: Not equal: expected: 201 actual : 200 Test: TestAPIRepoMigrate api_repo_test.go:402: Error Trace: /home/earl-warren/software/forgejo/tests/integration/integration_test.go:649 /home/earl-warren/software/forgejo/tests/integration/api_repo_test.go:402 Error: Received unexpected error: EOF Test: TestAPIRepoMigrate ``` ## 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 - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/8155): <!--number 8155 --><!--line 0 --><!--description ZG8gbm90IGZhaWwgd2hlbiByZWxlYXNlIG9yIHdpa2kgaXMgc2V0IGluIGAvcmVwb3MvbWlncmF0ZWAgQVBJ-->do not fail when release or wiki is set in `/repos/migrate` API<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8155 Reviewed-by: Lucas <sclu1034@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
fcecafe823
commit
7ec014cba8
3 changed files with 6 additions and 9 deletions
|
@ -224,9 +224,8 @@ func Migrate(ctx *context.APIContext) {
|
|||
HasWiki: &opts.Wiki,
|
||||
}
|
||||
|
||||
// only enabling wiki could return an error
|
||||
if err = updateRepoUnits(ctx, repoOpt); err != nil {
|
||||
log.Error("Failed to enable wiki on %s/%s repo. %w", repoOwner.Name, form.RepoName, err)
|
||||
if err = updateRepoUnits(ctx, repoOwner.Name, repo, repoOpt); err != nil {
|
||||
log.Error("Failed to update units on %s/%s repo. %w", repoOwner.Name, form.RepoName, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -647,7 +647,7 @@ func Edit(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := updateRepoUnits(ctx, opts); err != nil {
|
||||
if err := updateRepoUnits(ctx, ctx.Repo.Owner.Name, ctx.Repo.Repository, opts); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -779,10 +779,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
|
|||
}
|
||||
|
||||
// updateRepoUnits updates repo units: Issue settings, Wiki settings, PR settings
|
||||
func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
func updateRepoUnits(ctx *context.APIContext, owner string, repo *repo_model.Repository, opts api.EditRepoOption) error {
|
||||
var units []repo_model.RepoUnit
|
||||
var deleteUnitTypes []unit_model.Type
|
||||
|
||||
|
@ -1045,7 +1042,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
}
|
||||
}
|
||||
|
||||
log.Trace("Repository advanced settings updated: %s/%s", owner.Name, repo.Name)
|
||||
log.Trace("Repository advanced settings updated: %s/%s", owner, repo.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -394,6 +394,7 @@ func TestAPIRepoMigrate(t *testing.T) {
|
|||
CloneAddr: testCase.cloneURL,
|
||||
RepoOwnerID: testCase.userID,
|
||||
RepoName: testCase.repoName,
|
||||
Wiki: true,
|
||||
}).AddTokenAuth(token)
|
||||
resp := MakeRequest(t, req, NoExpectedStatus)
|
||||
require.Equalf(t, testCase.expectedStatus, resp.Code, "unexpected status (may be due to throttling): '%v' on url '%s'", resp.Body.String(), testCase.cloneURL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue