Skip to content

Commit 0692f43

Browse files
IT-AlexKoralex-kor-wrkwxiaoguanglafriks
authored
Show source/target branches on PR's list (#19747)
Add ability to show source/target branches for Pull Request's list. It can be useful to see which branches are used in each PR right in the list. Co-authored-by: Alexey Korobkov <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent 35d0358 commit 0692f43

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

models/issue_list.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ const (
2525
defaultMaxInSize = 50
2626
)
2727

28+
// get the repo IDs to be loaded later, these IDs are for issue.Repo and issue.PullRequest.HeadRepo
2829
func (issues IssueList) getRepoIDs() []int64 {
2930
repoIDs := make(map[int64]struct{}, len(issues))
3031
for _, issue := range issues {
31-
if issue.Repo != nil {
32-
continue
33-
}
34-
if _, ok := repoIDs[issue.RepoID]; !ok {
32+
if issue.Repo == nil {
3533
repoIDs[issue.RepoID] = struct{}{}
3634
}
35+
if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil {
36+
repoIDs[issue.PullRequest.HeadRepoID] = struct{}{}
37+
}
3738
}
3839
return container.KeysInt64(repoIDs)
3940
}
@@ -67,8 +68,11 @@ func (issues IssueList) loadRepositories(ctx context.Context) ([]*repo_model.Rep
6768
} else {
6869
repoMaps[issue.RepoID] = issue.Repo
6970
}
70-
if issue.PullRequest != nil && issue.PullRequest.BaseRepo == nil {
71+
if issue.PullRequest != nil {
7172
issue.PullRequest.BaseRepo = issue.Repo
73+
if issue.PullRequest.HeadRepo == nil {
74+
issue.PullRequest.HeadRepo = repoMaps[issue.PullRequest.HeadRepoID]
75+
}
7276
}
7377
}
7478
return valuesRepository(repoMaps), nil

templates/shared/issuelist.tmpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@
5959
{{else}}
6060
{{$.i18n.Tr .GetLastEventLabelFake $timeStr (.Poster.GetDisplayName | Escape) | Safe}}
6161
{{end}}
62+
{{if .IsPull}}
63+
<div class="branches">
64+
<div class="branch">
65+
<a class="bold" href="{{.PullRequest.BaseRepo.HTMLURL}}/src/branch/{{PathEscapeSegments .PullRequest.BaseBranch}}">
66+
{{/* inline to remove the spaces between spans */}}
67+
{{if ne .RepoID .PullRequest.BaseRepoID}}<span class="truncated-name">{{.PullRequest.BaseRepo.OwnerName}}</span>:{{end}}<span class="truncated-name">{{.PullRequest.BaseBranch}}</span>
68+
</a>
69+
</div>
70+
71+
&laquo;
72+
73+
{{if .PullRequest.HeadRepo}}
74+
<div class="branch">
75+
<a class="bold" href="{{.PullRequest.HeadRepo.HTMLURL}}/src/branch/{{PathEscapeSegments .PullRequest.HeadBranch}}">
76+
{{/* inline to remove the spaces between spans */}}
77+
{{if ne .RepoID .PullRequest.HeadRepoID}}<span class="truncated-name">{{.PullRequest.HeadRepo.OwnerName}}</span>:{{end}}<span class="truncated-name">{{.PullRequest.HeadBranch}}</span>
78+
</a>
79+
</div>
80+
{{end}}
81+
</div>
82+
{{end}}
6283
{{if and .Milestone (ne $.listType "milestone")}}
6384
<a class="milestone" {{if $.RepoLink}}href="{{$.RepoLink}}/milestone/{{.Milestone.ID}}"{{else}}href="{{.Repo.Link}}/milestone/{{.Milestone.ID}}"{{end}}>
6485
{{svg "octicon-milestone" 14 "mr-2"}}{{.Milestone.Name}}

web_src/less/shared/issuelist.less

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@
119119
}
120120
}
121121

122+
.branches {
123+
display: inline-flex;
124+
padding: 0 6px;
125+
126+
.branch {
127+
background-color: var(--color-secondary);
128+
border-radius: 3px;
129+
}
130+
131+
.truncated-name {
132+
white-space: nowrap;
133+
overflow: hidden;
134+
text-overflow: ellipsis;
135+
max-width: 10em;
136+
}
137+
}
138+
122139
> .item + .item {
123140
border-top: 1px solid var(--color-secondary);
124141
}

0 commit comments

Comments
 (0)