Skip to content

Commit 3ff1f20

Browse files
committed
Show commit status icon in commits table
1 parent 9a0b0da commit 3ff1f20

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

models/status.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package models
66

77
import (
8+
"container/list"
89
"fmt"
910
"strings"
1011
"time"
@@ -252,3 +253,40 @@ func NewCommitStatus(repo *Repository, creator *User, sha string, status *Commit
252253

253254
return sess.Commit()
254255
}
256+
257+
type SignCommitWithStatuses struct {
258+
Statuses []*CommitStatus
259+
State CommitStatusState
260+
*SignCommit
261+
}
262+
263+
func ParseCommitsWithStatus(oldCommits *list.List, repo *Repository) *list.List {
264+
var (
265+
newCommits = list.New()
266+
e = oldCommits.Front()
267+
err error
268+
)
269+
270+
for e != nil {
271+
c := e.Value.(SignCommit)
272+
commit := SignCommitWithStatuses{
273+
SignCommit: &c,
274+
State: "",
275+
Statuses: make([]*CommitStatus, 0),
276+
}
277+
commit.Statuses, err = GetLatestCommitStatus(repo, commit.ID.String(), 0)
278+
if err != nil {
279+
log.Error(3, "GetLatestCommitStatus: %v", err)
280+
} else {
281+
for _, status := range commit.Statuses {
282+
if status.State.IsWorseThan(commit.State) {
283+
commit.State = status.State
284+
}
285+
}
286+
}
287+
288+
newCommits.PushBack(commit)
289+
e = e.Next()
290+
}
291+
return newCommits
292+
}

routers/repo/commit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func Commits(ctx *context.Context) {
6969
commits = renderIssueLinks(commits, ctx.Repo.RepoLink)
7070
commits = models.ValidateCommitsWithEmails(commits)
7171
commits = models.ParseCommitsWithSignature(commits)
72+
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
7273
ctx.Data["Commits"] = commits
7374

7475
ctx.Data["Username"] = ctx.Repo.Owner.Name
@@ -123,6 +124,7 @@ func SearchCommits(ctx *context.Context) {
123124
commits = renderIssueLinks(commits, ctx.Repo.RepoLink)
124125
commits = models.ValidateCommitsWithEmails(commits)
125126
commits = models.ParseCommitsWithSignature(commits)
127+
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
126128
ctx.Data["Commits"] = commits
127129

128130
ctx.Data["Keyword"] = keyword
@@ -170,6 +172,7 @@ func FileHistory(ctx *context.Context) {
170172
commits = renderIssueLinks(commits, ctx.Repo.RepoLink)
171173
commits = models.ValidateCommitsWithEmails(commits)
172174
commits = models.ParseCommitsWithSignature(commits)
175+
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
173176
ctx.Data["Commits"] = commits
174177

175178
ctx.Data["Username"] = ctx.Repo.Owner.Name

templates/repo/commits_table.tmpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@
6161
</td>
6262
<td class="message collapsing">
6363
<span class="has-emoji{{if gt .ParentCount 1}} grey text{{end}}">{{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}}</span>
64+
{{if eq .State "pending"}}
65+
<i class="circle icon grey"></i>
66+
{{end}}
67+
{{if eq .State "success"}}
68+
<i class="check icon green"></i>
69+
{{end}}
70+
{{if eq .State "error"}}
71+
<i class="warning icon red"></i>
72+
{{end}}
73+
{{if eq .State "failure"}}
74+
<i class="remove icon red"></i>
75+
{{end}}
76+
{{if eq .State "warning"}}
77+
<i class="circle icon yellow"></i>
78+
{{end}}
6479
</td>
6580
<td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td>
6681
</tr>

0 commit comments

Comments
 (0)