loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Thilina Jayanath
Thilina Jayanath
and committed by
Earl Warren
ed96852f 263b55fd

+125
+12
routers/api/v1/repo/migrate.go
··· 218 218 return 219 219 } 220 220 221 + if opts.Releases || opts.Wiki { 222 + repoOpt := api.EditRepoOption{ 223 + HasReleases: &opts.Releases, 224 + HasWiki: &opts.Wiki, 225 + } 226 + 227 + // only enabling wiki could return an error 228 + if err = updateRepoUnits(ctx, repoOpt); err != nil { 229 + log.Error("Failed to enable wiki on %s/%s repo. %w", repoOwner.Name, form.RepoName, err) 230 + } 231 + } 232 + 221 233 log.Trace("Repository migrated: %s/%s", repoOwner.Name, form.RepoName) 222 234 ctx.JSON(http.StatusCreated, convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeAdmin})) 223 235 }
+113
tests/integration/migrate_test.go
··· 16 16 "code.gitea.io/gitea/models/db" 17 17 issues_model "code.gitea.io/gitea/models/issues" 18 18 repo_model "code.gitea.io/gitea/models/repo" 19 + "code.gitea.io/gitea/models/unit" 19 20 "code.gitea.io/gitea/models/unittest" 20 21 user_model "code.gitea.io/gitea/models/user" 21 22 "code.gitea.io/gitea/modules/setting" ··· 107 108 assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), test.RedirectURL(resp)) 108 109 // Step 6: check the repo was created 109 110 unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) 111 + }) 112 + } 113 + }) 114 + } 115 + 116 + func TestMigrateWithWiki(t *testing.T) { 117 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 118 + defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, true)() 119 + defer test.MockVariableValue(&setting.AppVer, "1.16.0")() 120 + require.NoError(t, migrations.Init()) 121 + 122 + ownerName := "user2" 123 + repoName := "repo1" 124 + repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: ownerName}) 125 + session := loginUser(t, ownerName) 126 + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeReadMisc) 127 + 128 + for _, s := range []struct { 129 + svc structs.GitServiceType 130 + }{ 131 + {svc: structs.GiteaService}, 132 + {svc: structs.ForgejoService}, 133 + } { 134 + t.Run(s.svc.Name(), func(t *testing.T) { 135 + defer tests.PrintCurrentTest(t)() 136 + // Step 0: verify the repo is available 137 + req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName) 138 + _ = session.MakeRequest(t, req, http.StatusOK) 139 + // Step 1: get the Gitea migration form 140 + req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc) 141 + resp := session.MakeRequest(t, req, http.StatusOK) 142 + // Step 2: load the form 143 + htmlDoc := NewHTMLParser(t, resp.Body) 144 + // Check form title 145 + title := htmlDoc.doc.Find("title").Text() 146 + assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title")) 147 + // Step 4: submit the migration to only migrate issues 148 + migratedRepoName := "otherrepo-" + s.svc.Name() 149 + req = NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{ 150 + "_csrf": GetCSRF(t, session, "/repo/migrate"), 151 + "service": fmt.Sprintf("%d", s.svc), 152 + "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName), 153 + "auth_token": token, 154 + "issues": "on", 155 + "wiki": "on", 156 + "repo_name": migratedRepoName, 157 + "description": "", 158 + "uid": fmt.Sprintf("%d", repoOwner.ID), 159 + }) 160 + resp = session.MakeRequest(t, req, http.StatusSeeOther) 161 + // Step 5: a redirection displays the migrated repository 162 + assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), test.RedirectURL(resp)) 163 + // Step 6: check the repo was created and load the repo 164 + migratedRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) 165 + // Step 7: check if the wiki is enabled 166 + assert.True(t, migratedRepo.UnitEnabled(db.DefaultContext, unit.TypeWiki)) 167 + }) 168 + } 169 + }) 170 + } 171 + 172 + func TestMigrateWithReleases(t *testing.T) { 173 + onGiteaRun(t, func(t *testing.T, u *url.URL) { 174 + defer test.MockVariableValue(&setting.Migrations.AllowLocalNetworks, true)() 175 + defer test.MockVariableValue(&setting.AppVer, "1.16.0")() 176 + require.NoError(t, migrations.Init()) 177 + 178 + ownerName := "user2" 179 + repoName := "repo1" 180 + repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: ownerName}) 181 + session := loginUser(t, ownerName) 182 + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeReadMisc) 183 + 184 + for _, s := range []struct { 185 + svc structs.GitServiceType 186 + }{ 187 + {svc: structs.GiteaService}, 188 + {svc: structs.ForgejoService}, 189 + } { 190 + t.Run(s.svc.Name(), func(t *testing.T) { 191 + defer tests.PrintCurrentTest(t)() 192 + // Step 0: verify the repo is available 193 + req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName) 194 + _ = session.MakeRequest(t, req, http.StatusOK) 195 + // Step 1: get the Gitea migration form 196 + req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc) 197 + resp := session.MakeRequest(t, req, http.StatusOK) 198 + // Step 2: load the form 199 + htmlDoc := NewHTMLParser(t, resp.Body) 200 + // Check form title 201 + title := htmlDoc.doc.Find("title").Text() 202 + assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title")) 203 + // Step 4: submit the migration to only migrate issues 204 + migratedRepoName := "otherrepo-" + s.svc.Name() 205 + req = NewRequestWithValues(t, "POST", "/repo/migrate", map[string]string{ 206 + "_csrf": GetCSRF(t, session, "/repo/migrate"), 207 + "service": fmt.Sprintf("%d", s.svc), 208 + "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName), 209 + "auth_token": token, 210 + "issues": "on", 211 + "releases": "on", 212 + "repo_name": migratedRepoName, 213 + "description": "", 214 + "uid": fmt.Sprintf("%d", repoOwner.ID), 215 + }) 216 + resp = session.MakeRequest(t, req, http.StatusSeeOther) 217 + // Step 5: a redirection displays the migrated repository 218 + assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), test.RedirectURL(resp)) 219 + // Step 6: check the repo was created and load the repo 220 + migratedRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) 221 + // Step 7: check if releases are enabled 222 + assert.True(t, migratedRepo.UnitEnabled(db.DefaultContext, unit.TypeReleases)) 110 223 }) 111 224 } 112 225 })