@@ -2,6 +2,7 @@ package github
2
2
3
3
import (
4
4
"net/http"
5
+ "strings"
5
6
6
7
"github.com/google/go-github/github"
7
8
"github.com/shurcooL/githubv4"
@@ -26,7 +27,7 @@ func New(githubAccessToken string) *githubManager {
26
27
return & githubManager {Context : ctx , Client : client , HttpClient : httpClient }
27
28
}
28
29
29
- func (gm * githubManager ) GetCommits (owner , repo , branch string , lastCommitsNumber int , specificCheckName string ) ([]Commit , error ) {
30
+ func (gm * githubManager ) GetCommits (owner , repo , branch string , lastCommitsNumber int , specificChecksNames string , sep string ) ([]Commit , error ) {
30
31
if lastCommitsNumber > 100 || lastCommitsNumber < 1 {
31
32
return nil , & Error {Message : "lastCommitsNumber must be a number between 1 and 100" } // TODO maybe in future implement pagination
32
33
}
@@ -45,7 +46,7 @@ func (gm *githubManager) GetCommits(owner, repo, branch string, lastCommitsNumbe
45
46
return nil , err
46
47
}
47
48
48
- return hydrateCommits (q , specificCheckName ), nil
49
+ return hydrateCommits (q , specificChecksNames , sep ), nil
49
50
}
50
51
51
52
func PickFirstParentCommits (fullCommitsList []Commit ) []Commit {
@@ -96,7 +97,7 @@ func (gm *githubManager) ChangeBranchHead(owner, repo, branch, sha string, force
96
97
return nil
97
98
}
98
99
99
- func hydrateCommits (q * githubQuery , specificCheckName string ) []Commit {
100
+ func hydrateCommits (q * githubQuery , specificChecksNames string , sep string ) []Commit {
100
101
var fullCommitsList []Commit
101
102
for _ , edge := range q .Repository .Ref .Target .Commit .History .Edges {
102
103
var parents []Commit
@@ -108,25 +109,40 @@ func hydrateCommits(q *githubQuery, specificCheckName string) []Commit {
108
109
}
109
110
110
111
statusSuccess := false
111
- // In case a commit check name is specified, it override and get priority over the commit cumulative status
112
- if specificCheckName != "" {
112
+ checkNames := strings .Split (specificChecksNames , sep )
113
+ numChecks := len (checkNames )
114
+ sc := 0
115
+ cc := 0
116
+
117
+ for _ , cn := range checkNames {
118
+
113
119
// first check if commit has commit status set
114
120
for _ , context := range edge .Node .Status .Contexts {
115
- if githubv4 .String (specificCheckName ) == context .Context {
116
- statusSuccess = context .State == githubv4 .String (githubv4 .StatusStateSuccess )
121
+ if githubv4 .String (cn ) == context .Context {
122
+ if context .State == githubv4 .String (githubv4 .StatusStateSuccess ) {
123
+ sc ++
124
+ }
117
125
}
118
126
}
119
127
120
128
// then check if commit has check-run set
121
129
for _ , checkSuite := range edge .Node .CheckSuites .Nodes {
122
130
for _ , checkRuns := range checkSuite .CheckRuns .Nodes {
123
- if githubv4 .String (specificCheckName ) == checkRuns .Name {
124
- statusSuccess = checkRuns .Conclusion == githubv4 .String (githubv4 .StatusStateSuccess )
131
+ if githubv4 .String (cn ) == checkRuns .Name {
132
+ if checkRuns .Conclusion == githubv4 .String (githubv4 .StatusStateSuccess ) {
133
+ cc ++
134
+ }
125
135
}
126
136
}
127
137
}
128
- } else {
129
- statusSuccess = bool (edge .Node .StatusCheckRollup .State == githubv4 .String (githubv4 .StatusStateSuccess ))
138
+ }
139
+
140
+ if numChecks == sc || numChecks == cc {
141
+ statusSuccess = true
142
+ }
143
+
144
+ if numChecks == 0 {
145
+ statusSuccess = edge .Node .StatusCheckRollup .State == githubv4 .String (githubv4 .StatusStateSuccess )
130
146
}
131
147
132
148
fullCommitsList = append (fullCommitsList , Commit {
0 commit comments