add commit status on repo and user pull request lists

This commit is contained in:
Lunny Xiao 2017-09-15 16:48:59 +08:00
parent 139ebf806e
commit 7f886eccd0
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
4 changed files with 58 additions and 32 deletions

View File

@ -209,8 +209,9 @@ func Issues(ctx *context.Context) {
}
}
var issuesStates = make([]*models.CommitStatus, 0, len(issues))
// Get posters.
for i := range issues {
for i, issue := range issues {
// Check read status
if !ctx.IsSigned {
issues[i].IsRead = true
@ -218,8 +219,19 @@ func Issues(ctx *context.Context) {
ctx.ServerError("GetIsRead", err)
return
}
if issue.IsPull {
issue.LoadAttributes()
statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, issue.PullRequest.MergeBase, 0)
if err != nil {
log.Error(3, "GetLatestCommitStatus: %v", err)
}
issuesStates = append(issuesStates, models.CalcCommitStatus(statuses))
}
}
ctx.Data["Issues"] = issues
ctx.Data["IssuesStates"] = issuesStates
// Get milestones.
ctx.Data["Milestones"], err = models.GetMilestonesByRepoID(repo.ID)

View File

@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@ -291,8 +292,19 @@ func Issues(ctx *context.Context) {
return
}
var issuesStates = make([]*models.CommitStatus, 0, len(issues))
for _, issue := range issues {
issue.Repo = showReposMap[issue.RepoID]
if issue.IsPull {
issue.LoadAttributes()
statuses, err := models.GetLatestCommitStatus(issue.Repo, issue.PullRequest.MergeBase, 0)
if err != nil {
log.Error(3, "GetLatestCommitStatus: %v", err)
}
issuesStates = append(issuesStates, models.CalcCommitStatus(statuses))
}
}
issueStats, err := models.GetUserIssueStats(models.UserIssueStatsOptions{

View File

@ -178,24 +178,26 @@
</div>
<div class="issue list">
{{range .Issues}}
{{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
{{range $index, $issue := .Issues}}
{{ $timeStr:= TimeSinceUnix $issue.CreatedUnix $.Lang }}
<li class="item">
<div class="ui checkbox issue-checkbox">
<input type="checkbox" data-issue-id={{.ID}}></input>
<input type="checkbox" data-issue-id={{$issue.ID}}></input>
</div>
<div class="ui {{if .IsRead}}black{{else}}green{{end}} label">#{{.Index}}</div>
<a class="title has-emoji" href="{{$.Link}}/{{.Index}}">{{.Title}}</a>
{{if .Ref}}
<a class="ui label" href="{{$.RepoLink}}/src/branch/{{.Ref}}">{{.Ref}}</a>
<div class="ui {{if $issue.IsRead}}black{{else}}green{{end}} label">#{{$issue.Index}}</div>
<a class="title has-emoji" href="{{$.Link}}/{{$issue.Index}}">{{$issue.Title}}</a>
{{if $issue.IsPull}}
{{template "repo/commit_status" (index $.IssuesStates $index)}}
{{end}}
{{range .Labels}}
{{if $issue.Ref}}
<a class="ui label" href="{{$.RepoLink}}/src/branch/{{$issue.Ref}}">{{$issue.Ref}}</a>
{{end}}
{{range $issue.Labels}}
<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>
{{end}}
{{if .NumComments}}
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{.NumComments}}</span>
{{if $issue.NumComments}}
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{$issue.NumComments}}</span>
{{end}}
{{if .TotalTrackedTime}}
@ -203,7 +205,7 @@
{{end}}
<p class="desc">
{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.HomeLink .Poster.Name | Safe}}
{{$.i18n.Tr "repo.issues.opened_by" $timeStr $issue.Poster.HomeLink $issue.Poster.Name | Safe}}
{{$tasks := .GetTasks}}
{{if gt $tasks 0}}
{{$tasksDone := .GetTasksDone}}
@ -211,18 +213,18 @@
<span class="octicon octicon-checklist"></span> {{$tasksDone}} / {{$tasks}} <span class="progress-bar"><span class="progress" style="width:calc(100% * {{$tasksDone}} / {{$tasks}});"></span></span>
</span>
{{end}}
{{if .Milestone}}
<a class="milestone" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{.Milestone.ID}}&assignee={{$.AssigneeID}}">
<span class="octicon octicon-milestone"></span> {{.Milestone.Name}}
{{if $issue.Milestone}}
<a class="milestone" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{$.SelectLabels}}&milestone={{$issue.Milestone.ID}}&assignee={{$.AssigneeID}}">
<span class="octicon octicon-milestone"></span> {{$issue.Milestone.Name}}
</a>
{{end}}
{{if ne .DeadlineUnix 0}}
{{if ne $issue.DeadlineUnix 0}}
<span class="octicon octicon-calendar"></span>
<span{{if .IsOverdue}} class="overdue"{{end}}>{{.DeadlineUnix.FormatShort}}</span>
<span{{if $issue.IsOverdue}} class="overdue"{{end}}>{{$issue.DeadlineUnix.FormatShort}}</span>
{{end}}
{{if .Assignee}}
<a class="ui right assignee poping up" href="{{.Assignee.HomeLink}}" data-content="{{.Assignee.Name}}" data-variation="inverted" data-position="left center">
<img class="ui avatar image" src="{{.Assignee.RelAvatarLink}}">
{{if $issue.Assignee}}
<a class="ui right assignee poping up" href="{{$issue.Assignee.HomeLink}}" data-content="{{$issue.Assignee.Name}}" data-variation="inverted" data-position="left center">
<img class="ui avatar image" src="{{$issue.Assignee.RelAvatarLink}}">
</a>
{{end}}
</p>

View File

@ -58,13 +58,13 @@
</div>
<div class="issue list">
{{range .Issues}}
{{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
{{range $index, $issue := .Issues}}
{{ $timeStr:= TimeSinceUnix $issue.CreatedUnix $.Lang }}
<li class="item">
<div class="ui label">{{if not $.RepoID}}{{.Repo.FullName}}{{end}}#{{.Index}}</div>
<a class="title has-emoji" href="{{AppSubUrl}}/{{.Repo.Owner.Name}}/{{.Repo.Name}}/issues/{{.Index}}">{{.Title}}</a>
<div class="ui label">{{if not $.RepoID}}{{$issue.Repo.FullName}}{{end}}#{{$issue.Index}}</div>
<a class="title has-emoji" href="{{AppSubUrl}}/{{$issue.Repo.Owner.Name}}/{{$issue.Repo.Name}}/issues/{{$issue.Index}}">{{$issue.Title}}</a>
{{with .Labels}}
{{with $issue.Labels}}
{{/* If we have any labels, we should show them
with a 2.5 line height, this way they don't look
awful and they don't stack on top of each other,
@ -76,18 +76,18 @@
</span>
{{end}}
{{if .NumComments}}
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{.NumComments}}</span>
{{if $issue.NumComments}}
<span class="comment ui right"><i class="octicon octicon-comment"></i> {{$issue.NumComments}}</span>
{{end}}
{{if .TotalTrackedTime}}
<span class="comment ui right"><i class="octicon octicon-clock"></i> {{.TotalTrackedTime | Sec2Time}}</span>
{{end}}
<p class="desc">
{{$.i18n.Tr "repo.issues.opened_by" $timeStr .Poster.HomeLink .Poster.Name | Safe}}
{{if .Assignee}}
<a class="ui right assignee poping up" href="{{.Assignee.HomeLink}}" data-content="{{.Assignee.Name}}" data-variation="inverted" data-position="left center">
<img class="ui avatar image" src="{{.Assignee.RelAvatarLink}}">
{{$.i18n.Tr "repo.issues.opened_by" $timeStr $issue.Poster.HomeLink $issue.Poster.Name | Safe}}
{{if $issue.Assignee}}
<a class="ui right assignee poping up" href="{{$issue.Assignee.HomeLink}}" data-content="{{$issue.Assignee.Name}}" data-variation="inverted" data-position="left center">
<img class="ui avatar image" src="{{$issue.Assignee.RelAvatarLink}}">
</a>
{{end}}
{{$tasks := .GetTasks}}