From c760e3b2b5d05a679913df8cfa4dd96b056a1175 Mon Sep 17 00:00:00 2001 From: Nicolas Auvray Date: Tue, 5 Aug 2025 01:30:12 +0200 Subject: [PATCH] Display pull request in merged commit view (#35202) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #34634 --- I am not a Web dev so I'm open to any change on the design. The important thing for me is to have the feature implemented. Here are screenshots on a test instance: Capture d'écran 2025-08-02 161710 Capture d'écran 2025-08-02 161725 --- options/locale/locale_en-US.ini | 1 + routers/web/repo/commit.go | 6 ++++++ templates/repo/commit_load_branches_and_tags.tmpl | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 53fbf0af76..d7e73a0cfb 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1322,6 +1322,7 @@ commit_graph.color = Color commit.contained_in = This commit is contained in: commit.contained_in_default_branch = This commit is part of the default branch commit.load_referencing_branches_and_tags = Load branches and tags referencing this commit +commit.merged_in_pr = This commit was merged in pull request %s. blame = Blame download_file = Download file normal_view = Normal View diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 9a06c9359b..0c60abcecd 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -15,6 +15,7 @@ import ( asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" + issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/renderhelper" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" @@ -411,6 +412,11 @@ func Diff(ctx *context.Context) { } } + pr, _ := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, commitID) + if pr != nil { + ctx.Data["MergedPRIssueNumber"] = pr.Index + } + ctx.HTML(http.StatusOK, tplCommitPage) } diff --git a/templates/repo/commit_load_branches_and_tags.tmpl b/templates/repo/commit_load_branches_and_tags.tmpl index ffa0e530e8..ecb210c575 100644 --- a/templates/repo/commit_load_branches_and_tags.tmpl +++ b/templates/repo/commit_load_branches_and_tags.tmpl @@ -1,5 +1,12 @@ {{if not .PageIsWiki}}
+ {{if .MergedPRIssueNumber}} + {{$prLink := HTMLFormat `#%d` $.RepoLink $.MergedPRIssueNumber $.MergedPRIssueNumber}} +
+
+
{{ctx.Locale.Tr "repo.commit.merged_in_pr" $prLink}}
+
+ {{end}}