From 371cc207be8ab37435286301958c5d1f45013783 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 28 Oct 2024 23:39:02 +0100 Subject: [PATCH 01/18] Add DefaultUnit to Repository --- models/migrations/migrations.go | 1 + models/migrations/v1_23/v307.go | 13 +++++++++++++ models/repo/repo.go | 1 + 3 files changed, 15 insertions(+) create mode 100644 models/migrations/v1_23/v307.go 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"` From 91ae32ca7c9a895fcaa553461816a58beae02a4b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 28 Oct 2024 23:47:37 +0100 Subject: [PATCH 02/18] todo --- routers/web/repo/view.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 9769117609485..35f10a1a2fac2 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -722,6 +722,7 @@ func checkHomeCodeViewable(ctx *context.Context) { } } + // TODO: ctx.Repo.Repository.DefaultUnit has to be respected here ... but we need to let code unit have it's own subpath ... var firstUnit *unit_model.Unit for _, repoUnitType := range ctx.Repo.Permission.ReadableUnitTypes() { if repoUnitType == unit_model.TypeCode { From b33f9b6c95cb93e5370396ab1f0fe781e33b2ef4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Oct 2024 00:06:39 +0100 Subject: [PATCH 03/18] code unit get its sub path as every other unit --- models/unit/unit.go | 2 +- routers/web/repo/view.go | 13 +++++++++++-- routers/web/web.go | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) 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 35f10a1a2fac2..eb27875db1c37 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -773,8 +773,8 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } -// Home render repository home page -func Home(ctx *context.Context) { +// HomeWithFeedCheck render repository home page or return feed +func HomeWithFeedCheck(ctx *context.Context) { if setting.Other.EnableFeed { isFeed, _, showFeedType := feed.GetFeedType(ctx.PathParam(":reponame"), ctx.Req) if isFeed { @@ -790,6 +790,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) +} + +// Home render repository home page +func Home(ctx *context.Context) { checkHomeCodeViewable(ctx) if ctx.Written() { return diff --git a/routers/web/web.go b/routers/web/web.go index a6ccb7a7924e9..1d34d32db3e79 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1140,7 +1140,8 @@ 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) + m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.HomeWithFeedCheck) + m.Get("/{username}/{reponame}/code", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home) // 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) From 8f837206e5c3faaa00eaa98720afc7477a9ccd1e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Oct 2024 00:14:03 +0100 Subject: [PATCH 04/18] it works --- templates/repo/header.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}} From c57011e1a9cc4bd0db5585269bc3c0594093fa48 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Oct 2024 13:09:38 +0100 Subject: [PATCH 05/18] more code comment info and cleanup --- routers/web/repo/view.go | 9 ++++----- routers/web/web.go | 5 +++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index eb27875db1c37..95db323f5c78e 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -722,7 +722,6 @@ func checkHomeCodeViewable(ctx *context.Context) { } } - // TODO: ctx.Repo.Repository.DefaultUnit has to be respected here ... but we need to let code unit have it's own subpath ... var firstUnit *unit_model.Unit for _, repoUnitType := range ctx.Repo.Permission.ReadableUnitTypes() { if repoUnitType == unit_model.TypeCode { @@ -773,7 +772,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } } -// HomeWithFeedCheck render repository home page or return feed +// 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) @@ -794,11 +793,11 @@ func HomeWithFeedCheck(ctx *context.Context) { if defaultURI == "/" { // support legacy code units defaultURI = "/code" } - ctx.Redirect(ctx.Repo.RepoLink + defaultURI) + ctx.Redirect(ctx.Repo.RepoLink+defaultURI, http.StatusMovedPermanently) } -// Home render repository home page -func Home(ctx *context.Context) { +// CodeHome render repository home 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 1d34d32db3e79..f9964a7f98419 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1139,9 +1139,10 @@ func registerRoutes(m *web.Router) { ) // end "/{username}/{reponame}/settings" - // user/org home, including rss feeds + // 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) - m.Get("/{username}/{reponame}/code", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home) + // 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) From e2cbb1fa11c1dcbe0a1afdcd3e283c73d12fc2d8 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Oct 2024 13:21:50 +0100 Subject: [PATCH 06/18] more --- routers/web/repo/view.go | 2 +- routers/web/web.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 95db323f5c78e..106ce35221541 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -796,7 +796,7 @@ func HomeWithFeedCheck(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink+defaultURI, http.StatusMovedPermanently) } -// CodeHome render repository home page +// CodeHome render repository code unit page func CodeHome(ctx *context.Context) { checkHomeCodeViewable(ctx) if ctx.Written() { diff --git a/routers/web/web.go b/routers/web/web.go index a0c47fc709f2c..8f211d6b60530 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1581,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) From ee37915e29ca34b862dade5e4dd369cbb6449017 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 19:01:58 +0100 Subject: [PATCH 07/18] update fixtures --- models/fixtures/repository.yml | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) 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 From 0e9d805c06745bd9ee0e132c87bfe328a1fae0e5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 19:17:27 +0100 Subject: [PATCH 08/18] jup --- tests/integration/pull_create_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From a0da1c4cc103f8be4dd92b2e1813310630a45958 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 20:36:25 +0100 Subject: [PATCH 09/18] adjust tests --- tests/integration/repo_fork_test.go | 4 ++-- tests/integration/repo_test.go | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go index feebebf062081..6b8ae432ddaad 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 diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index b967ccad1ec69..a43635363f375 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -139,7 +139,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 +158,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 +273,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.") From 76afc9324f46b4941a5a90d93e43f4f392807487 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 20:57:54 +0100 Subject: [PATCH 10/18] adjust tests (2) --- tests/integration/repo_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index a43635363f375..7eab78f2f26e3 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -27,6 +27,10 @@ func TestViewRepo(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo1") resp := session.MakeRequest(t, req, http.StatusOK) + 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() repoSummary := htmlDoc.doc.Find(".repository-summary").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) @@ -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") From 7df9ca936a8cdf3e7b8cd8831a5220339d59d82a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 21:00:33 +0100 Subject: [PATCH 11/18] adjust tests (3) --- tests/integration/repo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 7eab78f2f26e3..d8919dbb25db7 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -119,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) } From 924e3d5f5286fd52ec755fb860acf15930eec1dd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 21:22:12 +0100 Subject: [PATCH 12/18] adjust tests (4) --- tests/integration/links_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go index d3b30448fc81d..4f9e237159624 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 @@ -56,6 +55,8 @@ func TestRedirectsNoLogin(t *testing.T) { "/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt", "/user/avatar/Ghost/-1": "/assets/img/avatar_default.png", "/api/v1/swagger": "/api/swagger", + "/user2/repo1": "/user2/repo1/code", + "/user2/repo1/": "/user2/repo1/code", } for link, redirectLink := range redirects { req := NewRequest(t, "GET", link) From 40aae71221770689690aa84212e21e287510a812 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 21:42:49 +0100 Subject: [PATCH 13/18] adjust tests (5) --- tests/integration/links_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go index 4f9e237159624..4e91b81832e5e 100644 --- a/tests/integration/links_test.go +++ b/tests/integration/links_test.go @@ -55,8 +55,6 @@ func TestRedirectsNoLogin(t *testing.T) { "/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt", "/user/avatar/Ghost/-1": "/assets/img/avatar_default.png", "/api/v1/swagger": "/api/swagger", - "/user2/repo1": "/user2/repo1/code", - "/user2/repo1/": "/user2/repo1/code", } for link, redirectLink := range redirects { req := NewRequest(t, "GET", link) @@ -65,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)() From b2dbc98f8f4ff86c06c9df2b59a7d68082ef4a70 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 21:45:33 +0100 Subject: [PATCH 14/18] adjust tests (6) --- tests/integration/repo_generate_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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) From 3559d2f14213d04be5d00f7b19f9b051e0a902b5 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 21:59:36 +0100 Subject: [PATCH 15/18] adjust tests (7) --- tests/integration/links_test.go | 2 +- tests/integration/org_test.go | 10 +++++----- tests/integration/repo_fork_test.go | 4 +++- tests/integration/repo_test.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/integration/links_test.go b/tests/integration/links_test.go index 4e91b81832e5e..3182dc1716dd4 100644 --- a/tests/integration/links_test.go +++ b/tests/integration/links_test.go @@ -152,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/org_test.go b/tests/integration/org_test.go index ef4ef2bb9b429..9a7c947b83069 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,7 +72,7 @@ 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") 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) } diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go index 6b8ae432ddaad..796b82a30d69b 100644 --- a/tests/integration/repo_fork_test.go +++ b/tests/integration/repo_fork_test.go @@ -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_test.go b/tests/integration/repo_test.go index d8919dbb25db7..97044e5a84cc2 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -25,7 +25,7 @@ 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) From 573b49750403915eb06a2a7c0a840a6c08288ad2 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 22:16:05 +0100 Subject: [PATCH 16/18] adjust tests (8) --- tests/integration/migrate_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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}) }) From 8e539117d98ae029d9d197f83226323a5709720b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 22:27:26 +0100 Subject: [PATCH 17/18] adjust tests (9) --- tests/integration/org_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/org_test.go b/tests/integration/org_test.go index 9a7c947b83069..2cb28b12d7723 100644 --- a/tests/integration/org_test.go +++ b/tests/integration/org_test.go @@ -74,7 +74,7 @@ func TestLimitedOrg(t *testing.T) { session.MakeRequest(t, req, http.StatusOK) 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) } @@ -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) } From d63f28289c5c5d1f9f56664277d94ea4ed9ef82c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 31 Oct 2024 22:48:45 +0100 Subject: [PATCH 18/18] adjust tests (10) --- tests/integration/repo_branch_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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())