diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index b7970cb7c82f6..812ecc4857029 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -29,6 +29,7 @@ size: 8478 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 2 @@ -60,6 +61,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: true + default_unit: 1 - id: 3 @@ -91,6 +93,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 4 @@ -122,6 +125,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 5 @@ -152,6 +156,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 6 @@ -182,6 +187,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 7 @@ -212,6 +218,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 8 @@ -242,6 +249,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 9 @@ -272,6 +280,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 10 @@ -303,6 +312,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 11 @@ -334,6 +344,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 12 @@ -364,6 +375,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 13 @@ -394,6 +406,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 14 @@ -425,6 +438,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 15 @@ -456,6 +470,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 16 @@ -487,6 +502,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 17 @@ -517,6 +533,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 18 @@ -547,6 +564,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 19 @@ -577,6 +595,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 20 @@ -607,6 +626,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 21 @@ -637,6 +657,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 22 @@ -667,6 +688,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 23 @@ -697,6 +719,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 24 @@ -727,6 +750,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 25 @@ -757,6 +781,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 26 @@ -787,6 +812,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 27 @@ -817,6 +843,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 28 @@ -847,6 +874,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 29 @@ -877,6 +905,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 30 @@ -907,6 +936,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 31 @@ -938,6 +968,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 32 # org public repo @@ -968,6 +999,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 33 @@ -999,6 +1031,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 34 @@ -1029,6 +1062,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 35 @@ -1059,6 +1093,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 36 @@ -1090,6 +1125,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 37 @@ -1121,6 +1157,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 38 @@ -1152,6 +1189,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 39 @@ -1183,6 +1221,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 40 @@ -1214,6 +1253,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 41 @@ -1245,6 +1285,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 42 @@ -1276,6 +1317,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 43 @@ -1306,6 +1348,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 44 @@ -1337,6 +1380,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 45 @@ -1367,6 +1411,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 46 @@ -1398,6 +1443,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 47 @@ -1429,6 +1475,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 48 @@ -1460,6 +1507,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 49 @@ -1491,6 +1539,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 50 @@ -1522,6 +1571,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 51 @@ -1553,6 +1603,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 52 @@ -1584,6 +1635,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 53 @@ -1612,6 +1664,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 54 @@ -1624,6 +1677,7 @@ is_archived: false is_private: true status: 0 + default_unit: 1 - id: 55 @@ -1636,6 +1690,7 @@ is_private: true num_issues: 1 status: 0 + default_unit: 1 - id: 56 @@ -1649,6 +1704,7 @@ is_private: true status: 0 num_issues: 0 + default_unit: 1 - id: 57 @@ -1662,6 +1718,7 @@ is_private: false status: 0 num_issues: 0 + default_unit: 1 - id: 58 # org public repo @@ -1693,6 +1750,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 59 @@ -1706,6 +1764,7 @@ is_private: true status: 0 num_issues: 0 + default_unit: 1 - id: 60 @@ -1737,6 +1796,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 61 @@ -1768,6 +1828,7 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 - id: 62 @@ -1799,3 +1860,4 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false + default_unit: 1 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index ddf20d9542cfe..b5e962cc3b90e 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -364,6 +364,7 @@ func prepareMigrationTasks() []*migration { newMigration(304, "Add index for release sha1", v1_23.AddIndexForReleaseSha1), newMigration(305, "Add Repository Licenses", v1_23.AddRepositoryLicenses), newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection), + newMigration(307, "Add DefaultUnit to Repository", v1_23.AddDefaultUnitToRepository), } return preparedMigrations } diff --git a/models/migrations/v1_23/v307.go b/models/migrations/v1_23/v307.go new file mode 100644 index 0000000000000..056cb200831e2 --- /dev/null +++ b/models/migrations/v1_23/v307.go @@ -0,0 +1,13 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_23 //nolint + +import "xorm.io/xorm" + +func AddDefaultUnitToRepository(x *xorm.Engine) error { + type Repository struct { + DefaultUnit int `xorm:"NOT NULL DEFAULT 1"` + } + return x.Sync(new(Repository)) +} diff --git a/models/repo/repo.go b/models/repo/repo.go index 68f8e16a21d58..ae642bd5606a3 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -168,6 +168,7 @@ type Repository struct { RenderingMetas map[string]string `xorm:"-"` DocumentRenderingMetas map[string]string `xorm:"-"` Units []*RepoUnit `xorm:"-"` + DefaultUnit unit.Type `xorm:"NOT NULL DEFAULT 1"` PrimaryLanguage *LanguageStat `xorm:"-"` IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` diff --git a/models/unit/unit.go b/models/unit/unit.go index 3b62e5f982267..d07bb6782249e 100644 --- a/models/unit/unit.go +++ b/models/unit/unit.go @@ -206,7 +206,7 @@ var ( UnitCode = Unit{ TypeCode, "repo.code", - "/", + "/code", "repo.code.desc", 0, perm.AccessModeOwner, diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 7d9281b397387..3dcf3a9a8da36 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -771,8 +771,8 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } -// Home render repository home page -func Home(ctx *context.Context) { +// HomeWithFeedCheck redirect to default unit or return feed +func HomeWithFeedCheck(ctx *context.Context) { if setting.Other.EnableFeed { isFeed, _, showFeedType := feed.GetFeedType(ctx.PathParam(":reponame"), ctx.Req) if isFeed { @@ -788,6 +788,15 @@ func Home(ctx *context.Context) { } } + defaultURI := ctx.Repo.Repository.MustGetUnit(ctx, ctx.Repo.Repository.DefaultUnit).Unit().URI + if defaultURI == "/" { // support legacy code units + defaultURI = "/code" + } + ctx.Redirect(ctx.Repo.RepoLink+defaultURI, http.StatusMovedPermanently) +} + +// CodeHome render repository code unit page +func CodeHome(ctx *context.Context) { checkHomeCodeViewable(ctx) if ctx.Written() { return diff --git a/routers/web/web.go b/routers/web/web.go index 83d116babd769..8f211d6b60530 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1139,8 +1139,10 @@ func registerRoutes(m *web.Router) { ) // end "/{username}/{reponame}/settings" - // user/org home, including rss feeds - m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home) + // user/org home, witch either redirects to default unit or return rss feeds + m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.HomeWithFeedCheck) + // show the code unit's home view + m.Get("/{username}/{reponame}/code", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.CodeHome) // TODO: maybe it should relax the permission to allow "any access" m.Post("/{username}/{reponame}/markup", ignSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypeCode, unit.TypeIssues, unit.TypePullRequests, unit.TypeReleases, unit.TypeWiki), web.Bind(structs.MarkupOption{}), misc.Markup) @@ -1579,10 +1581,10 @@ func registerRoutes(m *web.Router) { m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed) m.Group("/src", func() { - m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Home) - m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.Home) - m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.Home) - m.Get("/*", context.RepoRefByType(context.RepoRefLegacy), repo.Home) // "/*" route is deprecated, and kept for backward compatibility + m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.CodeHome) + m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.CodeHome) + m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.CodeHome) + m.Get("/*", context.RepoRefByType(context.RepoRefLegacy), repo.CodeHome) // "/*" route is deprecated, and kept for backward compatibility }, repo.SetEditorconfigIfExists) m.Get("/forks", context.RepoRef(), repo.Forks) diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index d52891b02a76a..5648e17226313 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -133,7 +133,7 @@ {{if not (or .Repository.IsBeingCreated .Repository.IsBroken)}}
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}} - + {{svg "octicon-code"}} {{ctx.Locale.Tr "repo.code"}} {{end}} diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go index d3b30448fc81d..3182dc1716dd4 100644 --- a/tests/integration/links_test.go +++ b/tests/integration/links_test.go @@ -32,8 +32,7 @@ func TestLinksNoLogin(t *testing.T) { "/user/login", "/user/forgot_password", "/api/swagger", - "/user2/repo1", - "/user2/repo1/", + "/user2/repo1/code", "/user2/repo1/projects", "/user2/repo1/projects/1", "/user2/repo1/releases/tag/delete-tag", // It's the only one existing record on release.yml which has is_tag: true @@ -64,6 +63,20 @@ func TestRedirectsNoLogin(t *testing.T) { } } +func TestPermanentRedirectsNoLogin(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + redirects := map[string]string{ + "/user2/repo1": "/user2/repo1/code", + "/user2/repo1/": "/user2/repo1/code", + } + for link, redirectLink := range redirects { + req := NewRequest(t, "GET", link) + resp := MakeRequest(t, req, http.StatusMovedPermanently) + assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp)) + } +} + func TestNoLoginNotExist(t *testing.T) { defer tests.PrepareTestEnv(t)() @@ -139,7 +152,7 @@ func testLinksAsUser(userName string, t *testing.T) { DecodeJSON(t, respAPI, &apiRepos) repoLinks := []string{ - "", + "/code", "/issues", "/pulls", "/commits/branch/master", diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go index 4c784dd22b931..0938ca17c0117 100644 --- a/tests/integration/migrate_test.go +++ b/tests/integration/migrate_test.go @@ -73,14 +73,19 @@ func TestMigrateGiteaForm(t *testing.T) { // Step 0: verify the repo is available req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName) - _ = session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusMovedPermanently) + req = NewRequest(t, "GET", resp.Result().Header.Get("Location")) + _ = MakeRequest(t, req, http.StatusOK) + // Step 1: get the Gitea migration form req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", structs.GiteaService) - resp := session.MakeRequest(t, req, http.StatusOK) + resp = session.MakeRequest(t, req, http.StatusOK) + // Step 2: load the form htmlDoc := NewHTMLParser(t, resp.Body) link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action") assert.True(t, exists, "The template has changed") + // Step 4: submit the migration to only migrate issues migratedRepoName := "otherrepo" req = NewRequestWithValues(t, "POST", link, map[string]string{ @@ -94,9 +99,11 @@ func TestMigrateGiteaForm(t *testing.T) { "uid": fmt.Sprintf("%d", repoOwner.ID), }) resp = session.MakeRequest(t, req, http.StatusSeeOther) + // Step 5: a redirection displays the migrated repository loc := resp.Header().Get("Location") assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc) + // Step 6: check the repo was created unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) }) diff --git a/tests/integration/org_test.go b/tests/integration/org_test.go index ef4ef2bb9b429..2cb28b12d7723 100644 --- a/tests/integration/org_test.go +++ b/tests/integration/org_test.go @@ -63,7 +63,7 @@ func TestLimitedOrg(t *testing.T) { session := loginUser(t, "user2") req = NewRequest(t, "GET", "/limited_org") session.MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org") + req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org/code") session.MakeRequest(t, req, http.StatusOK) req = NewRequest(t, "GET", "/limited_org/private_repo_on_limited_org") session.MakeRequest(t, req, http.StatusNotFound) @@ -72,9 +72,9 @@ func TestLimitedOrg(t *testing.T) { session = loginUser(t, "user1") req = NewRequest(t, "GET", "/limited_org") session.MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org") + req = NewRequest(t, "GET", "/limited_org/public_repo_on_limited_org/code") session.MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", "/limited_org/private_repo_on_limited_org") + req = NewRequest(t, "GET", "/limited_org/private_repo_on_limited_org/code") session.MakeRequest(t, req, http.StatusOK) } @@ -102,7 +102,7 @@ func TestPrivateOrg(t *testing.T) { session = loginUser(t, "user4") req = NewRequest(t, "GET", "/privated_org") session.MakeRequest(t, req, http.StatusNotFound) - req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org") // colab of this repo + req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org/code") // colab of this repo session.MakeRequest(t, req, http.StatusOK) req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org") session.MakeRequest(t, req, http.StatusNotFound) @@ -111,9 +111,9 @@ func TestPrivateOrg(t *testing.T) { session = loginUser(t, "user1") req = NewRequest(t, "GET", "/privated_org") session.MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org") + req = NewRequest(t, "GET", "/privated_org/public_repo_on_private_org/code") session.MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org") + req = NewRequest(t, "GET", "/privated_org/private_repo_on_private_org/code") session.MakeRequest(t, req, http.StatusOK) } @@ -191,7 +191,7 @@ func TestOrgRestrictedUser(t *testing.T) { req = NewRequest(t, "GET", fmt.Sprintf("/%s", orgName)) restrictedSession.MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s", orgName, repoName)) + req = NewRequest(t, "GET", fmt.Sprintf("/%s/%s/code", orgName, repoName)) restrictedSession.MakeRequest(t, req, http.StatusOK) } diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go index 9812d2073d1e9..7a75a87450041 100644 --- a/tests/integration/pull_create_test.go +++ b/tests/integration/pull_create_test.go @@ -19,7 +19,7 @@ import ( ) func testPullCreate(t *testing.T, session *TestSession, user, repo string, toSelf bool, targetBranch, sourceBranch, title string) *httptest.ResponseRecorder { - req := NewRequest(t, "GET", path.Join(user, repo)) + req := NewRequest(t, "GET", path.Join(user, repo, "code")) resp := session.MakeRequest(t, req, http.StatusOK) // Click the PR button to create a pull diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go index 6d1cc8afcf108..2ddd30a7801d0 100644 --- a/tests/integration/repo_branch_test.go +++ b/tests/integration/repo_branch_test.go @@ -200,7 +200,9 @@ func prepareRepoPR(t *testing.T, baseSession, headSession *TestSession, baseRepo func checkRecentlyPushedNewBranches(t *testing.T, session *TestSession, repoPath string, expected []string) { branches := make([]string, 0, 2) req := NewRequest(t, "GET", repoPath) - resp := session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusMovedPermanently) + req = NewRequest(t, "GET", resp.Result().Header.Get("Location")) + resp = MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body) doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { branches = append(branches, branch.Text()) diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go index feebebf062081..796b82a30d69b 100644 --- a/tests/integration/repo_fork_test.go +++ b/tests/integration/repo_fork_test.go @@ -24,7 +24,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO session.MakeRequest(t, req, http.StatusNotFound) // Step1: go to the main page of repo - req = NewRequestf(t, "GET", "/%s/%s", ownerName, repoName) + req = NewRequestf(t, "GET", "/%s/%s/code", ownerName, repoName) resp := session.MakeRequest(t, req, http.StatusOK) // Step2: click the fork button @@ -49,7 +49,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO session.MakeRequest(t, req, http.StatusSeeOther) // Step4: check the existence of the forked repo - req = NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName) + req = NewRequestf(t, "GET", "/%s/%s/code", forkOwnerName, forkRepoName) resp = session.MakeRequest(t, req, http.StatusOK) return resp @@ -69,7 +69,9 @@ func TestRepoForkToOrg(t *testing.T) { // Check that no more forking is allowed as user2 owns repository // and org3 organization that owner user2 is also now has forked this repository req := NewRequest(t, "GET", "/user2/repo1") - resp := session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusMovedPermanently) + req = NewRequest(t, "GET", resp.Result().Header.Get("Location")) + resp = MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) _, exists := htmlDoc.doc.Find(`a.ui.button[href*="/fork"]`).Attr("href") assert.False(t, exists, "Forking should not be allowed anymore") diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go index 961255cedfbd5..a721a9a64b0b3 100644 --- a/tests/integration/repo_generate_test.go +++ b/tests/integration/repo_generate_test.go @@ -27,7 +27,9 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateID, templateOw // Step1: go to the main page of template repo req = NewRequestf(t, "GET", "/%s/%s", templateOwnerName, templateRepoName) - resp := session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusMovedPermanently) + req = NewRequest(t, "GET", resp.Result().Header.Get("Location")) + resp = session.MakeRequest(t, req, http.StatusOK) // Step2: click the "Use this template" button htmlDoc := NewHTMLParser(t, resp.Body) @@ -53,7 +55,7 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateID, templateOw // Step4: check the existence of the generated repo req = NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName) - session.MakeRequest(t, req, http.StatusOK) + session.MakeRequest(t, req, http.StatusMovedPermanently) // Step5: check substituted values in Readme req = NewRequestf(t, "GET", "/%s/%s/raw/branch/master/README.md", generateOwnerName, generateRepoName) diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index b967ccad1ec69..97044e5a84cc2 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -25,7 +25,11 @@ func TestViewRepo(t *testing.T) { session := loginUser(t, "user2") req := NewRequest(t, "GET", "/user2/repo1") - resp := session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusMovedPermanently) + + link := resp.Result().Header.Get("Location") + req = NewRequest(t, "GET", link) + resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) repoTopics := htmlDoc.doc.Find("#repo-topics").Children() @@ -44,7 +48,7 @@ func TestViewRepo(t *testing.T) { func testViewRepo(t *testing.T) { defer tests.PrepareTestEnv(t)() - req := NewRequest(t, "GET", "/org3/repo3") + req := NewRequest(t, "GET", "/org3/repo3/code") session := loginUser(t, "user2") resp := session.MakeRequest(t, req, http.StatusOK) @@ -115,7 +119,7 @@ func TestViewRepo2(t *testing.T) { func TestViewRepo3(t *testing.T) { defer tests.PrepareTestEnv(t)() - req := NewRequest(t, "GET", "/org3/repo3") + req := NewRequest(t, "GET", "/org3/repo3/code") session := loginUser(t, "user4") session.MakeRequest(t, req, http.StatusOK) } @@ -124,7 +128,11 @@ func TestViewRepo1CloneLinkAnonymous(t *testing.T) { defer tests.PrepareTestEnv(t)() req := NewRequest(t, "GET", "/user2/repo1") - resp := MakeRequest(t, req, http.StatusOK) + resp := MakeRequest(t, req, http.StatusMovedPermanently) + + link := resp.Result().Header.Get("Location") + req = NewRequest(t, "GET", link) + resp = MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) link, exists := htmlDoc.doc.Find("#repo-clone-https").Attr("data-link") @@ -139,7 +147,7 @@ func TestViewRepo1CloneLinkAuthorized(t *testing.T) { session := loginUser(t, "user2") - req := NewRequest(t, "GET", "/user2/repo1") + req := NewRequest(t, "GET", "/user2/repo1/code") resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) @@ -158,7 +166,11 @@ func TestViewRepoWithSymlinks(t *testing.T) { session := loginUser(t, "user2") req := NewRequest(t, "GET", "/user2/repo20.git") - resp := session.MakeRequest(t, req, http.StatusOK) + resp := session.MakeRequest(t, req, http.StatusMovedPermanently) + + link := resp.Result().Header.Get("Location") + req = NewRequest(t, "GET", link) + resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) files := htmlDoc.doc.Find("#repo-files-table > TBODY > TR > TD.name > SPAN.truncate") @@ -269,7 +281,7 @@ func TestViewRepoDirectoryReadme(t *testing.T) { } // viewing the top level - check("Home", "/user2/readme-test/", "README.md", "markdown", "The cake is a lie.") + check("Home", "/user2/readme-test/code", "README.md", "markdown", "The cake is a lie.") // viewing different file extensions check("md", "/user2/readme-test/src/branch/master/", "README.md", "markdown", "The cake is a lie.")