From 3b10fd9b3452d548ef116b27161b17f57a8e180c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 20 Sep 2024 22:57:55 +0800 Subject: [PATCH 01/23] Only use Host header from reverse proxy (#32060) X-Forwarded-Host has many problems: non-standard, not well-defined (X-Forwarded-Port or not), conflicts with Host header, it already caused problems like #31907. So do not use X-Forwarded-Host, just use Host header directly. Official document also only uses `Host` header and never mentioned others. --- .github/workflows/pull-db-tests.yml | 3 ++- modules/httplib/url.go | 13 +++---------- modules/httplib/url_test.go | 5 +++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index 246884f24b..90804c0f0a 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -201,7 +201,8 @@ jobs: runs-on: ubuntu-latest services: mssql: - image: mcr.microsoft.com/mssql/server:2017-latest + # some images before 2024-04 can't run on new kernels + image: mcr.microsoft.com/mssql/server:2019-latest env: ACCEPT_EULA: Y MSSQL_PID: Standard diff --git a/modules/httplib/url.go b/modules/httplib/url.go index 219dfe695c..e3bad1e5fb 100644 --- a/modules/httplib/url.go +++ b/modules/httplib/url.go @@ -52,11 +52,6 @@ func getRequestScheme(req *http.Request) string { return "" } -func getForwardedHost(req *http.Request) string { - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host - return req.Header.Get("X-Forwarded-Host") -} - // GuessCurrentAppURL tries to guess the current full app URL (with sub-path) by http headers. It always has a '/' suffix, exactly the same as setting.AppURL func GuessCurrentAppURL(ctx context.Context) string { return GuessCurrentHostURL(ctx) + setting.AppSubURL + "/" @@ -81,11 +76,9 @@ func GuessCurrentHostURL(ctx context.Context) string { if reqScheme == "" { return strings.TrimSuffix(setting.AppURL, setting.AppSubURL+"/") } - reqHost := getForwardedHost(req) - if reqHost == "" { - reqHost = req.Host - } - return reqScheme + "://" + reqHost + // X-Forwarded-Host has many problems: non-standard, not well-defined (X-Forwarded-Port or not), conflicts with Host header. + // So do not use X-Forwarded-Host, just use Host header directly. + return reqScheme + "://" + req.Host } // MakeAbsoluteURL tries to make a link to an absolute URL: diff --git a/modules/httplib/url_test.go b/modules/httplib/url_test.go index 28aaee6e12..fc6c91cd3a 100644 --- a/modules/httplib/url_test.go +++ b/modules/httplib/url_test.go @@ -70,7 +70,7 @@ func TestMakeAbsoluteURL(t *testing.T) { "X-Forwarded-Proto": {"https"}, }, }) - assert.Equal(t, "https://forwarded-host/foo", MakeAbsoluteURL(ctx, "/foo")) + assert.Equal(t, "https://user-host/foo", MakeAbsoluteURL(ctx, "/foo")) } func TestIsCurrentGiteaSiteURL(t *testing.T) { @@ -119,5 +119,6 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) { }, }) assert.True(t, IsCurrentGiteaSiteURL(ctx, "http://localhost:3000")) - assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host")) + assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://user-host")) + assert.False(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host")) } From aa9faf825074110d31fc2c75a31880c98a48feb2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 20 Sep 2024 17:27:19 +0200 Subject: [PATCH 02/23] Set manual `tabindex`es on login page (#31689) Fixes https://github.com/go-gitea/gitea/issues/31686. A more elborate manual tabindex numbering could be done, but I think it's not really worth the extra effort and such stuff could easily break during refactors. Includes another small tweak to un-stretch the`` element so it's only as large as it needs to be and this change also made the margin unneeded. --- templates/user/auth/signin_inner.tmpl | 12 +++++++----- web_src/css/form.css | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/templates/user/auth/signin_inner.tmpl b/templates/user/auth/signin_inner.tmpl index b0a52d2c64..ec61e56f4d 100644 --- a/templates/user/auth/signin_inner.tmpl +++ b/templates/user/auth/signin_inner.tmpl @@ -14,20 +14,22 @@ {{.CsrfTokenHtml}}
- +
{{if or (not .DisablePassword) .LinkAccountMode}}
{{end}} {{if not .LinkAccountMode}}
- +
{{end}} @@ -35,7 +37,7 @@ {{template "user/auth/captcha" .}}
- - {{else}} + {{else if and .IsShowClosed.Has (not .IsShowClosed.Value)}} {{end}} {{if $.IsRepoAdmin}} From 38e3d8b4e65d49c2efc6ab1d3c012e5a75cab07b Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 23 Sep 2024 16:54:20 -0400 Subject: [PATCH 15/23] use rebuilt mssql-2017 image (#32109) --- .github/workflows/pull-db-tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-db-tests.yml b/.github/workflows/pull-db-tests.yml index 90804c0f0a..22cb784245 100644 --- a/.github/workflows/pull-db-tests.yml +++ b/.github/workflows/pull-db-tests.yml @@ -198,11 +198,12 @@ jobs: test-mssql: if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true' needs: files-changed - runs-on: ubuntu-latest + # specifying the version of ubuntu in use as mssql fails on newer kernels + # pending resolution from vendor + runs-on: ubuntu-20.04 services: mssql: - # some images before 2024-04 can't run on new kernels - image: mcr.microsoft.com/mssql/server:2019-latest + image: mcr.microsoft.com/mssql/server:2017-latest env: ACCEPT_EULA: Y MSSQL_PID: Standard From 6afb22448b7845fb8f570d64ce2ad6c4c81b9d2f Mon Sep 17 00:00:00 2001 From: GiteaBot Date: Tue, 24 Sep 2024 00:30:57 +0000 Subject: [PATCH 16/23] [skip ci] Updated translations via Crowdin --- options/locale/locale_ja-JP.ini | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/options/locale/locale_ja-JP.ini b/options/locale/locale_ja-JP.ini index 48f241f7b8..3a80c741db 100644 --- a/options/locale/locale_ja-JP.ini +++ b/options/locale/locale_ja-JP.ini @@ -159,6 +159,7 @@ filter.public=公開 filter.private=プライベート no_results_found=見つかりません。 +internal_error_skipped=内部エラーが発生しましたがスキップされました: %s [search] search=検索… @@ -177,6 +178,8 @@ code_search_by_git_grep=現在のコード検索は "git grep" によって行 package_kind=パッケージを検索... project_kind=プロジェクトを検索... branch_kind=ブランチを検索... +tag_kind=タグを検索... +tag_tooltip=一致するタグを検索します。任意のシーケンスに一致させるには '%' を使用してください。 commit_kind=コミットを検索... runner_kind=ランナーを検索... no_results=一致する結果が見つかりませんでした @@ -1174,6 +1177,11 @@ migrate.gogs.description=notabug.org やその他の Gogs インスタンスか migrate.onedev.description=code.onedev.io やその他の OneDev インスタンスからデータを移行します。 migrate.codebase.description=codebasehq.com からデータを移行します。 migrate.gitbucket.description=GitBucket インスタンスからデータを移行します。 +migrate.codecommit.description=AWS CodeCommitからデータを移行します。 +migrate.codecommit.aws_access_key_id=AWS アクセスキー ID +migrate.codecommit.aws_secret_access_key=AWSシークレットアクセスキー +migrate.codecommit.https_git_credentials_username=HTTPS Git 認証情報 ユーザー名 +migrate.codecommit.https_git_credentials_password=HTTPS Git 認証情報 パスワード migrate.migrating_git=Gitデータ移行中 migrate.migrating_topics=トピック移行中 migrate.migrating_milestones=マイルストーン移行中 @@ -1251,6 +1259,7 @@ ambiguous_runes_header=このファイルには曖昧(ambiguous)なUnicode文字 ambiguous_runes_description=このファイルには、他の文字と見間違える可能性があるUnicode文字が含まれています。 それが意図的なものと考えられる場合は、この警告を無視して構いません。 それらの文字を表示するにはエスケープボタンを使用します。 invisible_runes_line=`この行には不可視のUnicode文字があります` ambiguous_runes_line=`この行には曖昧(ambiguous)なUnicode文字があります` +ambiguous_character=`%[1]c [U+%04[1]X] は %[2]c [U+%04[2]X] と混同するおそれがあります` escape_control_characters=エスケープ unescape_control_characters=エスケープ解除 @@ -1748,6 +1757,11 @@ issues.review.resolve_conversation=解決済みにする issues.review.un_resolve_conversation=未解決にする issues.review.resolved_by=がこの会話を解決済みにしました issues.review.commented=コメント +issues.review.official=承認済み +issues.review.requested=レビュー待ち +issues.review.rejected=変更要請済み +issues.review.stale=承認後に更新されました +issues.review.unofficial=カウントされない承認 issues.assignee.error=予期しないエラーにより、一部の担当者を追加できませんでした。 issues.reference_issue.body=内容 issues.content_history.deleted=削除しました @@ -1821,6 +1835,8 @@ pulls.is_empty=このブランチの変更は既にターゲットブランチ pulls.required_status_check_failed=いくつかの必要なステータスチェックが成功していません。 pulls.required_status_check_missing=必要なチェックがいくつか抜けています。 pulls.required_status_check_administrator=管理者であるため、このプルリクエストをマージすることは可能です。 +pulls.blocked_by_approvals=このプルリクエストはまだ必要な承認数を満たしていません。 公式の承認を %[1]d / %[2]d 得ています。 +pulls.blocked_by_approvals_whitelisted=このプルリクエストはまだ必要な承認数を満たしていません。 許可リストのユーザーまたはチームからの承認を %[1]d / %[2]d 得ています。 pulls.blocked_by_rejection=このプルリクエストは公式レビューアにより変更要請されています。 pulls.blocked_by_official_review_requests=このプルリクエストには公式レビュー依頼があります。 pulls.blocked_by_outdated_branch=このプルリクエストは遅れのためブロックされています。 From fcedf634d5864a9e4ec3f866b99076872aafd07d Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 24 Sep 2024 09:00:09 +0800 Subject: [PATCH 17/23] Fix bug in getting merged pull request by commit (#32079) --- routers/api/v1/api.go | 2 ++ routers/api/v1/repo/commits.go | 6 +++--- templates/swagger/v1_json.tmpl | 2 +- tests/integration/api_pull_test.go | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index be67ec1695..1244676508 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1286,6 +1286,8 @@ func Routes() *web.Router { m.Group("/{ref}", func() { m.Get("/status", repo.GetCombinedCommitStatusByRef) m.Get("/statuses", repo.GetCommitStatusesByRef) + }, context.ReferencesGitRepo()) + m.Group("/{sha}", func() { m.Get("/pull", repo.GetCommitPullRequest) }, context.ReferencesGitRepo()) }, reqRepoReader(unit.TypeCode)) diff --git a/routers/api/v1/repo/commits.go b/routers/api/v1/repo/commits.go index cec7c3d534..788c75fab2 100644 --- a/routers/api/v1/repo/commits.go +++ b/routers/api/v1/repo/commits.go @@ -325,11 +325,11 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) { } } -// GetCommitPullRequest returns the pull request of the commit +// GetCommitPullRequest returns the merged pull request of the commit func GetCommitPullRequest(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/commits/{sha}/pull repository repoGetCommitPullRequest // --- - // summary: Get the pull request of the commit + // summary: Get the merged pull request of the commit // produces: // - application/json // parameters: @@ -354,7 +354,7 @@ func GetCommitPullRequest(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - pr, err := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, ctx.PathParam(":sha")) + pr, err := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, ctx.PathParam("sha")) if err != nil { if issues_model.IsErrPullRequestNotExist(err) { ctx.Error(http.StatusNotFound, "GetPullRequestByMergedCommit", err) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index d9f1a8f5e9..5983505502 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5446,7 +5446,7 @@ "tags": [ "repository" ], - "summary": "Get the pull request of the commit", + "summary": "Get the merged pull request of the commit", "operationId": "repoGetCommitPullRequest", "parameters": [ { diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go index 8239878d2b..b7e01d4a20 100644 --- a/tests/integration/api_pull_test.go +++ b/tests/integration/api_pull_test.go @@ -334,3 +334,19 @@ func doAPIGetPullFiles(ctx APITestContext, pr *api.PullRequest, callback func(*t } } } + +func TestAPICommitPullRequest(t *testing.T) { + defer tests.PrepareTestEnv(t)() + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + + ctx := NewAPITestContext(t, "user2", repo.Name, auth_model.AccessTokenScopeReadRepository) + + mergedCommitSHA := "1a8823cd1a9549fde083f992f6b9b87a7ab74fb3" + req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/commits/%s/pull", owner.Name, repo.Name, mergedCommitSHA).AddTokenAuth(ctx.Token) + ctx.Session.MakeRequest(t, req, http.StatusOK) + + invalidCommitSHA := "abcd1234abcd1234abcd1234abcd1234abcd1234" + req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/commits/%s/pull", owner.Name, repo.Name, invalidCommitSHA).AddTokenAuth(ctx.Token) + ctx.Session.MakeRequest(t, req, http.StatusNotFound) +} From 3f2d8f873035b614b4cdb447d8e16f5af82cefe8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2024 09:30:05 +0800 Subject: [PATCH 18/23] Fix panic when cloning with wrong ssh format. (#32076) --- cmd/serv.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index 2bfd111061..f74a8fd3d0 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -143,6 +143,12 @@ func runServ(c *cli.Context) error { return nil } + defer func() { + if err := recover(); err != nil { + _ = fail(ctx, "Internal Server Error", "Panic: %v\n%s", err, log.Stack(2)) + } + }() + keys := strings.Split(c.Args().First(), "-") if len(keys) != 2 || keys[0] != "key" { return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args().First()) @@ -189,10 +195,7 @@ func runServ(c *cli.Context) error { } verb := words[0] - repoPath := words[1] - if repoPath[0] == '/' { - repoPath = repoPath[1:] - } + repoPath := strings.TrimPrefix(words[1], "/") var lfsVerb string if verb == lfsAuthenticateVerb { From 6eb5950835dd8e0eef2ef6d343af4acfce40a2fc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2024 10:06:28 +0800 Subject: [PATCH 19/23] Allow set branch protection in an empty repository (#32095) --- routers/web/web.go | 2 +- templates/repo/settings/branches.tmpl | 22 ++++++++++------------ templates/repo/settings/navbar.tmpl | 8 +++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/routers/web/web.go b/routers/web/web.go index 5129bd4bda..af46c36fe7 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1069,7 +1069,7 @@ func registerRoutes(m *web.Router) { m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch). Post(web.Bind(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost) m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost) - }, repo.MustBeNotEmpty) + }) m.Group("/tags", func() { m.Get("", repo_setting.ProtectedTags) diff --git a/templates/repo/settings/branches.tmpl b/templates/repo/settings/branches.tmpl index 52c0c2c800..6f070ba61c 100644 --- a/templates/repo/settings/branches.tmpl +++ b/templates/repo/settings/branches.tmpl @@ -15,19 +15,17 @@ {{.CsrfTokenHtml}} - {{if not .Repository.IsEmpty}} - diff --git a/templates/repo/settings/navbar.tmpl b/templates/repo/settings/navbar.tmpl index b9105bb8ed..e46273aff0 100644 --- a/templates/repo/settings/navbar.tmpl +++ b/templates/repo/settings/navbar.tmpl @@ -13,11 +13,9 @@ {{end}} {{if .Repository.UnitEnabled $.Context ctx.Consts.RepoUnitTypeCode}} - {{if not .Repository.IsEmpty}} - - {{ctx.Locale.Tr "repo.settings.branches"}} - - {{end}} + + {{ctx.Locale.Tr "repo.settings.branches"}} + {{ctx.Locale.Tr "repo.settings.tags"}} From 2c6fa6c1e05437b5515c7be4f516ac4e4a59bf3c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2024 11:02:42 +0800 Subject: [PATCH 20/23] Fix template bug of pull request view (#32072) Caused by #31924 --- templates/repo/issue/view_content/sidebar.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 49c40be5a9..e49e90df56 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -109,7 +109,7 @@
- + {{svg (printf "octicon-%s" .Type.Icon) 16 (printf "text %s" (.HTMLTypeColorName))}}
From aadbe0488f454b9f7f5a56765f4530f9d1e2c6ec Mon Sep 17 00:00:00 2001 From: Kemal Zebari <60799661+kemzeb@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:38:08 -0700 Subject: [PATCH 21/23] Truncate commit message during Discord webhook push events (#31970) Resolves #31668. --- services/webhook/discord.go | 11 +++++++++-- services/webhook/discord_test.go | 14 ++++++++++++++ services/webhook/general_test.go | 10 +++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/services/webhook/discord.go b/services/webhook/discord.go index f27b39dac3..59e87a7e1f 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -11,6 +11,7 @@ import ( "net/url" "strconv" "strings" + "unicode/utf8" webhook_model "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/git" @@ -154,8 +155,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) { var text string // for each commit, generate attachment text for i, commit := range p.Commits { - text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, - strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name) + // limit the commit message display to just the summary, otherwise it would be hard to read + message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 1)[0], "\r") + + // a limit of 50 is set because GitHub does the same + if utf8.RuneCountInString(message) > 50 { + message = fmt.Sprintf("%.47s...", message) + } + text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name) // add linebreak to each commit but the last if i < len(p.Commits)-1 { text += "\n" diff --git a/services/webhook/discord_test.go b/services/webhook/discord_test.go index c04b95383b..fbb4b24ef1 100644 --- a/services/webhook/discord_test.go +++ b/services/webhook/discord_test.go @@ -80,6 +80,20 @@ func TestDiscordPayload(t *testing.T) { assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL) }) + t.Run("PushWithLongCommitMessage", func(t *testing.T) { + p := pushTestMultilineCommitMessagePayload() + + pl, err := dc.Push(p) + require.NoError(t, err) + + assert.Len(t, pl.Embeds, 1) + assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title) + assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1", pl.Embeds[0].Description) + assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name) + assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL) + assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL) + }) + t.Run("Issue", func(t *testing.T) { p := issueTestPayload() diff --git a/services/webhook/general_test.go b/services/webhook/general_test.go index fc6e7140e7..d6a77c9442 100644 --- a/services/webhook/general_test.go +++ b/services/webhook/general_test.go @@ -64,9 +64,17 @@ func forkTestPayload() *api.ForkPayload { } func pushTestPayload() *api.PushPayload { + return pushTestPayloadWithCommitMessage("commit message") +} + +func pushTestMultilineCommitMessagePayload() *api.PushPayload { + return pushTestPayloadWithCommitMessage("This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好 ⚠️⚠️️\n\nThis is the message body.") +} + +func pushTestPayloadWithCommitMessage(message string) *api.PushPayload { commit := &api.PayloadCommit{ ID: "2020558fe2e34debb818a514715839cabd25e778", - Message: "commit message", + Message: message, URL: "http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778", Author: &api.PayloadUser{ Name: "user1", From e2f365b55cca7cf986a1f04e4d9e43d7e7aef7ad Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2024 12:14:57 +0800 Subject: [PATCH 22/23] Display head branch more comfortable on pull request view (#32000) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR do some minor improvements for head branch display on pull request view UI. - [x] Remove the link if the head branch has been deleted with a tooltip, so that users will not result in a 404 page - [x] Display a label if this pull request is an agit based one. ![图片](https://github.com/user-attachments/assets/872f26b6-f1cf-4427-9e41-e3a5b176dfa4) --- models/issues/pull.go | 4 ++++ options/locale/locale_en-US.ini | 1 + routers/web/repo/pull.go | 14 +++++++++++++- templates/repo/issue/view_title.tmpl | 9 +++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/models/issues/pull.go b/models/issues/pull.go index 5fe95d56cc..4a5782f836 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -268,6 +268,10 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) { return nil } +func (pr *PullRequest) IsAgitFlow() bool { + return pr.Flow == PullRequestFlowAGit +} + // LoadHeadRepo loads the head repository, pr.HeadRepo will remain nil if it does not exist // and thus ErrRepoNotExist will never be returned func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 957e73b171..f77fd203a2 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1927,6 +1927,7 @@ pulls.delete.text = Do you really want to delete this pull request? (This will p pulls.recently_pushed_new_branches = You pushed on branch %[1]s %[2]s pull.deleted_branch = (deleted):%s +pull.agit_documentation = Review documentation about AGit comments.edit.already_changed = Unable to save changes to the comment. It appears the content has already been changed by another user. Please refresh the page and try editing again to avoid overwriting their changes diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 95299b44d5..ced0bbc15a 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -164,7 +164,19 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) { ctx.Data["HeadTarget"] = pull.MustHeadUserName(ctx) + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch } ctx.Data["BaseTarget"] = pull.BaseBranch - ctx.Data["HeadBranchLink"] = pull.GetHeadBranchLink(ctx) + headBranchLink := "" + if pull.Flow == issues_model.PullRequestFlowGithub { + b, err := git_model.GetBranch(ctx, ctx.Repo.Repository.ID, pull.HeadBranch) + switch { + case err == nil: + if !b.IsDeleted { + headBranchLink = pull.GetHeadBranchLink(ctx) + } + case !git_model.IsErrBranchNotExist(err): + log.Error("GetBranch: %v", err) + } + } + ctx.Data["HeadBranchLink"] = headBranchLink ctx.Data["BaseBranchLink"] = pull.GetBaseBranchLink(ctx) } diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 1243681f3a..7fa77b3f1c 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -50,9 +50,14 @@ {{if .Issue.IsPull}} {{$headHref := .HeadTarget}} {{if .HeadBranchLink}} - {{$headHref = HTMLFormat `%s` .HeadBranchLink $headHref}} + {{$headHref = HTMLFormat `%s ` .HeadBranchLink $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} + {{else}} + {{if .Issue.PullRequest.IsAgitFlow}} + {{$headHref = HTMLFormat `%s AGit` $headHref "https://docs.gitea.com/usage/agit" (ctx.Locale.Tr "repo.pull.agit_documentation")}} + {{else}} + {{$headHref = HTMLFormat `%s` (ctx.Locale.Tr "form.target_branch_not_exist") $headHref}} + {{end}} {{end}} - {{$headHref = HTMLFormat `%s ` $headHref (ctx.Locale.Tr "copy_branch") .HeadTarget (svg "octicon-copy" 14)}} {{$baseHref := .BaseTarget}} {{if .BaseBranchLink}} {{$baseHref = HTMLFormat `%s` .BaseBranchLink $baseHref}} From 4947bec8360c152daca23e120eae1732d3848492 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2024 15:12:06 +0800 Subject: [PATCH 23/23] Include collaboration repositories on dashboard source/forks/mirrors list (#31946) Fix #13489 In the original implementation, only `All` will display your owned and collaborated repositories. For other filters like `Source`, `Mirrors` and etc. will only display your owned repositories. This PR removed the limitations. Now except `collbrations`, other filters will always display your owned and collaborated repositories. --- web_src/js/components/DashboardRepoList.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue index afc58d3689..ce165b1b3d 100644 --- a/web_src/js/components/DashboardRepoList.vue +++ b/web_src/js/components/DashboardRepoList.vue @@ -78,7 +78,6 @@ const sfc = { searchURL() { return `${this.subUrl}/repo/search?sort=updated&order=desc&uid=${this.uid}&team_id=${this.teamId}&q=${this.searchQuery }&page=${this.page}&limit=${this.searchLimit}&mode=${this.repoTypes[this.reposFilter].searchMode - }${this.reposFilter !== 'all' ? '&exclusive=1' : '' }${this.archivedFilter === 'archived' ? '&archived=true' : ''}${this.archivedFilter === 'unarchived' ? '&archived=false' : '' }${this.privateFilter === 'private' ? '&is_private=true' : ''}${this.privateFilter === 'public' ? '&is_private=false' : '' }`;