summaryrefslogtreecommitdiffstats
path: root/models/status.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-05-07 17:40:31 +0300
committerBo-Yi Wu <appleboy.tw@gmail.com>2017-05-07 22:40:31 +0800
commit79494047b062069fd8e692152d29773a22877d76 (patch)
tree59f8f66828e25ee9f9c13f2baf50494e5474bbcd /models/status.go
parentc864ccf9b1414dfdae1fd271511853e058b9e7c9 (diff)
downloadgitea-79494047b062069fd8e692152d29773a22877d76.tar.gz
gitea-79494047b062069fd8e692152d29773a22877d76.zip
Show commit status icon in commits table (#1688)
* Show commit status icon in commits table * Add comments * Fix icons * Few more places where commit table is displayed * Change integration test to use goquery for parsing html * Add integration tests for commit table and status icons * Fix status to return lates status correctly on all databases * Rewrote lates commit status selects
Diffstat (limited to 'models/status.go')
-rw-r--r--models/status.go58
1 files changed, 54 insertions, 4 deletions
diff --git a/models/status.go b/models/status.go
index 2e44ed93e6..2ce588bea5 100644
--- a/models/status.go
+++ b/models/status.go
@@ -5,6 +5,7 @@
package models
import (
+ "container/list"
"fmt"
"strings"
"time"
@@ -144,10 +145,20 @@ func GetCommitStatuses(repo *Repository, sha string, page int) ([]*CommitStatus,
// GetLatestCommitStatus returns all statuses with a unique context for a given commit.
func GetLatestCommitStatus(repo *Repository, sha string, page int) ([]*CommitStatus, error) {
- statuses := make([]*CommitStatus, 0, 10)
- return statuses, x.Limit(10, page*10).
- Where("repo_id = ?", repo.ID).And("sha = ?", sha).Select("*").
- GroupBy("context").Desc("created_unix").Find(&statuses)
+ ids := make([]int64, 0, 10)
+ err := x.Limit(10, page*10).
+ Table(&CommitStatus{}).
+ Where("repo_id = ?", repo.ID).And("sha = ?", sha).
+ Select("max( id ) as id").
+ GroupBy("context").OrderBy("max( id ) desc").Find(&ids)
+ if err != nil {
+ return nil, err
+ }
+ statuses := make([]*CommitStatus, 0, len(ids))
+ if len(ids) == 0 {
+ return statuses, nil
+ }
+ return statuses, x.In("id", ids).Find(&statuses)
}
// GetCommitStatus populates a given status for a given commit.
@@ -252,3 +263,42 @@ func NewCommitStatus(repo *Repository, creator *User, sha string, status *Commit
return sess.Commit()
}
+
+// SignCommitWithStatuses represents a commit with validation of signature and status state.
+type SignCommitWithStatuses struct {
+ Statuses []*CommitStatus
+ State CommitStatusState
+ *SignCommit
+}
+
+// ParseCommitsWithStatus checks commits latest statuses and calculates its worst status state
+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)
+ 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
+ }
+ }
+ }
+
+ newCommits.PushBack(commit)
+ e = e.Next()
+ }
+ return newCommits
+}