Skip to content

Commit deb88a4

Browse files
committed
add commit status on repo and user pull request lists
1 parent 0236856 commit deb88a4

File tree

4 files changed

+56
-30
lines changed

4 files changed

+56
-30
lines changed

routers/repo/issue.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,29 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB
186186
}
187187
}
188188

189+
var issuesStates = make([]*models.CommitStatus, 0, len(issues))
189190
// Get posters.
190-
for i := range issues {
191+
for i, issue := range issues {
191192
// Check read status
192193
if !ctx.IsSigned {
193194
issues[i].IsRead = true
194195
} else if err = issues[i].GetIsRead(ctx.User.ID); err != nil {
195196
ctx.ServerError("GetIsRead", err)
196197
return
197198
}
199+
200+
if issue.IsPull {
201+
issue.LoadAttributes()
202+
statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, issue.PullRequest.MergeBase, 0)
203+
if err != nil {
204+
log.Error(3, "GetLatestCommitStatus: %v", err)
205+
}
206+
207+
issuesStates = append(issuesStates, models.CalcCommitStatus(statuses))
208+
}
198209
}
199210
ctx.Data["Issues"] = issues
211+
ctx.Data["IssuesStates"] = issuesStates
200212

201213
// Get assignees.
202214
ctx.Data["Assignees"], err = repo.GetAssignees()

routers/user/home.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/base"
1414
"code.gitea.io/gitea/modules/context"
15+
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/setting"
1617
"code.gitea.io/gitea/modules/util"
1718

@@ -305,8 +306,19 @@ func Issues(ctx *context.Context) {
305306
return
306307
}
307308

309+
var issuesStates = make([]*models.CommitStatus, 0, len(issues))
308310
for _, issue := range issues {
309311
issue.Repo = showReposMap[issue.RepoID]
312+
313+
if issue.IsPull {
314+
issue.LoadAttributes()
315+
statuses, err := models.GetLatestCommitStatus(issue.Repo, issue.PullRequest.MergeBase, 0)
316+
if err != nil {
317+
log.Error(3, "GetLatestCommitStatus: %v", err)
318+
}
319+
320+
issuesStates = append(issuesStates, models.CalcCommitStatus(statuses))
321+
}
310322
}
311323

312324
issueStats, err := models.GetUserIssueStats(models.UserIssueStatsOptions{

templates/repo/issue/list.tmpl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,49 +178,51 @@
178178
</div>
179179

180180
<div class="issue list">
181-
{{range .Issues}}
182-
{{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
181+
{{range $index, $issue := .Issues}}
182+
{{ $timeStr:= TimeSinceUnix $issue.CreatedUnix $.Lang }}
183183
<li class="item">
184184
<div class="ui checkbox issue-checkbox">
185-
<input type="checkbox" data-issue-id={{.ID}}></input>
185+
<input type="checkbox" data-issue-id={{$issue.ID}}></input>
186186
</div>
187-
<div class="ui {{if .IsRead}}black{{else}}green{{end}} label">#{{.Index}}</div>
188-
<a class="title has-emoji" href="{{$.Link}}/{{.Index}}">{{.Title}}</a>
189-
190-
{{if .Ref}}
191-
<a class="ui label" href="{{$.RepoLink}}/src/branch/{{.Ref}}">{{.Ref}}</a>
187+
<div class="ui {{if $issue.IsRead}}black{{else}}green{{end}} label">#{{$issue.Index}}</div>
188+
<a class="title has-emoji" href="{{$.Link}}/{{$issue.Index}}">{{$issue.Title}}</a>
189+
{{if $issue.IsPull}}
190+
{{template "repo/commit_status" (index $.IssuesStates $index)}}
191+
{{end}}
192+
{{if $issue.Ref}}
193+
<a class="ui label" href="{{$.RepoLink}}/src/branch/{{$issue.Ref}}">{{$issue.Ref}}</a>
192194
{{end}}
193-
{{range .Labels}}
195+
{{range $issue.Labels}}
194196
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description}}">{{.Name}}</a>
195197
{{end}}
196198

197-
{{if .NumComments}}
198-
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{.NumComments}}</span>
199+
{{if $issue.NumComments}}
200+
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{$issue.NumComments}}</span>
199201
{{end}}
200202

201203
{{if .TotalTrackedTime}}
202204
<span class="comment ui right"><i class="octicon octicon-clock"></i> {{.TotalTrackedTime | Sec2Time}}</span>
203205
{{end}}
204206

205207
<p class="desc">
206-
{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.HomeLink .Poster.Name | Safe}}
208+
{{$.i18n.Tr "repo.issues.opened_by" $timeStr $issue.Poster.HomeLink $issue.Poster.Name | Safe}}
207209
{{$tasks := .GetTasks}}
208210
{{if gt $tasks 0}}
209211
{{$tasksDone := .GetTasksDone}}
210212
<span class="checklist">
211213
<span class="octicon octicon-checklist"></span> {{$tasksDone}} / {{$tasks}} <span class="progress-bar"><span class="progress" style="width:calc(100% * {{$tasksDone}} / {{$tasks}});"></span></span>
212214
</span>
213215
{{end}}
214-
{{if .Milestone}}
215-
<a class="milestone" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{.Milestone.ID}}&assignee={{$.AssigneeID}}">
216-
<span class="octicon octicon-milestone"></span> {{.Milestone.Name}}
216+
{{if $issue.Milestone}}
217+
<a class="milestone" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$issue.Milestone.ID}}&assignee={{$.AssigneeID}}">
218+
<span class="octicon octicon-milestone"></span> {{$issue.Milestone.Name}}
217219
</a>
218220
{{end}}
219-
{{if ne .DeadlineUnix 0}}
221+
{{if ne $issue.DeadlineUnix 0}}
220222
<span class="octicon octicon-calendar"></span>
221-
<span{{if .IsOverdue}} class="overdue"{{end}}>{{.DeadlineUnix.FormatShort}}</span>
223+
<span{{if $issue.IsOverdue}} class="overdue"{{end}}>{{$issue.DeadlineUnix.FormatShort}}</span>
222224
{{end}}
223-
{{range .Assignees}}
225+
{{range $issue.Assignees}}
224226
<a class="ui right assignee poping up" href="{{.HomeLink}}" data-content="{{.Name}}" data-variation="inverted" data-position="left center">
225227
<img class="ui avatar image" src="{{.RelAvatarLink}}">
226228
</a>

templates/user/dashboard/issues.tmpl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
</div>
5959

6060
<div class="issue list">
61-
{{range .Issues}}
62-
{{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
61+
{{range $index, $issue := .Issues}}
62+
{{ $timeStr:= TimeSinceUnix $issue.CreatedUnix $.Lang }}
6363
<li class="item">
64-
<div class="ui label">{{if not $.RepoID}}{{.Repo.FullName}}{{end}}#{{.Index}}</div>
65-
<a class="title has-emoji" href="{{AppSubUrl}}/{{.Repo.Owner.Name}}/{{.Repo.Name}}/issues/{{.Index}}">{{.Title}}</a>
64+
<div class="ui label">{{if not $.RepoID}}{{$issue.Repo.FullName}}{{end}}#{{$issue.Index}}</div>
65+
<a class="title has-emoji" href="{{AppSubUrl}}/{{$issue.Repo.Owner.Name}}/{{$issue.Repo.Name}}/issues/{{$issue.Index}}">{{$issue.Title}}</a>
6666

67-
{{with .Labels}}
67+
{{with $issue.Labels}}
6868
{{/* If we have any labels, we should show them
6969
with a 2.5 line height, this way they don't look
7070
awful and they don't stack on top of each other,
@@ -76,18 +76,18 @@
7676
</span>
7777
{{end}}
7878

79-
{{if .NumComments}}
80-
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{.NumComments}}</span>
79+
{{if $issue.NumComments}}
80+
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{$issue.NumComments}}</span>
8181
{{end}}
8282
{{if .TotalTrackedTime}}
8383
<span class="comment ui right"><i class="octicon octicon-clock"></i> {{.TotalTrackedTime | Sec2Time}}</span>
8484
{{end}}
8585

8686
<p class="desc">
87-
{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.HomeLink .Poster.Name | Safe}}
88-
{{if .Assignee}}
89-
<a class="ui right assignee poping up" href="{{.Assignee.HomeLink}}" data-content="{{.Assignee.Name}}" data-variation="inverted" data-position="left center">
90-
<img class="ui avatar image" src="{{.Assignee.RelAvatarLink}}">
87+
{{$.i18n.Tr "repo.issues.opened_by" $timeStr $issue.Poster.HomeLink $issue.Poster.Name | Safe}}
88+
{{if $issue.Assignee}}
89+
<a class="ui right assignee poping up" href="{{$issue.Assignee.HomeLink}}" data-content="{{$issue.Assignee.Name}}" data-variation="inverted" data-position="left center">
90+
<img class="ui avatar image" src="{{$issue.Assignee.RelAvatarLink}}">
9191
</a>
9292
{{end}}
9393
{{$tasks := .GetTasks}}

0 commit comments

Comments
 (0)