From f3c4baa84b8fa7afb3eab137b4c5e3544bd9e761 Mon Sep 17 00:00:00 2001 From: Cirno the Strongest <1447794+CirnoT@users.noreply.github.com> Date: Sun, 20 Dec 2020 04:13:12 +0100 Subject: [PATCH] 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 Co-authored-by: techknowlogick --- integrations/repo_commits_test.go | 2 +- models/commit_status.go | 4 +++- routers/repo/blame.go | 1 + routers/repo/commit.go | 1 + routers/repo/issue.go | 3 ++- routers/repo/view.go | 1 + routers/user/home.go | 3 ++- services/pull/pull.go | 6 +++--- templates/repo/commit_page.tmpl | 2 +- templates/repo/commit_status.tmpl | 10 +++++----- templates/repo/commit_statuses.tmpl | 14 ++++++++++++++ templates/repo/commits_list.tmpl | 2 +- templates/repo/commits_list_small.tmpl | 4 ++-- templates/repo/view_list.tmpl | 2 +- templates/shared/issuelist.tmpl | 12 +++++++----- web_src/js/index.js | 9 +++++++++ web_src/less/_base.less | 6 +++++- web_src/less/_repository.less | 4 ++++ 18 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 templates/repo/commit_statuses.tmpl diff --git a/integrations/repo_commits_test.go b/integrations/repo_commits_test.go index f341f8026a..f26960271a 100644 --- a/integrations/repo_commits_test.go +++ b/integrations/repo_commits_test.go @@ -65,7 +65,7 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) { doc = NewHTMLParser(t, resp.Body) // Check if commit status is displayed in message column - sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status") + sel := doc.doc.Find("#commits-table tbody tr td.message a.commit-statuses-trigger i.commit-status") assert.Equal(t, sel.Length(), 1) for _, class := range classes { assert.True(t, sel.HasClass(class)) diff --git a/models/commit_status.go b/models/commit_status.go index 9dffece378..5d637afc2b 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -252,7 +252,8 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { // SignCommitWithStatuses represents a commit with validation of signature and status state. type SignCommitWithStatuses struct { - Status *CommitStatus + Status *CommitStatus + Statuses []*CommitStatus *SignCommit } @@ -272,6 +273,7 @@ func ParseCommitsWithStatus(oldCommits *list.List, repo *Repository) *list.List if err != nil { log.Error("GetLatestCommitStatus: %v", err) } else { + commit.Statuses = statuses commit.Status = CalcCommitStatus(statuses) } diff --git a/routers/repo/blame.go b/routers/repo/blame.go index 514adc3bc1..9be1ea05af 100644 --- a/routers/repo/blame.go +++ b/routers/repo/blame.go @@ -102,6 +102,7 @@ func RefBlame(ctx *context.Context) { blob := entry.Blob() ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses) + ctx.Data["LatestCommitStatuses"] = statuses ctx.Data["Paths"] = paths ctx.Data["TreeLink"] = treeLink diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 43a95c2adb..c411d247e2 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -302,6 +302,7 @@ func Diff(ctx *context.Context) { } ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses) + ctx.Data["CommitStatuses"] = statuses diff, err := gitdiff.GetDiffCommit(repoPath, commitID, setting.Git.MaxGitDiffLines, diff --git a/routers/repo/issue.go b/routers/repo/issue.go index e350f74de9..eec0b7fd96 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -259,7 +259,8 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti return } - commitStatus[issues[i].PullRequest.ID], _ = pull_service.GetLastCommitStatus(issues[i].PullRequest) + var statuses, _ = pull_service.GetLastCommitStatus(issues[i].PullRequest) + commitStatus[issues[i].PullRequest.ID] = models.CalcCommitStatus(statuses) } } diff --git a/routers/repo/view.go b/routers/repo/view.go index 66ad8e3ad7..8f010490c3 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -359,6 +359,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { } ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses) + ctx.Data["LatestCommitStatuses"] = statuses // Check permission to add or upload new file. if ctx.Repo.CanWrite(models.UnitTypeCode) && ctx.Repo.IsViewBranch { diff --git a/routers/user/home.go b/routers/user/home.go index 779971ca97..46532f82b9 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -563,7 +563,8 @@ func Issues(ctx *context.Context) { issue.Repo = showReposMap[issue.RepoID] if isPullList { - commitStatus[issue.PullRequest.ID], _ = pull_service.GetLastCommitStatus(issue.PullRequest) + var statuses, _ = pull_service.GetLastCommitStatus(issue.PullRequest) + commitStatus[issue.PullRequest.ID] = models.CalcCommitStatus(statuses) } } diff --git a/services/pull/pull.go b/services/pull/pull.go index 23a4bf9776..499bafff1e 100644 --- a/services/pull/pull.go +++ b/services/pull/pull.go @@ -640,8 +640,8 @@ func GetCommitMessages(pr *models.PullRequest) string { return stringBuilder.String() } -// GetLastCommitStatus returns the last commit status for this pull request. -func GetLastCommitStatus(pr *models.PullRequest) (status *models.CommitStatus, err error) { +// GetLastCommitStatus returns list of commit statuses for latest commit on this pull request. +func GetLastCommitStatus(pr *models.PullRequest) (status []*models.CommitStatus, err error) { if err = pr.LoadBaseRepo(); err != nil { return nil, err } @@ -666,7 +666,7 @@ func GetLastCommitStatus(pr *models.PullRequest) (status *models.CommitStatus, e if err != nil { return nil, err } - return models.CalcCommitStatus(statusList), nil + return statusList, nil } // IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 0448c938bd..6260d2e965 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -23,7 +23,7 @@ {{.i18n.Tr "repo.diff.browse_source"}} {{end}} -

{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}{{template "repo/commit_status" .CommitStatus}}

+

{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}

{{if IsMultilineCommitMessage .Commit.Message}}
{{RenderCommitBody .Commit.Message $.RepoLink $.Repository.ComposeMetas}}
{{end}} diff --git a/templates/repo/commit_status.tmpl b/templates/repo/commit_status.tmpl index 638f81ed8f..75ab6b4e1c 100644 --- a/templates/repo/commit_status.tmpl +++ b/templates/repo/commit_status.tmpl @@ -1,15 +1,15 @@ {{if eq .State "pending"}} - + {{end}} {{if eq .State "success"}} - + {{end}} {{if eq .State "error"}} - + {{end}} {{if eq .State "failure"}} - + {{end}} {{if eq .State "warning"}} - + {{end}} diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl new file mode 100644 index 0000000000..d2e9f0bd16 --- /dev/null +++ b/templates/repo/commit_statuses.tmpl @@ -0,0 +1,14 @@ +{{template "repo/commit_status" .Status}} + diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index e7489bf51d..66138e2138 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -70,7 +70,7 @@ {{end}} {{if eq (CommitType .) "SignCommitWithStatuses"}} - {{template "repo/commit_status" .Status}} + {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}} {{end}} {{if IsMultilineCommitMessage .Message}} diff --git a/templates/repo/commits_list_small.tmpl b/templates/repo/commits_list_small.tmpl index aaf4174bbd..acab040a45 100644 --- a/templates/repo/commits_list_small.tmpl +++ b/templates/repo/commits_list_small.tmpl @@ -16,8 +16,8 @@ {{if eq (CommitType .) "SignCommitWithStatuses"}} - {{template "repo/commit_status" .Status}} - {{end}} + {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $.root}} + {{end}} {{$class := "ui sha label"}} {{if .Signature}} {{$class = (printf "%s%s" $class " isSigned")}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index a99efab020..fc66fb6b2d 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -21,7 +21,7 @@ {{template "repo/shabox_badge" dict "root" $ "verification" .LatestCommitVerification}} {{end}} - {{template "repo/commit_status" .LatestCommitStatus}} + {{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses "root" $}} {{ $commitLink:= printf "%s/commit/%s" .RepoLink .LatestCommit.ID }} {{RenderCommitMessageLinkSubject .LatestCommit.Message $.RepoLink $commitLink $.Repository.ComposeMetas}} {{if IsMultilineCommitMessage .LatestCommit.Message}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index 62f55f6c40..adb319a644 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -31,12 +31,14 @@
- {{RenderEmoji .Title}} - {{if .IsPull }} - {{if (index $.CommitStatus .PullRequest.ID)}} - {{template "repo/commit_status" (index $.CommitStatus .PullRequest.ID)}} + + {{RenderEmoji .Title}} + {{if .IsPull }} + {{if (index $.CommitStatus .PullRequest.ID)}} + {{template "repo/commit_status" (index $.CommitStatus .PullRequest.ID)}} + {{end}} {{end}} - {{end}} + {{range .Labels}} {{.Name | RenderEmoji}} diff --git a/web_src/js/index.js b/web_src/js/index.js index e55e2febe0..dd7032eb84 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -759,6 +759,15 @@ async function initRepository() { }); } + // Commit statuses + $('.commit-statuses-trigger').each(function () { + $(this) + .popup({ + on: 'click', + position: ($('.repository.file.list').length > 0 ? 'right center' : 'left center'), + }); + }); + // File list and commits if ($('.repository.file.list').length > 0 || ('.repository.commits').length > 0) { initFilterBranchTagDropdown('.choose.reference .dropdown'); diff --git a/web_src/less/_base.less b/web_src/less/_base.less index e49b1c5bbb..7dbbda04de 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -530,6 +530,10 @@ a.ui.card:hover, border-radius: var(--border-radius); } +.ui.divided.list > .item { + border-color: var(--color-secondary); +} + .dont-break-out { overflow-wrap: break-word; word-wrap: break-word; @@ -1164,7 +1168,7 @@ footer { } } -.center { +.center:not(.popup) { text-align: center; } diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 0180a6ec1b..f859737e07 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -1,4 +1,8 @@ .repository { + .commit-statuses .list > .item { + line-height: 2; + } + .repo-header { .ui.compact.menu { margin-left: 1rem;