Skip to content

Commit ef85bf8

Browse files
Roberto Santallalafriks
Roberto Santalla
andauthored
Project: show referenced PRs in issue cards (#14183)
Co-authored-by: Lauris BH <lauris@nix.lv>
1 parent 1722299 commit ef85bf8

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

models/project_board.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ func (b *ProjectBoard) LoadIssues() (IssueList, error) {
256256
issueList = append(issueList, issues...)
257257
}
258258

259+
if err := IssueList(issueList).LoadComments(); err != nil {
260+
return nil, err
261+
}
262+
259263
b.Issues = issueList
260264
return issueList, nil
261265
}

routers/repo/projects.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,32 @@ func ViewProject(ctx *context.Context) {
280280
boards[0].Title = ctx.Tr("repo.projects.type.uncategorized")
281281
}
282282

283-
if ctx.Data["Issues"], err = boards.LoadIssues(); err != nil {
283+
issueList, err := boards.LoadIssues()
284+
if err != nil {
284285
ctx.ServerError("LoadIssuesOfBoards", err)
285286
return
286287
}
288+
ctx.Data["Issues"] = issueList
289+
290+
linkedPrsMap := make(map[int64][]*models.Issue)
291+
for _, issue := range issueList {
292+
var referencedIds []int64
293+
for _, comment := range issue.Comments {
294+
if comment.RefIssueID != 0 && comment.RefIsPull {
295+
referencedIds = append(referencedIds, comment.RefIssueID)
296+
}
297+
}
298+
299+
if len(referencedIds) > 0 {
300+
if linkedPrs, err := models.Issues(&models.IssuesOptions{
301+
IssueIDs: referencedIds,
302+
IsPull: util.OptionalBoolTrue,
303+
}); err == nil {
304+
linkedPrsMap[issue.ID] = linkedPrs
305+
}
306+
}
307+
}
308+
ctx.Data["LinkedPRs"] = linkedPrsMap
287309

288310
project.RenderedContent = string(markdown.Render([]byte(project.Description), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
289311

templates/repo/projects/view.tmpl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,21 @@
166166
</span>
167167
<a class="project-board-title" href="{{$.RepoLink}}/issues/{{.Index}}">#{{.Index}} {{.Title}}</a>
168168
</div>
169+
{{- if .MilestoneID }}
169170
<div class="meta">
170-
{{ if .MilestoneID }}
171171
<a class="milestone" href="{{$.RepoLink}}/milestone/{{ .MilestoneID}}">
172172
{{svg "octicon-milestone"}} {{ .Milestone.Name }}
173173
</a>
174-
{{ end }}
175174
</div>
175+
{{- end }}
176+
{{- range index $.LinkedPRs .ID }}
177+
<div class="meta">
178+
<a href="{{$.RepoLink}}/pulls/{{ .ID }}">
179+
<span class="{{if .PullRequest.HasMerged}}purple{{else if .IsClosed}}red{{else}}green{{end}}">{{svg "octicon-git-merge"}}</span>
180+
{{ .Title}} (#{{ .ID }})
181+
</a>
182+
</div>
183+
{{- end }}
176184
</div>
177185
<div class="extra content">
178186
{{ range .Labels }}

web_src/less/_repository.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,7 @@ tbody.commit-list {
29212921
}
29222922

29232923
.board-card .content {
2924-
padding: 5px 8px !important;
2924+
padding: 8px 8px 5px !important;
29252925
}
29262926

29272927
.board-card .extra.content {

0 commit comments

Comments
 (0)