@@ -2,6 +2,7 @@ package github
22
33import (
44 "net/http"
5+ "strings"
56
67 "github.com/google/go-github/github"
78 "github.com/shurcooL/githubv4"
@@ -26,7 +27,7 @@ func New(githubAccessToken string) *githubManager {
2627 return & githubManager {Context : ctx , Client : client , HttpClient : httpClient }
2728}
2829
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 ) {
3031 if lastCommitsNumber > 100 || lastCommitsNumber < 1 {
3132 return nil , & Error {Message : "lastCommitsNumber must be a number between 1 and 100" } // TODO maybe in future implement pagination
3233 }
@@ -45,7 +46,7 @@ func (gm *githubManager) GetCommits(owner, repo, branch string, lastCommitsNumbe
4546 return nil , err
4647 }
4748
48- return hydrateCommits (q , specificCheckName ), nil
49+ return hydrateCommits (q , specificChecksNames , sep ), nil
4950}
5051
5152func PickFirstParentCommits (fullCommitsList []Commit ) []Commit {
@@ -96,7 +97,7 @@ func (gm *githubManager) ChangeBranchHead(owner, repo, branch, sha string, force
9697 return nil
9798}
9899
99- func hydrateCommits (q * githubQuery , specificCheckName string ) []Commit {
100+ func hydrateCommits (q * githubQuery , specificChecksNames string , sep string ) []Commit {
100101 var fullCommitsList []Commit
101102 for _ , edge := range q .Repository .Ref .Target .Commit .History .Edges {
102103 var parents []Commit
@@ -108,25 +109,40 @@ func hydrateCommits(q *githubQuery, specificCheckName string) []Commit {
108109 }
109110
110111 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+
113119 // first check if commit has commit status set
114120 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+ }
117125 }
118126 }
119127
120128 // then check if commit has check-run set
121129 for _ , checkSuite := range edge .Node .CheckSuites .Nodes {
122130 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+ }
125135 }
126136 }
127137 }
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 )
130146 }
131147
132148 fullCommitsList = append (fullCommitsList , Commit {
0 commit comments