From 6840a8ccfcdbdcc352eac40a5c9beabf6e7c54ff Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Mon, 20 Feb 2023 04:30:36 +0200 Subject: [PATCH 01/23] Add comment marking the end of database migrations in `1.19.0` (#22975) There will be no more migrations in `1.19.0` --------- Signed-off-by: Yarden Shoham --- models/migrations/migrations.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index c7497becd1130..989a1d6ae1fb3 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -461,6 +461,8 @@ var migrations = []Migration{ NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText), // v243 -> v244 NewMigration("Add exclusive label", v1_19.AddExclusiveLabel), + + // Gitea 1.19.0 ends at v244 } // GetCurrentDBVersion returns the current db version From 2b3f12f6fd12afebb3b8397dc612621df6c730e2 Mon Sep 17 00:00:00 2001 From: Kyle D Date: Sun, 19 Feb 2023 20:56:07 -0700 Subject: [PATCH 02/23] Use beforeCommit instead of baseCommit (#22949) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces: https://github.com/go-gitea/gitea/pull/22947 Fixes https://github.com/go-gitea/gitea/issues/22946 Probably related to https://github.com/go-gitea/gitea/issues/19530 Basically, many of the diffs were broken because they were comparing to the base commit, where a 3-dot diff should be comparing to the [last common ancestor](https://matthew-brett.github.io/pydagogue/git_diff_dots.html). This should have an integration test so that we don’t run into this issue again. --------- Co-authored-by: Jonathan Tran --- models/db/iterate_test.go | 2 +- models/fixtures/repo_unit.yml | 13 +++ routers/web/repo/compare.go | 11 ++- templates/repo/diff/box.tmpl | 2 +- .../repo20.git/hooks/post-receive.d/gitea | 2 +- .../repo20.git/hooks/pre-receive.d/gitea | 2 +- .../user2/repo20.git/hooks/update.d/gitea | 2 +- .../07/0b2e783a6b3e521a23fdead377a3e41a04410d | Bin 0 -> 128 bytes .../79/adb592126eddce5f656f56db797910db025af0 | Bin 0 -> 165 bytes .../8b/abce967f21b9dfa6987f943b91093dac58a4f0 | 1 + .../a4/202876cd8bbc3f38b7d99594edbe1bb7f97a6f | Bin 0 -> 191 bytes .../b0/246d5964a3630491bd06c756be46513e3d7035 | Bin 0 -> 21 bytes .../b6/7e43a07d48243a5f670ace063acd5e13f719df | Bin 0 -> 173 bytes .../c8/e31bc7688741a5287fcde4fbb8fc129ca07027 | 2 + .../cf/e3b3c1fd36fba04f9183287b106497e1afe986 | 3 + .../ea/f5f7510320b6a327fb308379de2f94d8859a54 | Bin 0 -> 30 bytes .../user2/repo20.git/refs/heads/add-csv | 1 + .../repo20.git/refs/heads/remove-files-a | 1 + .../repo20.git/refs/heads/remove-files-b | 1 + tests/integration/compare_test.go | 78 ++++++++++++++++++ 20 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/07/0b2e783a6b3e521a23fdead377a3e41a04410d create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/79/adb592126eddce5f656f56db797910db025af0 create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/8b/abce967f21b9dfa6987f943b91093dac58a4f0 create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/a4/202876cd8bbc3f38b7d99594edbe1bb7f97a6f create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/b0/246d5964a3630491bd06c756be46513e3d7035 create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/b6/7e43a07d48243a5f670ace063acd5e13f719df create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/c8/e31bc7688741a5287fcde4fbb8fc129ca07027 create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/cf/e3b3c1fd36fba04f9183287b106497e1afe986 create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/objects/ea/f5f7510320b6a327fb308379de2f94d8859a54 create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/refs/heads/add-csv create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-a create mode 100644 tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-b diff --git a/models/db/iterate_test.go b/models/db/iterate_test.go index 63487afa49b15..a713fe0d8b85c 100644 --- a/models/db/iterate_test.go +++ b/models/db/iterate_test.go @@ -25,7 +25,7 @@ func TestIterate(t *testing.T) { return nil }) assert.NoError(t, err) - assert.EqualValues(t, 81, repoCnt) + assert.EqualValues(t, 83, repoCnt) err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error { reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID} diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 8706717ad46e8..503b8c9ddfa46 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -556,3 +556,16 @@ repo_id: 54 type: 1 created_unix: 946684810 + +- + id: 82 + repo_id: 31 + type: 1 + created_unix: 946684810 + +- + id: 83 + repo_id: 31 + type: 3 + config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" + created_unix: 946684810 diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 4e40867de204c..f21611c6348dd 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -43,8 +43,8 @@ const ( ) // setCompareContext sets context data. -func setCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, headName string) { - ctx.Data["BaseCommit"] = base +func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string) { + ctx.Data["BeforeCommit"] = before ctx.Data["HeadCommit"] = head ctx.Data["GetBlobByPathForCommit"] = func(commit *git.Commit, path string) *git.Blob { @@ -59,7 +59,7 @@ func setCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, return blob } - setPathsCompareContext(ctx, base, head, headOwner, headName) + setPathsCompareContext(ctx, before, head, headOwner, headName) setImageCompareContext(ctx) setCsvCompareContext(ctx) } @@ -629,9 +629,8 @@ func PrepareCompareDiff( } baseGitRepo := ctx.Repo.GitRepo - baseCommitID := ci.CompareInfo.BaseCommitID - baseCommit, err := baseGitRepo.GetCommit(baseCommitID) + beforeCommit, err := baseGitRepo.GetCommit(beforeCommitID) if err != nil { ctx.ServerError("GetCommit", err) return false @@ -668,7 +667,7 @@ func PrepareCompareDiff( ctx.Data["Username"] = ci.HeadUser.Name ctx.Data["Reponame"] = ci.HeadRepo.Name - setCompareContext(ctx, baseCommit, headCommit, ci.HeadUser.Name, repo.Name) + setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, repo.Name) return false } diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 62cc069555fd1..1e7982435586b 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -71,7 +71,7 @@
{{range $i, $file := .Diff.Files}} {{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}} - {{$blobBase := call $.GetBlobByPathForCommit $.BaseCommit $file.OldName}} + {{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}} {{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}} {{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}} {{$isCsv := (call $.IsCsvFile $file)}} diff --git a/tests/gitea-repositories-meta/user2/repo20.git/hooks/post-receive.d/gitea b/tests/gitea-repositories-meta/user2/repo20.git/hooks/post-receive.d/gitea index ee2ab2f2df2b8..43a948da3a983 100755 --- a/tests/gitea-repositories-meta/user2/repo20.git/hooks/post-receive.d/gitea +++ b/tests/gitea-repositories-meta/user2/repo20.git/hooks/post-receive.d/gitea @@ -1,2 +1,2 @@ #!/usr/bin/env bash -"/home/tris/Projects/go/src/code.gitea.io/gitea/gitea" hook --config='/home/tris/Projects/go/src/code.gitea.io/gitea/custom/conf/app.ini' post-receive +"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" post-receive diff --git a/tests/gitea-repositories-meta/user2/repo20.git/hooks/pre-receive.d/gitea b/tests/gitea-repositories-meta/user2/repo20.git/hooks/pre-receive.d/gitea index cdbc3c7c1a69b..49d09406364a5 100755 --- a/tests/gitea-repositories-meta/user2/repo20.git/hooks/pre-receive.d/gitea +++ b/tests/gitea-repositories-meta/user2/repo20.git/hooks/pre-receive.d/gitea @@ -1,2 +1,2 @@ #!/usr/bin/env bash -"/home/tris/Projects/go/src/code.gitea.io/gitea/gitea" hook --config='/home/tris/Projects/go/src/code.gitea.io/gitea/custom/conf/app.ini' pre-receive +"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" pre-receive diff --git a/tests/gitea-repositories-meta/user2/repo20.git/hooks/update.d/gitea b/tests/gitea-repositories-meta/user2/repo20.git/hooks/update.d/gitea index 7447b2fe01109..38101c242664a 100755 --- a/tests/gitea-repositories-meta/user2/repo20.git/hooks/update.d/gitea +++ b/tests/gitea-repositories-meta/user2/repo20.git/hooks/update.d/gitea @@ -1,2 +1,2 @@ #!/usr/bin/env bash -"/home/tris/Projects/go/src/code.gitea.io/gitea/gitea" hook --config='/home/tris/Projects/go/src/code.gitea.io/gitea/custom/conf/app.ini' update $1 $2 $3 +"$GITEA_ROOT/gitea" hook --config="$GITEA_ROOT/$GITEA_CONF" update $1 $2 $3 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/objects/07/0b2e783a6b3e521a23fdead377a3e41a04410d b/tests/gitea-repositories-meta/user2/repo20.git/objects/07/0b2e783a6b3e521a23fdead377a3e41a04410d new file mode 100644 index 0000000000000000000000000000000000000000..7ec6df17fbb8e3b25c5c31f866f2dd4ec3ccafe0 GIT binary patch literal 128 zcmV-`0Du2@0V^p=O;s>7HfAs}00M@3WKAUhDKy*_wtRA`}fY#mbBaP(exd% i3XnkzOrobB+Nw=mblA;n>(lw}pKI*DUIhR*r8f`;wL;SX literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/objects/79/adb592126eddce5f656f56db797910db025af0 b/tests/gitea-repositories-meta/user2/repo20.git/objects/79/adb592126eddce5f656f56db797910db025af0 new file mode 100644 index 0000000000000000000000000000000000000000..0071ac75b4bfacbc195a4ed815c400b8704bb366 GIT binary patch literal 165 zcmV;W09yZe0V^p=O;s>7vt%$a00M@3WKAUhDKy*_wtRA`}fY#mbBaP(exd% z3XnkzOrobB+Nw=mblA;n>(lw}pKI*DUNtl@Ff%bxC`m0Y(JQGaVR-fRdmyvIw#Dkd T4Vo+O=})=QIx7SK^4La`N~u-D literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/objects/8b/abce967f21b9dfa6987f943b91093dac58a4f0 b/tests/gitea-repositories-meta/user2/repo20.git/objects/8b/abce967f21b9dfa6987f943b91093dac58a4f0 new file mode 100644 index 0000000000000..06bf6dc972c8e --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo20.git/objects/8b/abce967f21b9dfa6987f943b91093dac58a4f0 @@ -0,0 +1 @@ +xAn0 s+l [_ATkIJC>z[,f1Z!K̀SL5[,D҉':aRнeDl :^CglHd>iqrms1Km=?U3okߝ{@wʼE] \ No newline at end of file diff --git a/tests/gitea-repositories-meta/user2/repo20.git/objects/a4/202876cd8bbc3f38b7d99594edbe1bb7f97a6f b/tests/gitea-repositories-meta/user2/repo20.git/objects/a4/202876cd8bbc3f38b7d99594edbe1bb7f97a6f new file mode 100644 index 0000000000000000000000000000000000000000..5096e42a239f82cf71251c3b96bd97c339bf1dde GIT binary patch literal 191 zcmV;w06_nE0V^p=O;s>5Fkvt;00M@3WKAUhDKy*_wtRA`}fY#mbBaP(exd% zii}JK&FE!o!v9{$Pg*Ke^o1{B+r4GeHz6wl*~P#lditTQ+SEmd-MqFwo$vm+#{TP7 tLjwad6BC7!)Z!Ao0euMOo(*zQCZwY3m>%#Dd)%0y&8b6-|m-cci&JxdPk&^qziN zN|_YU<3U#uuw)|&12$v%n3`ue_I~YTd7o!qa?AOSym>S_jEvfFIjiYuei0seJ31 bo6MpDDw`hD_6J-u%u{{cpOg6jb7x6@F5XqV literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/objects/c8/e31bc7688741a5287fcde4fbb8fc129ca07027 b/tests/gitea-repositories-meta/user2/repo20.git/objects/c8/e31bc7688741a5287fcde4fbb8fc129ca07027 new file mode 100644 index 0000000000000..48bb1a43d94bf --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo20.git/objects/c8/e31bc7688741a5287fcde4fbb8fc129ca07027 @@ -0,0 +1,2 @@ +xA +0@Q9\@N&w"L4Ҧ+Z؀vm`!&u֎mFKla8t]l;H}g9'2}{*lQ}&+i+unv0NX ,!{D&:uI *|i}a=gw<;p4EQH#1Q;~y$k@v-VC+? literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/add-csv b/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/add-csv new file mode 100644 index 0000000000000..c95a517668423 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/add-csv @@ -0,0 +1 @@ +c8e31bc7688741a5287fcde4fbb8fc129ca07027 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-a b/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-a new file mode 100644 index 0000000000000..138f2f43d50a7 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-a @@ -0,0 +1 @@ +cfe3b3c1fd36fba04f9183287b106497e1afe986 diff --git a/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-b b/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-b new file mode 100644 index 0000000000000..04270e29bd41b --- /dev/null +++ b/tests/gitea-repositories-meta/user2/repo20.git/refs/heads/remove-files-b @@ -0,0 +1 @@ +8babce967f21b9dfa6987f943b91093dac58a4f0 diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index dc2bff89fd452..509524ca5627c 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -4,6 +4,7 @@ package integration import ( + "fmt" "net/http" "strings" "testing" @@ -40,3 +41,80 @@ func TestCompareDefault(t *testing.T) { selection := htmlDoc.doc.Find(".choose.branch .filter.dropdown") assert.Lenf(t, selection.Nodes, 2, "The template has changed") } + +// Ensure the comparison matches what we expect +func inspectCompare(t *testing.T, htmlDoc *HTMLDoc, diffCount int, diffChanges []string) { + selection := htmlDoc.doc.Find("#diff-file-boxes").Children() + + assert.Lenf(t, selection.Nodes, diffCount, "Expected %v diffed files, found: %v", diffCount, len(selection.Nodes)) + + for _, diffChange := range diffChanges { + selection = htmlDoc.doc.Find(fmt.Sprintf("[data-new-filename=\"%s\"]", diffChange)) + assert.Lenf(t, selection.Nodes, 1, "Expected 1 match for [data-new-filename=\"%s\"], found: %v", diffChange, len(selection.Nodes)) + } +} + +// Git commit graph for repo20 +// * 8babce9 (origin/remove-files-b) Add a dummy file +// * b67e43a Delete test.csv and link_hi +// | * cfe3b3c (origin/remove-files-a) Delete test.csv and link_hi +// |/ +// * c8e31bc (origin/add-csv) Add test csv file +// * 808038d (HEAD -> master, origin/master, origin/HEAD) Added test links + +func TestCompareBranches(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + // Inderect compare remove-files-b (head) with add-csv (base) branch + // + // 'link_hi' and 'test.csv' are deleted, 'test.txt' is added + req := NewRequest(t, "GET", "/user2/repo20/compare/add-csv...remove-files-b") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + diffCount := 3 + diffChanges := []string{"link_hi", "test.csv", "test.txt"} + + inspectCompare(t, htmlDoc, diffCount, diffChanges) + + // Inderect compare remove-files-b (head) with remove-files-a (base) branch + // + // 'link_hi' and 'test.csv' are deleted, 'test.txt' is added + + req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-a...remove-files-b") + resp = session.MakeRequest(t, req, http.StatusOK) + htmlDoc = NewHTMLParser(t, resp.Body) + + diffCount = 3 + diffChanges = []string{"link_hi", "test.csv", "test.txt"} + + inspectCompare(t, htmlDoc, diffCount, diffChanges) + + // Inderect compare remove-files-a (head) with remove-files-b (base) branch + // + // 'link_hi' and 'test.csv' are deleted + + req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b...remove-files-a") + resp = session.MakeRequest(t, req, http.StatusOK) + htmlDoc = NewHTMLParser(t, resp.Body) + + diffCount = 2 + diffChanges = []string{"link_hi", "test.csv"} + + inspectCompare(t, htmlDoc, diffCount, diffChanges) + + // Direct compare remove-files-b (head) with remove-files-a (base) branch + // + // 'test.txt' is deleted + + req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b..remove-files-a") + resp = session.MakeRequest(t, req, http.StatusOK) + htmlDoc = NewHTMLParser(t, resp.Body) + + diffCount = 1 + diffChanges = []string{"test.txt"} + + inspectCompare(t, htmlDoc, diffCount, diffChanges) +} From ef11d41639dd1e89676e395068ee453312560adb Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 20 Feb 2023 05:20:30 +0000 Subject: [PATCH 03/23] Make CI use a dummy password hasher for all tests (#22983) During the recent hash algorithm change it became clear that the choice of password hash algorithm plays a role in the time taken for CI to run. Therefore as attempt to improve CI we should consider using a dummy hashing algorithm instead of a real hashing algorithm. This PR creates a dummy algorithm which is then set as the default hashing algorithm during tests that use the fixtures. This hopefully will cause a reduction in the time it takes for CI to run. --------- Signed-off-by: Andrew Thornton Co-authored-by: Lunny Xiao --- models/fixtures/user.yml | 132 +++++++++++------------ models/unittest/fixtures.go | 10 ++ modules/auth/password/hash/argon2.go | 2 +- modules/auth/password/hash/bcrypt.go | 2 +- modules/auth/password/hash/dummy.go | 33 ++++++ modules/auth/password/hash/dummy_test.go | 25 +++++ modules/auth/password/hash/hash.go | 13 ++- modules/auth/password/hash/hash_test.go | 8 +- modules/auth/password/hash/pbkdf2.go | 2 +- modules/auth/password/hash/scrypt.go | 2 +- modules/setting/setting.go | 5 + 11 files changed, 160 insertions(+), 74 deletions(-) create mode 100644 modules/auth/password/hash/dummy.go create mode 100644 modules/auth/password/hash/dummy_test.go diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index b5f8b27215bb7..b1c7fc0030675 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -8,8 +8,8 @@ email: user1@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user1 @@ -45,8 +45,8 @@ email: user2@example.com keep_email_private: true email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user2 @@ -82,8 +82,8 @@ email: user3@example.com keep_email_private: false email_notifications_preference: onmention - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user3 @@ -119,8 +119,8 @@ email: user4@example.com keep_email_private: false email_notifications_preference: onmention - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user4 @@ -156,8 +156,8 @@ email: user5@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user5 @@ -193,8 +193,8 @@ email: user6@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user6 @@ -230,8 +230,8 @@ email: user7@example.com keep_email_private: false email_notifications_preference: disabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user7 @@ -267,8 +267,8 @@ email: user8@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user8 @@ -304,8 +304,8 @@ email: user9@example.com keep_email_private: false email_notifications_preference: onmention - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user9 @@ -341,8 +341,8 @@ email: user10@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user10 @@ -378,8 +378,8 @@ email: user11@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user11 @@ -415,8 +415,8 @@ email: user12@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user12 @@ -452,8 +452,8 @@ email: user13@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user13 @@ -489,8 +489,8 @@ email: user14@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user14 @@ -526,8 +526,8 @@ email: user15@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user15 @@ -563,8 +563,8 @@ email: user16@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user16 @@ -600,8 +600,8 @@ email: user17@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user17 @@ -637,8 +637,8 @@ email: user18@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user18 @@ -674,8 +674,8 @@ email: user19@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user19 @@ -711,8 +711,8 @@ email: user20@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user20 @@ -748,8 +748,8 @@ email: user21@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user21 @@ -785,8 +785,8 @@ email: limited_org@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: limited_org @@ -822,8 +822,8 @@ email: privated_org@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: privated_org @@ -859,8 +859,8 @@ email: user24@example.com keep_email_private: true email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user24 @@ -896,8 +896,8 @@ email: org25@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: org25 @@ -933,8 +933,8 @@ email: org26@example.com keep_email_private: false email_notifications_preference: onmention - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: org26 @@ -970,8 +970,8 @@ email: user27@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user27 @@ -1007,8 +1007,8 @@ email: user28@example.com keep_email_private: true email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user28 @@ -1044,8 +1044,8 @@ email: user29@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user29 @@ -1081,8 +1081,8 @@ email: user30@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user30 @@ -1118,8 +1118,8 @@ email: user31@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user31 @@ -1155,8 +1155,8 @@ email: user32@example.com keep_email_private: false email_notifications_preference: enabled - passwd: 7d93daa0d1e6f2305cc8fa496847d61dc7320bb16262f9c55dd753480207234cdd96a93194e408341971742f47017 - passwd_hash_algo: argon2 + passwd: ZogKvWdyEx:notpassword + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user32 @@ -1192,8 +1192,8 @@ email: user33@example.com keep_email_private: false email_notifications_preference: enabled - passwd: e82bc8ae42a53b98c3bd0f941aacc4aa2a264407534b0a11bf270137f67af912f694b67951f92148c45f91717e1478ca7889 - passwd_hash_algo: pbkdf2$50000$50 + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy must_change_password: false login_source: 0 login_name: user33 diff --git a/models/unittest/fixtures.go b/models/unittest/fixtures.go index 9fba053825b93..545452a159fb5 100644 --- a/models/unittest/fixtures.go +++ b/models/unittest/fixtures.go @@ -9,6 +9,8 @@ import ( "time" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/modules/auth/password/hash" + "code.gitea.io/gitea/modules/setting" "github.com/go-testfixtures/testfixtures/v3" "xorm.io/xorm" @@ -64,6 +66,11 @@ func InitFixtures(opts FixturesOptions, engine ...*xorm.Engine) (err error) { return err } + // register the dummy hash algorithm function used in the test fixtures + _ = hash.Register("dummy", hash.NewDummyHasher) + + setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy") + return err } @@ -115,5 +122,8 @@ func LoadFixtures(engine ...*xorm.Engine) error { } } } + _ = hash.Register("dummy", hash.NewDummyHasher) + setting.PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy") + return err } diff --git a/modules/auth/password/hash/argon2.go b/modules/auth/password/hash/argon2.go index 14c16b53c4287..0cd6472fa1270 100644 --- a/modules/auth/password/hash/argon2.go +++ b/modules/auth/password/hash/argon2.go @@ -13,7 +13,7 @@ import ( ) func init() { - Register("argon2", NewArgon2Hasher) + MustRegister("argon2", NewArgon2Hasher) } // Argon2Hasher implements PasswordHasher diff --git a/modules/auth/password/hash/bcrypt.go b/modules/auth/password/hash/bcrypt.go index ddf5420408f30..4607c169cd854 100644 --- a/modules/auth/password/hash/bcrypt.go +++ b/modules/auth/password/hash/bcrypt.go @@ -8,7 +8,7 @@ import ( ) func init() { - Register("bcrypt", NewBcryptHasher) + MustRegister("bcrypt", NewBcryptHasher) } // BcryptHasher implements PasswordHasher diff --git a/modules/auth/password/hash/dummy.go b/modules/auth/password/hash/dummy.go new file mode 100644 index 0000000000000..22f2e2f648e7a --- /dev/null +++ b/modules/auth/password/hash/dummy.go @@ -0,0 +1,33 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package hash + +import ( + "encoding/hex" +) + +// DummyHasher implements PasswordHasher and is a dummy hasher that simply +// puts the password in place with its salt +// This SHOULD NOT be used in production and is provided to make the integration +// tests faster only +type DummyHasher struct{} + +// HashWithSaltBytes a provided password and salt +func (hasher *DummyHasher) HashWithSaltBytes(password string, salt []byte) string { + if hasher == nil { + return "" + } + + if len(salt) == 10 { + return string(salt) + ":" + password + } + + return hex.EncodeToString(salt) + ":" + password +} + +// NewDummyHasher is a factory method to create a DummyHasher +// Any provided configuration is ignored +func NewDummyHasher(_ string) *DummyHasher { + return &DummyHasher{} +} diff --git a/modules/auth/password/hash/dummy_test.go b/modules/auth/password/hash/dummy_test.go new file mode 100644 index 0000000000000..f3b36df625044 --- /dev/null +++ b/modules/auth/password/hash/dummy_test.go @@ -0,0 +1,25 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package hash + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDummyHasher(t *testing.T) { + dummy := &PasswordHashAlgorithm{ + PasswordSaltHasher: NewDummyHasher(""), + Specification: "dummy", + } + + password, salt := "password", "ZogKvWdyEx" + + hash, err := dummy.Hash(password, salt) + assert.Nil(t, err) + assert.Equal(t, hash, salt+":"+password) + + assert.True(t, dummy.VerifyPassword(password, hash, salt)) +} diff --git a/modules/auth/password/hash/hash.go b/modules/auth/password/hash/hash.go index 3572dd46d4777..459320e1b0222 100644 --- a/modules/auth/password/hash/hash.go +++ b/modules/auth/password/hash/hash.go @@ -83,17 +83,26 @@ var ( availableHasherFactories = map[string]func(string) PasswordSaltHasher{} ) +// MustRegister registers a PasswordSaltHasher with the availableHasherFactories +// Caution: This is not thread safe. +func MustRegister[T PasswordSaltHasher](name string, newFn func(config string) T) { + if err := Register(name, newFn); err != nil { + panic(err) + } +} + // Register registers a PasswordSaltHasher with the availableHasherFactories // Caution: This is not thread safe. -func Register[T PasswordSaltHasher](name string, newFn func(config string) T) { +func Register[T PasswordSaltHasher](name string, newFn func(config string) T) error { if _, has := availableHasherFactories[name]; has { - panic(fmt.Errorf("duplicate registration of password salt hasher: %s", name)) + return fmt.Errorf("duplicate registration of password salt hasher: %s", name) } availableHasherFactories[name] = func(config string) PasswordSaltHasher { n := newFn(config) return n } + return nil } // In early versions of gitea the password hash algorithm field of a user could be diff --git a/modules/auth/password/hash/hash_test.go b/modules/auth/password/hash/hash_test.go index 593c8386a3558..7aa051733f825 100644 --- a/modules/auth/password/hash/hash_test.go +++ b/modules/auth/password/hash/hash_test.go @@ -19,16 +19,20 @@ func (t testSaltHasher) HashWithSaltBytes(password string, salt []byte) string { } func Test_registerHasher(t *testing.T) { - Register("Test_registerHasher", func(config string) testSaltHasher { + MustRegister("Test_registerHasher", func(config string) testSaltHasher { return testSaltHasher(config) }) assert.Panics(t, func() { - Register("Test_registerHasher", func(config string) testSaltHasher { + MustRegister("Test_registerHasher", func(config string) testSaltHasher { return testSaltHasher(config) }) }) + assert.Error(t, Register("Test_registerHasher", func(config string) testSaltHasher { + return testSaltHasher(config) + })) + assert.Equal(t, "password$salt$", Parse("Test_registerHasher").PasswordSaltHasher.HashWithSaltBytes("password", []byte("salt"))) diff --git a/modules/auth/password/hash/pbkdf2.go b/modules/auth/password/hash/pbkdf2.go index be3121318e3ea..27382fedb8cb0 100644 --- a/modules/auth/password/hash/pbkdf2.go +++ b/modules/auth/password/hash/pbkdf2.go @@ -14,7 +14,7 @@ import ( ) func init() { - Register("pbkdf2", NewPBKDF2Hasher) + MustRegister("pbkdf2", NewPBKDF2Hasher) } // PBKDF2Hasher implements PasswordHasher diff --git a/modules/auth/password/hash/scrypt.go b/modules/auth/password/hash/scrypt.go index e77434fc32b2a..f3d38f751a3b7 100644 --- a/modules/auth/password/hash/scrypt.go +++ b/modules/auth/password/hash/scrypt.go @@ -13,7 +13,7 @@ import ( ) func init() { - Register("scrypt", NewScryptHasher) + MustRegister("scrypt", NewScryptHasher) } // ScryptHasher implements PasswordHasher diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 83ebde9478827..87b1e2797fe7d 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -16,6 +16,7 @@ import ( "strings" "time" + "code.gitea.io/gitea/modules/auth/password/hash" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/user" "code.gitea.io/gitea/modules/util" @@ -232,6 +233,10 @@ func InitProviderAndLoadCommonSettingsForTest(extraConfigs ...string) { if err := PrepareAppDataPath(); err != nil { log.Fatal("Can not prepare APP_DATA_PATH: %v", err) } + // register the dummy hash algorithm function used in the test fixtures + _ = hash.Register("dummy", hash.NewDummyHasher) + + PasswordHashAlgo, _ = hash.SetDefaultPasswordHashAlgorithm("dummy") } // newFileProviderFromConf initializes configuration context. From b811ab48e513a5b98edb935e0c63e76233ee1783 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 20 Feb 2023 16:08:33 +0900 Subject: [PATCH 04/23] Add all units to the units permission list in org team members sidebar (#22971) Add all units to the units permission list in org team members sidebar. Before: ![BQF448EIHEYKY62XGG(5101](https://user-images.githubusercontent.com/18380374/219877772-b57df8fb-2b82-4b1a-85c8-3809f8751cab.png) After: ![image](https://user-images.githubusercontent.com/18380374/219877762-f69482b8-abf9-4333-978e-6a3f52039a16.png) Co-authored-by: Lunny Xiao --- templates/org/team/sidebar.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/org/team/sidebar.tmpl b/templates/org/team/sidebar.tmpl index ab118a7e263f4..507173e51fcff 100644 --- a/templates/org/team/sidebar.tmpl +++ b/templates/org/team/sidebar.tmpl @@ -58,7 +58,7 @@ {{range $t, $unit := $.Units}} - {{if and (lt $unit.MaxPerm 2) (not $unit.Type.UnitGlobalDisabled)}} + {{if (not $unit.Type.UnitGlobalDisabled)}} {{$.locale.Tr $unit.NameKey}} {{if eq ($.Team.UnitAccessMode $.Context $unit.Type) 0 -}} From 1d64eafe8f296e77c59c18fcda428d2b5df67ac0 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 20 Feb 2023 16:42:02 +0800 Subject: [PATCH 05/23] Add me to maintainers (#22998) Add me to maintainers. [List of merged PRs](https://github.com/go-gitea/gitea/pulls?q=is%3Apr+author%3AZettat123+is%3Amerged) Co-authored-by: Jason Song --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index a37d336de3a4c..b1adf9ef0d657 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -47,3 +47,4 @@ Wim (@42wim) Xinyu Zhou (@xin-u) Jason Song (@wolfogre) Yarden Shoham (@yardenshoham) +Yu Tian (@Zettat123) From 3596df52c09831f7f39f8416264ff267954f35a0 Mon Sep 17 00:00:00 2001 From: oliverpool <3864879+oliverpool@users.noreply.github.com> Date: Mon, 20 Feb 2023 09:43:04 +0100 Subject: [PATCH 06/23] Fix hidden commit status on multiple checks (#22889) Since #22632, when a commit status has multiple checks, no check is shown at all (hence no way to see the other checks). This PR fixes this by always adding a tag with the `.commit-statuses-trigger` to the DOM (the `.vm` is for vertical alignment). ![2023-02-13-120528](https://user-images.githubusercontent.com/3864879/218441846-1a79c169-2efd-46bb-9e75-d8b45d7cc8e3.png) --------- Co-authored-by: Lunny Xiao --- templates/repo/commit_statuses.tmpl | 16 +++++-- tests/integration/git_test.go | 15 +++++-- tests/integration/pull_status_test.go | 21 ++++++---- tests/integration/repo_commits_test.go | 58 ++++++++++++++++++++++++-- web_src/js/features/repo-commit.js | 2 +- web_src/less/_base.less | 3 +- web_src/less/_repository.less | 24 ----------- 7 files changed, 92 insertions(+), 47 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 8250a858173be..8858fb8402129 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,6 +1,14 @@ -{{if eq (len .Statuses) 1}}{{$status := index .Statuses 0}}{{if $status.TargetURL}}{{template "repo/commit_status" .Status}}{{end}}{{end}} -
-
+{{if .Statuses}} + {{if and (eq (len .Statuses) 1) .Status.TargetURL}} + + {{template "repo/commit_status" .Status}} + + {{else}} + + {{template "repo/commit_status" .Status}} + + {{end}} +
{{range .Statuses}}
{{template "repo/commit_status" .}} @@ -11,4 +19,4 @@
{{end}}
-
+{{end}} diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go index 420a8676b9ed6..d21f3994a1d98 100644 --- a/tests/integration/git_test.go +++ b/tests/integration/git_test.go @@ -630,8 +630,17 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { commitID := path.Base(commitURL) + addCommitStatus := func(status api.CommitStatusState) func(*testing.T) { + return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{ + State: status, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + }) + } + // Call API to add Pending status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusPending)) + t.Run("CreateStatus", addCommitStatus(api.CommitStatusPending)) // Cancel not existing auto merge ctx.ExpectedCode = http.StatusNotFound @@ -660,7 +669,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { assert.False(t, pr.HasMerged) // Call API to add Failure status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusFailure)) + t.Run("CreateStatus", addCommitStatus(api.CommitStatusFailure)) // Check pr status pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t) @@ -668,7 +677,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) { assert.False(t, pr.HasMerged) // Call API to add Success status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusSuccess)) + t.Run("CreateStatus", addCommitStatus(api.CommitStatusSuccess)) // wait to let gitea merge stuff time.Sleep(time.Second) diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go index e60d17edc02ca..736d1ee4f0eec 100644 --- a/tests/integration/pull_status_test.go +++ b/tests/integration/pull_status_test.go @@ -70,7 +70,12 @@ func TestPullCreate_CommitStatus(t *testing.T) { for _, status := range statusList { // Call API to add status for commit - t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, status)) + t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, api.CreateStatusOption{ + State: status, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + })) req = NewRequestf(t, "GET", "/user1/repo1/pulls/1/commits") resp = session.MakeRequest(t, req, http.StatusOK) @@ -88,15 +93,13 @@ func TestPullCreate_CommitStatus(t *testing.T) { }) } -func doAPICreateCommitStatus(ctx APITestContext, commitID string, status api.CommitStatusState) func(*testing.T) { +func doAPICreateCommitStatus(ctx APITestContext, commitID string, data api.CreateStatusOption) func(*testing.T) { return func(t *testing.T) { - req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token), - api.CreateStatusOption{ - State: status, - TargetURL: "http://test.ci/", - Description: "", - Context: "testci", - }, + req := NewRequestWithJSON( + t, + http.MethodPost, + fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token), + data, ) if ctx.ExpectedCode != 0 { ctx.Session.MakeRequest(t, req, ctx.ExpectedCode) diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index cbd83c6deb174..e74e3867f4af9 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -52,14 +52,19 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { // Call API to add status for commit ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo) - t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState(state))) + t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusState(state), + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + })) req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master") resp = session.MakeRequest(t, req, http.StatusOK) doc = NewHTMLParser(t, resp.Body) - // Check if commit status is displayed in message column - sel := doc.doc.Find("#commits-table tbody tr td.message a.commit-statuses-trigger .commit-status") + // Check if commit status is displayed in message column (.tippy-target to ignore the tippy trigger) + sel := doc.doc.Find("#commits-table tbody tr td.message .tippy-target .commit-status") assert.Equal(t, 1, sel.Length()) for _, class := range classes { assert.True(t, sel.HasClass(class)) @@ -145,7 +150,12 @@ func TestRepoCommitsStatusParallel(t *testing.T) { go func(parentT *testing.T, i int) { parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) { ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepoStatus) - runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState("pending")) + runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusPending, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + }) runBody(t) wg.Done() }) @@ -153,3 +163,43 @@ func TestRepoCommitsStatusParallel(t *testing.T) { } wg.Wait() } + +func TestRepoCommitsStatusMultiple(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + + // Request repository commits page + req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master") + resp := session.MakeRequest(t, req, http.StatusOK) + + doc := NewHTMLParser(t, resp.Body) + // Get first commit URL + commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href") + assert.True(t, exists) + assert.NotEmpty(t, commitURL) + + // Call API to add status for commit + ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo) + t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusSuccess, + TargetURL: "http://test.ci/", + Description: "", + Context: "testci", + })) + + t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{ + State: api.CommitStatusSuccess, + TargetURL: "http://test.ci/", + Description: "", + Context: "other_context", + })) + + req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master") + resp = session.MakeRequest(t, req, http.StatusOK) + + doc = NewHTMLParser(t, resp.Body) + // Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present + sel := doc.doc.Find("#commits-table tbody tr td.message [data-tippy=\"commit-statuses\"] .commit-status") + assert.Equal(t, 1, sel.Length()) +} diff --git a/web_src/js/features/repo-commit.js b/web_src/js/features/repo-commit.js index e2eef3ee59028..d22aa8e980bd3 100644 --- a/web_src/js/features/repo-commit.js +++ b/web_src/js/features/repo-commit.js @@ -58,7 +58,7 @@ export function initRepoCommitLastCommitLoader() { } export function initCommitStatuses() { - $('.commit-statuses-trigger').each(function () { + $('[data-tippy="commit-statuses"]').each(function () { const top = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0; createTippy(this, { diff --git a/web_src/less/_base.less b/web_src/less/_base.less index fae29d0d60df6..fc04df4f94460 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -340,8 +340,7 @@ a.label, .ui.search .results a, .ui .menu a, .ui.cards a.card, -.issue-keyword a, -a.commit-statuses-trigger { +.issue-keyword a { text-decoration: none !important; } diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index f489335712abf..3bec5f58fbaf7 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -1,28 +1,4 @@ .repository { - .popup.commit-statuses { - // we had better limit the max size of the popup, and add scroll bars if the content size is too large. - // otherwise some part of the popup will be hidden by viewport boundary - max-height: 45vh; - max-width: 60vw; - - &.ui.right { - // Override `.ui.attached.header .right:not(.dropdown) height: 30px;` which would otherwise lead to - // the status popup box having its height fixed at 30px. See https://github.com/go-gitea/gitea/issues/18498 - height: auto; - } - - overflow: auto; - padding: 0; - - .list { - padding: .8em; // to make the scrollbar align to the border, we move the padding from outer `.popup` to this inside `.list` - - > .item { - line-height: 2; - } - } - } - .repo-header { .ui.compact.menu { margin-left: 1rem; From 9a83aa28a351c9af1731a94ce0e1b5d3842db4e8 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 20 Feb 2023 19:30:41 +0800 Subject: [PATCH 07/23] Get rules by id when editing branch protection rule (#22932) When users rename an existing branch protection rule, a new rule with the new name will be created and the old rule will still exist. ![image](https://user-images.githubusercontent.com/15528715/219276442-d3c001ad-e693-44ec-9ad2-b33f2666b49b.png) --- ![image](https://user-images.githubusercontent.com/15528715/219276478-547c3b93-b3f1-4292-a1ef-c1b7747fe1bb.png) The reason is that the `SettingsProtectedBranchPost` function only get branch protection rule by name before updating or creating a rule. When the rule name changes, the function cannot find the existing rule so it will create a new rule rather than update the existing rule. To fix the bug, the function should get rule by id first. --------- Co-authored-by: Lunny Xiao --- options/locale/locale_en-US.ini | 1 + routers/web/repo/setting_protected_branch.go | 34 +++++++++++++++++--- services/forms/repo_form.go | 1 + 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 411a585c81d60..92ca5be8d3584 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2152,6 +2152,7 @@ settings.choose_branch = Choose a branch… settings.no_protected_branch = There are no protected branches. settings.edit_protected_branch = Edit settings.protected_branch_required_rule_name = Required rule name +settings.protected_branch_duplicate_rule_name = Duplicate rule name settings.protected_branch_required_approvals_min = Required approvals cannot be negative. settings.tags = Tags settings.tags.protection = Tag Protection diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go index a54565c1f1512..0a8c39fef0735 100644 --- a/routers/web/repo/setting_protected_branch.go +++ b/routers/web/repo/setting_protected_branch.go @@ -166,10 +166,36 @@ func SettingsProtectedBranchPost(ctx *context.Context) { } var err error - protectBranch, err = git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName) - if err != nil { - ctx.ServerError("GetProtectBranchOfRepoByName", err) - return + if f.RuleID > 0 { + // If the RuleID isn't 0, it must be an edit operation. So we get rule by id. + protectBranch, err = git_model.GetProtectedBranchRuleByID(ctx, ctx.Repo.Repository.ID, f.RuleID) + if err != nil { + ctx.ServerError("GetProtectBranchOfRepoByID", err) + return + } + if protectBranch != nil && protectBranch.RuleName != f.RuleName { + // RuleName changed. We need to check if there is a rule with the same name. + // If a rule with the same name exists, an error should be returned. + sameNameProtectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName) + if err != nil { + ctx.ServerError("GetProtectBranchOfRepoByName", err) + return + } + if sameNameProtectBranch != nil { + ctx.Flash.Error(ctx.Tr("repo.settings.protected_branch_duplicate_rule_name")) + ctx.Redirect(fmt.Sprintf("%s/settings/branches/edit?rule_name=%s", ctx.Repo.RepoLink, protectBranch.RuleName)) + return + } + } + } else { + // FIXME: If a new ProtectBranch has a duplicate RuleName, an error should be returned. + // Currently, if a new ProtectBranch with a duplicate RuleName is created, the existing ProtectBranch will be updated. + // But we cannot modify this logic now because many unit tests rely on it. + protectBranch, err = git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, f.RuleName) + if err != nil { + ctx.ServerError("GetProtectBranchOfRepoByName", err) + return + } } if protectBranch == nil { // No options found, create defaults. diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index ff0916f8e195c..374ae0ac5cb59 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -190,6 +190,7 @@ func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) bindi // ProtectBranchForm form for changing protected branch settings type ProtectBranchForm struct { RuleName string `binding:"Required"` + RuleID int64 EnablePush string WhitelistUsers string WhitelistTeams string From c3d9a70d0a4fc77fe4c44028e72d1a9aadee3e5a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 20 Feb 2023 21:08:41 +0800 Subject: [PATCH 08/23] only trigger docs build and publish when docs changed (#22968) Since drone plugin https://github.com/meltwater/drone-convert-pathschanged/ enabled, we can filter event with path in drone. Building docs will now only be triggered when documentations changed. --------- Co-authored-by: Jason Song --- .drone.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 7150629028e3a..cf0caf7612f6f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,6 +12,9 @@ trigger: - push - tag - pull_request + paths: + exclude: + - docs/** volumes: - name: deps @@ -112,7 +115,6 @@ steps: image: golang:1.19 # this step is kept as the lowest version of golang that we support pull: always environment: - GO111MODULE: on GOPROXY: https://goproxy.io commands: - go build -o gitea_no_gcc # test if build succeeds without the sqlite tag @@ -124,7 +126,6 @@ steps: - name: build-backend-arm64 image: golang:1.20 environment: - GO111MODULE: on GOPROXY: https://goproxy.io GOOS: linux GOARCH: arm64 @@ -140,7 +141,6 @@ steps: - name: build-backend-windows image: golang:1.20 environment: - GO111MODULE: on GOPROXY: https://goproxy.io GOOS: windows GOARCH: amd64 @@ -155,7 +155,6 @@ steps: - name: build-backend-386 image: golang:1.20 environment: - GO111MODULE: on GOPROXY: https://goproxy.io GOOS: linux GOARCH: 386 @@ -183,6 +182,9 @@ trigger: - push - tag - pull_request + paths: + exclude: + - docs/** volumes: - name: deps @@ -410,6 +412,9 @@ trigger: - push - tag - pull_request + paths: + exclude: + - docs/** volumes: - name: deps @@ -517,6 +522,9 @@ depends_on: trigger: event: - pull_request + paths: + exclude: + - docs/** volumes: - name: deps @@ -696,6 +704,9 @@ trigger: - "release/*" event: - push + paths: + exclude: + - docs/** depends_on: - testing-amd64 @@ -947,6 +958,9 @@ trigger: - push - tag - pull_request + paths: + include: + - docs/** steps: - name: build-docs @@ -1241,6 +1255,9 @@ depends_on: trigger: ref: - "refs/pull/**" + paths: + exclude: + - docs/** steps: - name: dryrun From 36d1d5fb7871058e510e59b027d5ee32bba43f2b Mon Sep 17 00:00:00 2001 From: sillyguodong <33891828+sillyguodong@users.noreply.github.com> Date: Mon, 20 Feb 2023 22:22:34 +0800 Subject: [PATCH 09/23] Fix panic when call api (/repos/{owner}/{repo}/pulls/{index}/files) (#22921) Close: #22910 --- I'm confused about that why does the api (`GET /repos/{owner}/{repo}/pulls/{index}/files`) require caller to pass the parameters `limit` and `page`. In my case, the caller only needs to pass a `skip-to` to paging. This is consistent with the api `GET /{owner}/{repo}/pulls/{index}/files` So, I deleted the code related to `listOptions` --------- Co-authored-by: Lunny Xiao --- routers/api/v1/repo/pull.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 7005725cf6642..fa8b517ae77ce 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -1420,8 +1420,9 @@ func GetPullRequestFiles(ctx *context.APIContext) { startCommitID := prInfo.MergeBase endCommitID := headCommitID - maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles + maxLines := setting.Git.MaxGitDiffLines + // FIXME: If there are too many files in the repo, may cause some unpredictable issues. diff, err := gitdiff.GetDiff(baseGitRepo, &gitdiff.DiffOptions{ BeforeCommitID: startCommitID, @@ -1429,7 +1430,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { SkipTo: ctx.FormString("skip-to"), MaxLines: maxLines, MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, - MaxFiles: maxFiles, + MaxFiles: -1, // GetDiff() will return all files WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.FormString("whitespace")), }) if err != nil { @@ -1452,6 +1453,7 @@ func GetPullRequestFiles(ctx *context.APIContext) { if lenFiles < 0 { lenFiles = 0 } + apiFiles := make([]*api.ChangedFile, 0, lenFiles) for i := start; i < end; i++ { apiFiles = append(apiFiles, convert.ToChangedFile(diff.Files[i], pr.HeadRepo, endCommitID)) From 018815215fa08b530108f551ab58c1f1b3657799 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Feb 2023 23:52:21 +0800 Subject: [PATCH 10/23] Bump golang.org/x/net from 0.4.0 to 0.7.0 (#22980) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.4.0 to 0.7.0.
Commits
  • 8e2b117 http2/hpack: avoid quadratic complexity in hpack decoding
  • 547e7ed http2: avoid referencing ResponseWrite.Write parameter after returning
  • 39940ad html: parse comments per HTML spec
  • 87ce33e go.mod: update golang.org/x dependencies
  • 415cb6d all: fix some comments
  • 7e3c19c all: correct typos in comments
  • 296f09a http2: case insensitive handling for 100-continue
  • f8411da nettest: fix tests on dragonfly and js/wasm
  • 8e0e7d8 go.mod: update golang.org/x dependencies
  • 7805fdc http2: rewrite inbound flow control tracking
  • Additional commits viewable in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=golang.org/x/net&package-manager=go_modules&previous-version=0.4.0&new-version=0.7.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: techknowlogick Co-authored-by: delvh Co-authored-by: Lunny Xiao --- go.mod | 6 +++--- go.sum | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 3dc050b99a173..343a70da25a02 100644 --- a/go.mod +++ b/go.mod @@ -103,10 +103,10 @@ require ( github.com/yuin/goldmark-highlighting/v2 v2.0.0-20220924101305-151362477c87 github.com/yuin/goldmark-meta v1.1.0 golang.org/x/crypto v0.4.0 - golang.org/x/net v0.4.0 + golang.org/x/net v0.7.0 golang.org/x/oauth2 v0.3.0 - golang.org/x/sys v0.3.0 - golang.org/x/text v0.5.0 + golang.org/x/sys v0.5.0 + golang.org/x/text v0.7.0 golang.org/x/tools v0.1.12 google.golang.org/grpc v1.47.0 google.golang.org/protobuf v1.28.1 diff --git a/go.sum b/go.sum index 03c2cc18c66e4..7eb420b02b03a 100644 --- a/go.sum +++ b/go.sum @@ -1463,8 +1463,8 @@ golang.org/x/net v0.0.0-20220630215102-69896b714898/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= -golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1609,14 +1609,15 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= -golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1627,8 +1628,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= -golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 9aaf6998b735ad091202513c52b1d40076dd6afe Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 20 Feb 2023 17:08:32 +0100 Subject: [PATCH 11/23] Fix pull request branch selector visible without clicking Edit (#23012) Caused by #22950 --- templates/repo/issue/view_title.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index b43253f90b5b1..f0ac1e021ec4b 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -61,7 +61,7 @@ {{$.locale.Tr "repo.pulls.title_desc" .NumCommits $headHref $baseHref | Safe}} {{end}} - +
+ {{if $.IsOrganizationOwner}}
{{$.locale.Tr "admin.users.2fa"}}
@@ -51,6 +52,7 @@ {{end}}
+ {{end}}
{{end}}
From 97aacc3ea1ea89d5781da4b86a11f8340148ca49 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 21 Feb 2023 08:14:02 +0800 Subject: [PATCH 18/23] Improve pull_request_template.md (#22888) Update `pull_request_template.md` because: - It's a kind idea to hide the tips. However, it's easier to include them in the commit message by mistake when you cannot see them. Check `git log | grep 'Please check the following:'`. So don't hide it, expose it and help fix it. - "for backports" is much clearer than "for bug fixes". I saw someone post a PR to a release branch because they believed it was the right way for a bugfix. - "Allow edits by maintainers", or we have to ask the contributor to update the branch and they could be confused. - Remind the contributor that the words could be included in the commit message, to avoid some words like "Hello", "Sorry". If they really need them, they can separate them with a line, like: ```markdown Close #xxxx Because ... Then ... Finally ... --- Hello, this is my first time opening a pull request. Sorry for any mistakes. ``` And the merger should be careful, check and delete the extra content before merging. --------- Co-authored-by: techknowlogick --- .github/pull_request_template.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3a12bb8f721e6..b752abb794dec 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,9 +1,9 @@ - Please check the following: - -1. Make sure you are targeting the `main` branch, pull requests on release branches are only allowed for bug fixes. -2. Read contributing guidelines: https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md -3. Describe what your pull request does and which issue you're targeting (if any) - ---> +1. Make sure you are targeting the `main` branch, pull requests on release branches are only allowed for backports. +2. Make sure you have read contributing guidelines: https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md . +3. Describe what your pull request does and which issue you're targeting (if any). +4. It is recommended to enable "Allow edits by maintainers", so maintainers can help more easily. +5. Your input here will be included in the commit message when this PR has been merged. If you don't want some content to be included, please separate them with a line like `---`. +6. Delete all these tips before posting. + From 35d2fa744aae5782dcced573aa08ee9ff62c8e36 Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 21 Feb 2023 00:15:49 +0000 Subject: [PATCH 19/23] Fix intermittent panic in notify issue change content (#23019) Ensure that issue pullrequests are loaded before trying to set the self-reference. Signed-off-by: Andrew Thornton Co-authored-by: delvh Co-authored-by: techknowlogick --- models/issues/issue.go | 14 ++++++++------ services/webhook/notifier.go | 7 ++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/models/issues/issue.go b/models/issues/issue.go index 6c76909fcfd8a..c59e9d14e5370 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -251,13 +251,15 @@ func (issue *Issue) LoadPoster(ctx context.Context) (err error) { // LoadPullRequest loads pull request info func (issue *Issue) LoadPullRequest(ctx context.Context) (err error) { - if issue.IsPull && issue.PullRequest == nil { - issue.PullRequest, err = GetPullRequestByIssueID(ctx, issue.ID) - if err != nil { - if IsErrPullRequestNotExist(err) { - return err + if issue.IsPull { + if issue.PullRequest == nil { + issue.PullRequest, err = GetPullRequestByIssueID(ctx, issue.ID) + if err != nil { + if IsErrPullRequestNotExist(err) { + return err + } + return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err) } - return fmt.Errorf("getPullRequestByIssueID [%d]: %w", issue.ID, err) } issue.PullRequest.Issue = issue } diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index ba6d968dbd27b..b023717cd258e 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -150,7 +150,6 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *u log.Error("LoadPullRequest failed: %v", err) return } - issue.PullRequest.Issue = issue apiPullRequest := &api.PullRequestPayload{ Index: issue.Index, PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil), @@ -196,7 +195,6 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user log.Error("LoadPullRequest failed: %v", err) return } - issue.PullRequest.Issue = issue err = PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, webhook_module.HookEventPullRequest, &api.PullRequestPayload{ Action: api.HookIssueEdited, Index: issue.Index, @@ -328,7 +326,10 @@ func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *us mode, _ := access_model.AccessLevel(ctx, issue.Poster, issue.Repo) var err error if issue.IsPull { - issue.PullRequest.Issue = issue + if err := issue.LoadPullRequest(ctx); err != nil { + log.Error("LoadPullRequest: %v", err) + return + } err = PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, webhook_module.HookEventPullRequest, &api.PullRequestPayload{ Action: api.HookIssueEdited, Index: issue.Index, From 1b950b98cf98c5064bafbd57cd6cde1fa029881b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 21 Feb 2023 08:16:56 +0800 Subject: [PATCH 20/23] Use `gt-relative` class instead of the ambiguous `gt-pr` class (#23008) `.gt-relative` is also `position: relative !important;` There are `gt-pr-?` styles below (line 140) for `padding-right`, which makes `.gt-pr` ambiguous Co-authored-by: delvh Co-authored-by: John Olheiser Co-authored-by: techknowlogick --- templates/repo/commit_page.tmpl | 2 +- web_src/less/helpers.less | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 0ecbf29161997..028fdc7e51484 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -17,7 +17,7 @@ {{$class = (printf "%s%s" $class " isWarning")}} {{end}} {{end}} -
+

{{RenderCommitMessage $.Context .Commit.Message $.RepoLink $.Repository.ComposeMetas}}{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}

{{if not $.PageIsWiki}} diff --git a/web_src/less/helpers.less b/web_src/less/helpers.less index 9cabe01626f3b..baa5959946e82 100644 --- a/web_src/less/helpers.less +++ b/web_src/less/helpers.less @@ -2,7 +2,6 @@ .gt-di { display: inline !important; } .gt-dif { display: inline-flex !important; } .gt-dib { display: inline-block !important; } -.gt-pr { position: relative !important; } .gt-ac { align-items: center !important; } .gt-tc { text-align: center !important; } .gt-tl { text-align: left !important; } From 34ae184622ba1eee62d73f13db709bc6b646795f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 21 Feb 2023 10:22:13 +0800 Subject: [PATCH 21/23] Render access log template as text instead of HTML (#23013) Fix https://github.com/go-gitea/gitea/pull/22906#discussion_r1112106675 --- modules/context/access_log.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/context/access_log.go b/modules/context/access_log.go index 84663ee8d3b07..1aaba9dc2d5c9 100644 --- a/modules/context/access_log.go +++ b/modules/context/access_log.go @@ -6,8 +6,8 @@ package context import ( "bytes" "context" - "html/template" "net/http" + "text/template" "time" "code.gitea.io/gitea/modules/log" From 4fcf3a3f90ddced158cb31fbb5c1b534c824fc8c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 Feb 2023 11:56:13 +0900 Subject: [PATCH 22/23] Add me to maintainers (#23026) Add me to maintainers. [My PRs list](https://github.com/go-gitea/gitea/pulls?q=is%3Apr+author%3Ayp05327+is%3Amerged+) --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index b1adf9ef0d657..fcd235e52a57d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -48,3 +48,4 @@ Xinyu Zhou (@xin-u) Jason Song (@wolfogre) Yarden Shoham (@yardenshoham) Yu Tian (@Zettat123) +Eddie Yang <576951401@qq.com> (@yp05327) From e3cffa70f9f731436ab005e4bb10f57166ffc6d5 Mon Sep 17 00:00:00 2001 From: HesterG Date: Tue, 21 Feb 2023 13:03:44 +0800 Subject: [PATCH 23/23] add margin top to the top of branches (#23002) add margin top as mentioned in #22973 --------- Co-authored-by: jidi Co-authored-by: Lunny Xiao --- templates/repo/branch/list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index cfa81a0f5bf1b..a093c19deb8cc 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -5,7 +5,7 @@ {{template "base/alert" .}} {{template "repo/sub_menu" .}} {{if .DefaultBranchBranch}} -

+

{{.locale.Tr "repo.default_branch"}}