aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/status.go34
-rw-r--r--routers/repo/commit.go10
-rw-r--r--routers/repo/view.go8
-rw-r--r--templates/repo/commit_status.tmpl15
-rw-r--r--templates/repo/commits_table.tmpl16
-rw-r--r--templates/repo/diff/page.tmpl2
-rw-r--r--templates/repo/view_list.tmpl3
7 files changed, 60 insertions, 28 deletions
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"}}
+ <a href="{{.TargetURL}}" target=_blank><i class="commit-status circle icon yellow"></i></a>
+{{end}}
+{{if eq .State "success"}}
+ <a href="{{.TargetURL}}" target=_blank><i class="commit-status check icon green"></i></a>
+{{end}}
+{{if eq .State "error"}}
+ <a href="{{.TargetURL}}" target=_blank><i class="commit-status warning icon red"></i></a>
+{{end}}
+{{if eq .State "failure"}}
+ <a href="{{.TargetURL}}" target=_blank><i class="commit-status remove icon red"></i></a>
+{{end}}
+{{if eq .State "warning"}}
+ <a href="{{.TargetURL}}" target=_blank><i class="commit-status warning sign icon yellow"></i></a>
+{{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 @@
</td>
<td class="message collapsing">
<span class="has-emoji{{if gt .ParentCount 1}} grey text{{end}}">{{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}}</span>
- {{if eq .State "pending"}}
- <i class="commit-status circle icon yellow"></i>
- {{end}}
- {{if eq .State "success"}}
- <i class="commit-status check icon green"></i>
- {{end}}
- {{if eq .State "error"}}
- <i class="commit-status warning icon red"></i>
- {{end}}
- {{if eq .State "failure"}}
- <i class="commit-status remove icon red"></i>
- {{end}}
- {{if eq .State "warning"}}
- <i class="commit-status warning sign icon yellow"></i>
- {{end}}
+ {{template "repo/commit_status" .Status}}
</td>
<td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td>
</tr>
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 @@
<a class="ui floated right blue tiny button" href="{{EscapePound .SourcePath}}">
{{.i18n.Tr "repo.diff.browse_source"}}
</a>
- {{RenderCommitMessage true .Commit.Message $.RepoLink $.Repository.ComposeMetas}}
+ <h3>{{RenderCommitMessage false .Commit.Message $.RepoLink $.Repository.ComposeMetas}}{{template "repo/commit_status" .CommitStatus}}</h3>
</div>
<div class="ui attached info segment {{if .Commit.Signature}} isSigned {{if .Verification.Verified }} isVerified {{end}}{{end}}">
{{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 @@
</div>
{{end}}
</a>
- <span class="grey has-emoji">{{RenderCommitMessage false .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}}</span>
+ <span class="grey has-emoji">{{RenderCommitMessage false .LatestCommit.Summary .RepoLink $.Repository.ComposeMetas}}
+ {{template "repo/commit_status" .LatestCommitStatus}}</span>
</th>
<th class="nine wide">
</th>