Skip to content

Commit 7e220f2

Browse files
authored
DQSAAS-826 Fix status and check commit if already in dest branch (#1)
1 parent c1eb937 commit 7e220f2

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

flow-manager/manager.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package flow_manager
22

33
import (
4+
"fmt"
5+
46
"github.com/Docplanner/github-flow-manager/github"
57
"github.com/araddon/qlbridge/datasource"
68
"github.com/araddon/qlbridge/expr"
@@ -17,9 +19,20 @@ func Manage(githubToken, owner, repo, sourceBranch, destinationBranch, expressio
1719
}
1820
firstParentCommits := github.PickFirstParentCommits(commits)
1921

22+
destinationCommits, err := gm.GetCommits(owner, repo, destinationBranch, 1)
23+
if nil != err {
24+
return nil, err
25+
}
26+
2027
var evaluationResultList []evaluationResult
2128
builtins.LoadAllBuiltins()
2229
for _, commit := range firstParentCommits {
30+
31+
if destinationCommits[0].SHA == commit.SHA {
32+
fmt.Println("COMMIT ID: " + commit.SHA + " IS ALREADY IN " + destinationBranch + " branch. EXITING THE PROCESS WITHOUT ANY ACTION.")
33+
return evaluationResultList, nil
34+
}
35+
2336
evalContext := datasource.NewContextSimpleNative(map[string]interface{}{
2437
"SHA": commit.SHA,
2538
"Message": commit.Message,

github/github-query.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ type githubQuery struct {
1818
}
1919
}
2020
} `graphql:"parents(first: $parentsNumber)"`
21-
Oid githubql.String
22-
Message githubql.String
23-
PushedDate githubql.DateTime
24-
Status struct {
25-
Id githubql.String
26-
State githubql.String
21+
Oid githubql.String
22+
Message githubql.String
23+
PushedDate githubql.DateTime
24+
StatusCheckRollup struct {
25+
State githubql.String
26+
Contexts struct {
27+
TotalCount githubql.Int
28+
} `graphql:"contexts(first: $parentsNumber)"`
2729
}
2830
}
2931
}

github/manager.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package github
22

33
import (
4-
"golang.org/x/oauth2"
5-
"golang.org/x/net/context"
6-
"github.com/shurcooL/githubql"
7-
"github.com/google/go-github/github"
84
"net/http"
5+
6+
"github.com/google/go-github/github"
7+
"github.com/shurcooL/githubql"
8+
"golang.org/x/net/context"
9+
"golang.org/x/oauth2"
910
)
1011

1112
type githubManager struct {
@@ -14,7 +15,7 @@ type githubManager struct {
1415
HttpClient *http.Client
1516
}
1617

17-
func New(githubAccessToken string) (*githubManager) {
18+
func New(githubAccessToken string) *githubManager {
1819
ctx := context.Background()
1920
src := oauth2.StaticTokenSource(
2021
&oauth2.Token{AccessToken: githubAccessToken},
@@ -47,7 +48,7 @@ func (gm *githubManager) GetCommits(owner, repo, branch string, lastCommitsNumbe
4748
return hydrateCommits(q), nil
4849
}
4950

50-
func PickFirstParentCommits(fullCommitsList []Commit) ([]Commit) {
51+
func PickFirstParentCommits(fullCommitsList []Commit) []Commit {
5152
var firstParentCommits []Commit
5253
if 0 == len(fullCommitsList) {
5354
return firstParentCommits
@@ -76,7 +77,7 @@ func PickFirstParentCommits(fullCommitsList []Commit) ([]Commit) {
7677
}
7778

7879
// TODO remove v3 client when implemented in v4
79-
func (gm *githubManager) ChangeBranchHead(owner, repo, branch, sha string, force bool) (error) {
80+
func (gm *githubManager) ChangeBranchHead(owner, repo, branch, sha string, force bool) error {
8081
httpClient := gm.HttpClient
8182

8283
client := github.NewClient(httpClient)
@@ -95,7 +96,7 @@ func (gm *githubManager) ChangeBranchHead(owner, repo, branch, sha string, force
9596
return nil
9697
}
9798

98-
func hydrateCommits(q *githubQuery) ([]Commit) {
99+
func hydrateCommits(q *githubQuery) []Commit {
99100
var fullCommitsList []Commit
100101
for _, edge := range q.Repository.Ref.Target.Commit.History.Edges {
101102
var parents []Commit
@@ -105,11 +106,12 @@ func hydrateCommits(q *githubQuery) ([]Commit) {
105106
Message: string(parent.Node.Message),
106107
})
107108
}
109+
108110
fullCommitsList = append(fullCommitsList, Commit{
109111
SHA: string(edge.Node.Oid),
110112
Message: string(edge.Node.Message),
111113
Parents: parents,
112-
StatusSuccess: bool(edge.Node.Status.State == githubql.String(githubql.StatusStateSuccess)),
114+
StatusSuccess: bool(edge.Node.StatusCheckRollup.State == githubql.String(githubql.StatusStateSuccess)),
113115
PushedDate: edge.Node.PushedDate.Time,
114116
})
115117
}

0 commit comments

Comments
 (0)