diff --git a/models/status.go b/models/status.go index e300c763ff..d0c4a08744 100644 --- a/models/status.go +++ b/models/status.go @@ -126,6 +126,26 @@ func (status *CommitStatus) APIFormat() *api.Status { return apiStatus } +// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc +func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus { + var lastStatus *CommitStatus + var state CommitStatusState + for _, status := range statuses { + if status.State.IsWorseThan(state) { + state = status.State + lastStatus = status + } + } + if lastStatus == nil { + if len(statuses) > 0 { + lastStatus = statuses[0] + } else { + lastStatus = &CommitStatus{} + } + } + return lastStatus +} + // GetCommitStatuses returns all statuses for a given commit. func GetCommitStatuses(repo *Repository, sha string, page int) ([]*CommitStatus, error) { statuses := make([]*CommitStatus, 0, 10) @@ -255,8 +275,7 @@ func NewCommitStatus(repo *Repository, creator *User, sha string, status *Commit // SignCommitWithStatuses represents a commit with validation of signature and status state. type SignCommitWithStatuses struct { - Statuses []*CommitStatus - State CommitStatusState + Status *CommitStatus *SignCommit } @@ -265,25 +284,18 @@ func ParseCommitsWithStatus(oldCommits *list.List, repo *Repository) *list.List var ( newCommits = list.New() e = oldCommits.Front() - err error ) for e != nil { c := e.Value.(SignCommit) commit := SignCommitWithStatuses{ SignCommit: &c, - State: "", - Statuses: make([]*CommitStatus, 0), } - commit.Statuses, err = GetLatestCommitStatus(repo, commit.ID.String(), 0) + statuses, err := GetLatestCommitStatus(repo, commit.ID.String(), 0) if err != nil { log.Error(3, "GetLatestCommitStatus: %v", err) } else { - for _, status := range commit.Statuses { - if status.State.IsWorseThan(commit.State) { - commit.State = status.State - } - } + commit.Status = CalcCommitStatus(statuses) } newCommits.PushBack(commit) diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 1835e47318..95630fcece 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -13,7 +13,9 @@ 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" + "github.com/Unknwon/paginater" ) @@ -208,6 +210,14 @@ func Diff(ctx *context.Context) { if len(commitID) != 40 { commitID = commit.ID.String() } + + statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, ctx.Repo.Commit.ID.String(), 0) + if err != nil { + log.Error(3, "GetLatestCommitStatus: %v", err) + } + + ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses) + diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) diff --git a/routers/repo/view.go b/routers/repo/view.go index 84e5ba85ce..3a9e0e1d3b 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -1,3 +1,4 @@ +// Copyright 2017 The Gitea Authors. All rights reserved. // Copyright 2014 The Gogs Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -120,6 +121,13 @@ func renderDirectory(ctx *context.Context, treeLink string) { ctx.Data["LatestCommitVerification"] = models.ParseCommitWithSignature(latestCommit) ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(latestCommit) + statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, ctx.Repo.Commit.ID.String(), 0) + if err != nil { + log.Error(3, "GetLatestCommitStatus: %v", err) + } + + ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(statuses) + // Check permission to add or upload new file. if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch { ctx.Data["CanAddFile"] = true diff --git a/templates/repo/commit_status.tmpl b/templates/repo/commit_status.tmpl new file mode 100644 index 0000000000..752fd762e3 --- /dev/null +++ b/templates/repo/commit_status.tmpl @@ -0,0 +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}} \ No newline at end of file diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index e33ffcdaa3..b5bd8f33d0 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -61,21 +61,7 @@ {{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}} - {{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}} + {{template "repo/commit_status" .Status}} {{TimeSince .Author.When $.Lang}} diff --git a/templates/repo/diff/page.tmpl b/templates/repo/diff/page.tmpl index 4ddf3ad436..2736daa7f9 100644 --- a/templates/repo/diff/page.tmpl +++ b/templates/repo/diff/page.tmpl @@ -9,7 +9,7 @@ {{.i18n.Tr "repo.diff.browse_source"}} - {{RenderCommitMessage true .Commit.Message $.RepoLink $.Repository.ComposeMetas}} +

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

{{if .Author}} diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 663ef41447..67164753e9 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -25,7 +25,8 @@
{{end}} - {{RenderCommitMessage false .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}} + {{RenderCommitMessage false .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}} + {{template "repo/commit_status" .LatestCommitStatus}}