1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00

Display commit status on landing page of repo (#1784)

* Display commit status on landing page of repo

* improve last status of commits and add link to ci

* fix last commit status since the order of ids are desc
This commit is contained in:
Rémy Boulanouar 2017-09-14 08:51:32 +02:00 committed by Lunny Xiao
parent a89692d158
commit be3319b3d5
7 changed files with 60 additions and 28 deletions

View File

@ -126,6 +126,26 @@ func (status *CommitStatus) APIFormat() *api.Status {
return apiStatus 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. // GetCommitStatuses returns all statuses for a given commit.
func GetCommitStatuses(repo *Repository, sha string, page int) ([]*CommitStatus, error) { func GetCommitStatuses(repo *Repository, sha string, page int) ([]*CommitStatus, error) {
statuses := make([]*CommitStatus, 0, 10) 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. // SignCommitWithStatuses represents a commit with validation of signature and status state.
type SignCommitWithStatuses struct { type SignCommitWithStatuses struct {
Statuses []*CommitStatus Status *CommitStatus
State CommitStatusState
*SignCommit *SignCommit
} }
@ -265,25 +284,18 @@ func ParseCommitsWithStatus(oldCommits *list.List, repo *Repository) *list.List
var ( var (
newCommits = list.New() newCommits = list.New()
e = oldCommits.Front() e = oldCommits.Front()
err error
) )
for e != nil { for e != nil {
c := e.Value.(SignCommit) c := e.Value.(SignCommit)
commit := SignCommitWithStatuses{ commit := SignCommitWithStatuses{
SignCommit: &c, 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 { if err != nil {
log.Error(3, "GetLatestCommitStatus: %v", err) log.Error(3, "GetLatestCommitStatus: %v", err)
} else { } else {
for _, status := range commit.Statuses { commit.Status = CalcCommitStatus(statuses)
if status.State.IsWorseThan(commit.State) {
commit.State = status.State
}
}
} }
newCommits.PushBack(commit) newCommits.PushBack(commit)

View File

@ -13,7 +13,9 @@ import (
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"github.com/Unknwon/paginater" "github.com/Unknwon/paginater"
) )
@ -208,6 +210,14 @@ func Diff(ctx *context.Context) {
if len(commitID) != 40 { if len(commitID) != 40 {
commitID = commit.ID.String() 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), diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName),
commitID, setting.Git.MaxGitDiffLines, commitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles) setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)

View File

@ -1,3 +1,4 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Copyright 2014 The Gogs Authors. All rights reserved. // Copyright 2014 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // 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["LatestCommitVerification"] = models.ParseCommitWithSignature(latestCommit)
ctx.Data["LatestCommitUser"] = models.ValidateCommitWithEmail(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. // Check permission to add or upload new file.
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch { if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
ctx.Data["CanAddFile"] = true ctx.Data["CanAddFile"] = true

View File

@ -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}}

View File

@ -61,21 +61,7 @@
</td> </td>
<td class="message collapsing"> <td class="message collapsing">
<span class="has-emoji{{if gt .ParentCount 1}} grey text{{end}}">{{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}}</span> <span class="has-emoji{{if gt .ParentCount 1}} grey text{{end}}">{{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}}</span>
{{if eq .State "pending"}} {{template "repo/commit_status" .Status}}
<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}}
</td> </td>
<td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td> <td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td>
</tr> </tr>

View File

@ -9,7 +9,7 @@
<a class="ui floated right blue tiny button" href="{{EscapePound .SourcePath}}"> <a class="ui floated right blue tiny button" href="{{EscapePound .SourcePath}}">
{{.i18n.Tr "repo.diff.browse_source"}} {{.i18n.Tr "repo.diff.browse_source"}}
</a> </a>
{{RenderCommitMessage true .Commit.Message $.RepoLink $.Repository.ComposeMetas}} <h3>{{RenderCommitMessage false .Commit.Message $.RepoLink $.Repository.ComposeMetas}}{{template "repo/commit_status" .CommitStatus}}</h3>
</div> </div>
<div class="ui attached info segment {{if .Commit.Signature}} isSigned {{if .Verification.Verified }} isVerified {{end}}{{end}}"> <div class="ui attached info segment {{if .Commit.Signature}} isSigned {{if .Verification.Verified }} isVerified {{end}}{{end}}">
{{if .Author}} {{if .Author}}

View File

@ -25,7 +25,8 @@
</div> </div>
{{end}} {{end}}
</a> </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>
<th class="nine wide"> <th class="nine wide">
</th> </th>