Skip to content

Commit f3c4baa

Browse files
CirnoTlunnytechknowlogick
authored
Show dropdown with all statuses for commit (#13977)
* Show dropdown with all statuses for commit * Use popups * Remove unnecessary change * Style popup * Use divided list * As per @silverwind * Refactor GetLastCommitStatus * Missing dropdown on repo home and commit page * Fix tests * Make status icon be a part of a link on PR list * Fix missing translation call * Indent fix Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 029836c commit f3c4baa

File tree

18 files changed

+63
-23
lines changed

18 files changed

+63
-23
lines changed

integrations/repo_commits_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
6565

6666
doc = NewHTMLParser(t, resp.Body)
6767
// Check if commit status is displayed in message column
68-
sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
68+
sel := doc.doc.Find("#commits-table tbody tr td.message a.commit-statuses-trigger i.commit-status")
6969
assert.Equal(t, sel.Length(), 1)
7070
for _, class := range classes {
7171
assert.True(t, sel.HasClass(class))

models/commit_status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ func NewCommitStatus(opts NewCommitStatusOptions) error {
252252

253253
// SignCommitWithStatuses represents a commit with validation of signature and status state.
254254
type SignCommitWithStatuses struct {
255-
Status *CommitStatus
255+
Status *CommitStatus
256+
Statuses []*CommitStatus
256257
*SignCommit
257258
}
258259

@@ -272,6 +273,7 @@ func ParseCommitsWithStatus(oldCommits *list.List, repo *Repository) *list.List
272273
if err != nil {
273274
log.Error("GetLatestCommitStatus: %v", err)
274275
} else {
276+
commit.Statuses = statuses
275277
commit.Status = CalcCommitStatus(statuses)
276278
}
277279

routers/repo/blame.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func RefBlame(ctx *context.Context) {
102102
blob := entry.Blob()
103103

104104
ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses)
105+
ctx.Data["LatestCommitStatuses"] = statuses
105106

106107
ctx.Data["Paths"] = paths
107108
ctx.Data["TreeLink"] = treeLink

routers/repo/commit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ func Diff(ctx *context.Context) {
302302
}
303303

304304
ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)
305+
ctx.Data["CommitStatuses"] = statuses
305306

306307
diff, err := gitdiff.GetDiffCommit(repoPath,
307308
commitID, setting.Git.MaxGitDiffLines,

routers/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
259259
return
260260
}
261261

262-
commitStatus[issues[i].PullRequest.ID], _ = pull_service.GetLastCommitStatus(issues[i].PullRequest)
262+
var statuses, _ = pull_service.GetLastCommitStatus(issues[i].PullRequest)
263+
commitStatus[issues[i].PullRequest.ID] = models.CalcCommitStatus(statuses)
263264
}
264265
}
265266

routers/repo/view.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
359359
}
360360

361361
ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses)
362+
ctx.Data["LatestCommitStatuses"] = statuses
362363

363364
// Check permission to add or upload new file.
364365
if ctx.Repo.CanWrite(models.UnitTypeCode) && ctx.Repo.IsViewBranch {

routers/user/home.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ func Issues(ctx *context.Context) {
563563
issue.Repo = showReposMap[issue.RepoID]
564564

565565
if isPullList {
566-
commitStatus[issue.PullRequest.ID], _ = pull_service.GetLastCommitStatus(issue.PullRequest)
566+
var statuses, _ = pull_service.GetLastCommitStatus(issue.PullRequest)
567+
commitStatus[issue.PullRequest.ID] = models.CalcCommitStatus(statuses)
567568
}
568569
}
569570

services/pull/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ func GetCommitMessages(pr *models.PullRequest) string {
640640
return stringBuilder.String()
641641
}
642642

643-
// GetLastCommitStatus returns the last commit status for this pull request.
644-
func GetLastCommitStatus(pr *models.PullRequest) (status *models.CommitStatus, err error) {
643+
// GetLastCommitStatus returns list of commit statuses for latest commit on this pull request.
644+
func GetLastCommitStatus(pr *models.PullRequest) (status []*models.CommitStatus, err error) {
645645
if err = pr.LoadBaseRepo(); err != nil {
646646
return nil, err
647647
}
@@ -666,7 +666,7 @@ func GetLastCommitStatus(pr *models.PullRequest) (status *models.CommitStatus, e
666666
if err != nil {
667667
return nil, err
668668
}
669-
return models.CalcCommitStatus(statusList), nil
669+
return statusList, nil
670670
}
671671

672672
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{{.i18n.Tr "repo.diff.browse_source"}}
2424
</a>
2525
{{end}}
26-
<h3><span class="message-wrapper"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</span></span>{{template "repo/commit_status" .CommitStatus}}</h3>
26+
<h3><span class="message-wrapper"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</span></span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}</h3>
2727
{{if IsMultilineCommitMessage .Commit.Message}}
2828
<pre class="commit-body">{{RenderCommitBody .Commit.Message $.RepoLink $.Repository.ComposeMetas}}</pre>
2929
{{end}}

templates/repo/commit_status.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{{if eq .State "pending"}}
2-
<a class="commit-status-link" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer"><i class="commit-status circle icon yellow"></i></a>
2+
<i class="commit-status circle icon yellow"></i>
33
{{end}}
44
{{if eq .State "success"}}
5-
<a class="commit-status-link" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer"><i class="commit-status check icon green"></i></a>
5+
<i class="commit-status check icon green"></i>
66
{{end}}
77
{{if eq .State "error"}}
8-
<a class="commit-status-link" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer"><i class="commit-status warning icon red"></i></a>
8+
<i class="commit-status warning icon red"></i>
99
{{end}}
1010
{{if eq .State "failure"}}
11-
<a class="commit-status-link" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer"><i class="commit-status remove icon red"></i></a>
11+
<i class="commit-status remove icon red"></i>
1212
{{end}}
1313
{{if eq .State "warning"}}
14-
<a class="commit-status-link" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer"><i class="commit-status warning sign icon yellow"></i></a>
14+
<i class="commit-status warning sign icon yellow"></i>
1515
{{end}}

templates/repo/commit_statuses.tmpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<a class="ui link commit-statuses-trigger">{{template "repo/commit_status" .Status}}</a>
2+
<div class="ui popup very wide fixed basic commit-statuses">
3+
<div class="ui relaxed list divided">
4+
{{range .Statuses}}
5+
<div class="ui item singular-status">
6+
<span>{{template "repo/commit_status" .}}</span>
7+
<span class="ui">{{.Context}} <span class="text grey">{{.Description}}</span></span>
8+
{{if .TargetURL}}
9+
<div class="ui right"><a href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer">{{$.root.i18n.Tr "repo.pulls.status_checks_details"}}</a></div>
10+
{{end}}
11+
</div>
12+
{{end}}
13+
</div>
14+
</div>

templates/repo/commits_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<button class="basic compact mini ui icon button commit-button"><i class="ellipsis horizontal icon"></i></button>
7171
{{end}}
7272
{{if eq (CommitType .) "SignCommitWithStatuses"}}
73-
{{template "repo/commit_status" .Status}}
73+
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}}
7474
{{end}}
7575
{{if IsMultilineCommitMessage .Message}}
7676
<pre class="commit-body" style="display: none;">{{RenderCommitBody .Message $.RepoLink $.Repository.ComposeMetas}}</pre>

templates/repo/commits_list_small.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<span class="ui float right shabox">
1818
{{if eq (CommitType .) "SignCommitWithStatuses"}}
19-
{{template "repo/commit_status" .Status}}
20-
{{end}}
19+
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $.root}}
20+
{{end}}
2121
{{$class := "ui sha label"}}
2222
{{if .Signature}}
2323
{{$class = (printf "%s%s" $class " isSigned")}}

templates/repo/view_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{{template "repo/shabox_badge" dict "root" $ "verification" .LatestCommitVerification}}
2222
{{end}}
2323
</a>
24-
{{template "repo/commit_status" .LatestCommitStatus}}
24+
{{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses "root" $}}
2525
{{ $commitLink:= printf "%s/commit/%s" .RepoLink .LatestCommit.ID }}
2626
<span class="grey commit-summary" title="{{.LatestCommit.Summary}}"><span class="message-wrapper">{{RenderCommitMessageLinkSubject .LatestCommit.Message $.RepoLink $commitLink $.Repository.ComposeMetas}}</span>
2727
{{if IsMultilineCommitMessage .LatestCommit.Message}}

templates/shared/issuelist.tmpl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
</div>
3232
<div class="issue-item-main f1 fc df">
3333
<div class="issue-item-top-row df ac fw">
34-
<a class="title mr-3" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji .Title}}</a>
35-
{{if .IsPull }}
36-
{{if (index $.CommitStatus .PullRequest.ID)}}
37-
{{template "repo/commit_status" (index $.CommitStatus .PullRequest.ID)}}
34+
<a class="title mr-3" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">
35+
{{RenderEmoji .Title}}
36+
{{if .IsPull }}
37+
{{if (index $.CommitStatus .PullRequest.ID)}}
38+
{{template "repo/commit_status" (index $.CommitStatus .PullRequest.ID)}}
39+
{{end}}
3840
{{end}}
39-
{{end}}
41+
</a>
4042
<span class="labels-list">
4143
{{range .Labels}}
4244
<a class="ui label" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&state={{$.State}}&labels={{.ID}}{{if ne $.listType "milestone"}}&milestone={{$.MilestoneID}}{{end}}&assignee={{$.AssigneeID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}" title="{{.Description | RenderEmojiPlain}}">{{.Name | RenderEmoji}}</a>

web_src/js/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,15 @@ async function initRepository() {
759759
});
760760
}
761761

762+
// Commit statuses
763+
$('.commit-statuses-trigger').each(function () {
764+
$(this)
765+
.popup({
766+
on: 'click',
767+
position: ($('.repository.file.list').length > 0 ? 'right center' : 'left center'),
768+
});
769+
});
770+
762771
// File list and commits
763772
if ($('.repository.file.list').length > 0 || ('.repository.commits').length > 0) {
764773
initFilterBranchTagDropdown('.choose.reference .dropdown');

web_src/less/_base.less

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ a.ui.card:hover,
530530
border-radius: var(--border-radius);
531531
}
532532

533+
.ui.divided.list > .item {
534+
border-color: var(--color-secondary);
535+
}
536+
533537
.dont-break-out {
534538
overflow-wrap: break-word;
535539
word-wrap: break-word;
@@ -1164,7 +1168,7 @@ footer {
11641168
}
11651169
}
11661170

1167-
.center {
1171+
.center:not(.popup) {
11681172
text-align: center;
11691173
}
11701174

web_src/less/_repository.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.repository {
2+
.commit-statuses .list > .item {
3+
line-height: 2;
4+
}
5+
26
.repo-header {
37
.ui.compact.menu {
48
margin-left: 1rem;

0 commit comments

Comments
 (0)