Skip to content

Commit c760e3b

Browse files
authored
Display pull request in merged commit view (#35202)
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: <img width="2758" height="420" alt="Capture d'écran 2025-08-02 161710" src="https://github.com/user-attachments/assets/30abbeb5-6139-4a91-9348-36e78f1646e6" /> <img width="2769" height="520" alt="Capture d'écran 2025-08-02 161725" src="https://github.com/user-attachments/assets/29871f05-f0b5-4a31-9ada-812780269c7d" />
1 parent 67d6235 commit c760e3b

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,7 @@ commit_graph.color = Color
13221322
commit.contained_in = This commit is contained in:
13231323
commit.contained_in_default_branch = This commit is part of the default branch
13241324
commit.load_referencing_branches_and_tags = Load branches and tags referencing this commit
1325+
commit.merged_in_pr = This commit was merged in pull request %s.
13251326
blame = Blame
13261327
download_file = Download file
13271328
normal_view = Normal View

routers/web/repo/commit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
asymkey_model "code.gitea.io/gitea/models/asymkey"
1616
"code.gitea.io/gitea/models/db"
1717
git_model "code.gitea.io/gitea/models/git"
18+
issues_model "code.gitea.io/gitea/models/issues"
1819
"code.gitea.io/gitea/models/renderhelper"
1920
repo_model "code.gitea.io/gitea/models/repo"
2021
unit_model "code.gitea.io/gitea/models/unit"
@@ -411,6 +412,11 @@ func Diff(ctx *context.Context) {
411412
}
412413
}
413414

415+
pr, _ := issues_model.GetPullRequestByMergedCommit(ctx, ctx.Repo.Repository.ID, commitID)
416+
if pr != nil {
417+
ctx.Data["MergedPRIssueNumber"] = pr.Index
418+
}
419+
414420
ctx.HTML(http.StatusOK, tplCommitPage)
415421
}
416422

templates/repo/commit_load_branches_and_tags.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{{if not .PageIsWiki}}
22
<div class="branch-and-tag-area" data-text-default-branch-tooltip="{{ctx.Locale.Tr "repo.commit.contained_in_default_branch"}}">
3+
{{if .MergedPRIssueNumber}}
4+
{{$prLink := HTMLFormat `<a href="%s/pulls/%d">#%d</a>` $.RepoLink $.MergedPRIssueNumber $.MergedPRIssueNumber}}
5+
<div>
6+
<div class="divider"></div>
7+
<div>{{ctx.Locale.Tr "repo.commit.merged_in_pr" $prLink}}</div>
8+
</div>
9+
{{end}}
310
<button class="ui button ellipsis-button load-branches-and-tags tw-mt-2" aria-expanded="false"
411
data-fetch-url="{{.RepoLink}}/commit/{{.CommitID}}/load-branches-and-tags"
512
data-tooltip-content="{{ctx.Locale.Tr "repo.commit.load_referencing_branches_and_tags"}}"

0 commit comments

Comments
 (0)