summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThilina Jayanath <thilina91@gmail.com>2025-01-12 10:16:45 +0100
committerEarl Warren <earl-warren@noreply.codeberg.org>2025-01-12 10:16:45 +0100
commited96852fdbc0dd5b047c8ffe5afe2d400788f578 (patch)
treefa8cc5170911fb095db37cea1d06b42863366049
parentUpdate x/tools (forgejo) (#6537) (diff)
downloadforgejo-ed96852fdbc0dd5b047c8ffe5afe2d400788f578.tar.xz
forgejo-ed96852fdbc0dd5b047c8ffe5afe2d400788f578.zip
fix: enable releases and/or wiki if user set the options in repo migration (#6051)
## 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. - [ ] 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. - [ ] 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. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6051 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Thilina Jayanath <thilina91@gmail.com> Co-committed-by: Thilina Jayanath <thilina91@gmail.com>
-rw-r--r--routers/api/v1/repo/migrate.go12
-rw-r--r--tests/integration/migrate_test.go113
2 files changed, 125 insertions, 0 deletions
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index 0991723d47..723a696b92 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -218,6 +218,18 @@ func Migrate(ctx *context.APIContext) {
return
}
+ if opts.Releases || opts.Wiki {
+ repoOpt := api.EditRepoOption{
+ HasReleases: &opts.Releases,
+ 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)
+ }
+ }
+
log.Trace("Repository migrated: %s/%s", repoOwner.Name, form.RepoName)
ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeAdmin}))
}
diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go
index 343cf752cc..c1e12f8267 100644
--- a/tests/integration/migrate_test.go
+++ b/tests/integration/migrate_test.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
@@ -112,6 +113,118 @@ func TestMigrate(t *testing.T) {
})
}
+func TestMigrateWithWiki(t *testing.T) {
+ onGiteaRun(t, func(t *testing.T, u *url.URL) {
+ defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, true)()
+ defer test.MockVariableValue(&setting.AppVer, "1.16.0")()
+ require.NoError(t, migrations.Init())
+
+ ownerName := "user2"
+ repoName := "repo1"
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: ownerName})
+ session := loginUser(t, ownerName)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeReadMisc)
+
+ for _, s := range []struct {
+ svc structs.GitServiceType
+ }{
+ {svc: structs.GiteaService},
+ {svc: structs.ForgejoService},
+ } {
+ t.Run(s.svc.Name(), func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+ // Step 0: verify the repo is available
+ req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName)
+ _ = session.MakeRequest(t, req, http.StatusOK)
+ // Step 1: get the Gitea migration form
+ req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ // Step 2: load the form
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ // Check form title
+ title := htmlDoc.doc.Find("title").Text()
+ assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title"))
+ // Step 4: submit the migration to only migrate issues
+ migratedRepoName := "otherrepo-" + s.svc.Name()
+ req = NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{
+ "_csrf": GetCSRF(t, session, "/repo/migrate"),
+ "service": fmt.Sprintf("%d", s.svc),
+ "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName),
+ "auth_token": token,
+ "issues": "on",
+ "wiki": "on",
+ "repo_name": migratedRepoName,
+ "description": "",
+ "uid": fmt.Sprintf("%d", repoOwner.ID),
+ })
+ resp = session.MakeRequest(t, req, http.StatusSeeOther)
+ // Step 5: a redirection displays the migrated repository
+ assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), test.RedirectURL(resp))
+ // Step 6: check the repo was created and load the repo
+ migratedRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
+ // Step 7: check if the wiki is enabled
+ assert.True(t, migratedRepo.UnitEnabled(db.DefaultContext, unit.TypeWiki))
+ })
+ }
+ })
+}
+
+func TestMigrateWithReleases(t *testing.T) {
+ onGiteaRun(t, func(t *testing.T, u *url.URL) {
+ defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, true)()
+ defer test.MockVariableValue(&setting.AppVer, "1.16.0")()
+ require.NoError(t, migrations.Init())
+
+ ownerName := "user2"
+ repoName := "repo1"
+ repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: ownerName})
+ session := loginUser(t, ownerName)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeReadMisc)
+
+ for _, s := range []struct {
+ svc structs.GitServiceType
+ }{
+ {svc: structs.GiteaService},
+ {svc: structs.ForgejoService},
+ } {
+ t.Run(s.svc.Name(), func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+ // Step 0: verify the repo is available
+ req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName)
+ _ = session.MakeRequest(t, req, http.StatusOK)
+ // Step 1: get the Gitea migration form
+ req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ // Step 2: load the form
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ // Check form title
+ title := htmlDoc.doc.Find("title").Text()
+ assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title"))
+ // Step 4: submit the migration to only migrate issues
+ migratedRepoName := "otherrepo-" + s.svc.Name()
+ req = NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{
+ "_csrf": GetCSRF(t, session, "/repo/migrate"),
+ "service": fmt.Sprintf("%d", s.svc),
+ "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName),
+ "auth_token": token,
+ "issues": "on",
+ "releases": "on",
+ "repo_name": migratedRepoName,
+ "description": "",
+ "uid": fmt.Sprintf("%d", repoOwner.ID),
+ })
+ resp = session.MakeRequest(t, req, http.StatusSeeOther)
+ // Step 5: a redirection displays the migrated repository
+ assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), test.RedirectURL(resp))
+ // Step 6: check the repo was created and load the repo
+ migratedRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
+ // Step 7: check if releases are enabled
+ assert.True(t, migratedRepo.UnitEnabled(db.DefaultContext, unit.TypeReleases))
+ })
+ }
+ })
+}
+
func Test_UpdateCommentsMigrationsByType(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())