diff options
author | Rémy Boulanouar <rboulanouar@gmail.com> | 2017-09-14 08:51:32 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-09-14 14:51:31 +0800 |
commit | be3319b3d545289b772d7a92b4b62205863954d9 (patch) | |
tree | 89473f47f6303ea5ab57ade7901de1a3a48dd673 /models | |
parent | a89692d15884271a2927b5f7332ed074116d324c (diff) | |
download | gitea-be3319b3d545289b772d7a92b4b62205863954d9.tar.gz gitea-be3319b3d545289b772d7a92b4b62205863954d9.zip |
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
Diffstat (limited to 'models')
-rw-r--r-- | models/status.go | 34 |
1 files changed, 23 insertions, 11 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) |