X Tutup
Skip to content

Commit c7a38b6

Browse files
committed
Merge branch 'checks-crash'
2 parents 8e89c04 + 7c731bc commit c7a38b6

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

api/pull_request_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package api
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
)
7+
8+
func TestPullRequest_ChecksStatus(t *testing.T) {
9+
pr := PullRequest{}
10+
payload := `
11+
{ "commits": { "nodes": [{ "commit": {
12+
"statusCheckRollup": {
13+
"contexts": {
14+
"nodes": [
15+
{ "state": "SUCCESS" },
16+
{ "state": "PENDING" },
17+
{ "state": "FAILURE" },
18+
{ "status": "IN_PROGRESS",
19+
"conclusion": null },
20+
{ "status": "COMPLETED",
21+
"conclusion": "SUCCESS" },
22+
{ "status": "COMPLETED",
23+
"conclusion": "FAILURE" },
24+
{ "status": "COMPLETED",
25+
"conclusion": "ACTION_REQUIRED" }
26+
]
27+
}
28+
}
29+
} }] } }
30+
`
31+
err := json.Unmarshal([]byte(payload), &pr)
32+
eq(t, err, nil)
33+
34+
checks := pr.ChecksStatus()
35+
eq(t, checks.Total, 7)
36+
eq(t, checks.Pending, 2)
37+
eq(t, checks.Failing, 3)
38+
eq(t, checks.Passing, 2)
39+
}

api/queries_pr.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type PullRequest struct {
3838
Contexts struct {
3939
Nodes []struct {
4040
State string
41+
Status string
4142
Conclusion string
4243
}
4344
}
@@ -86,16 +87,21 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
8687
}
8788
commit := pr.Commits.Nodes[0].Commit
8889
for _, c := range commit.StatusCheckRollup.Contexts.Nodes {
89-
state := c.State
90+
state := c.State // StatusContext
9091
if state == "" {
91-
state = c.Conclusion
92+
// CheckRun
93+
if c.Status == "COMPLETED" {
94+
state = c.Conclusion
95+
} else {
96+
state = c.Status
97+
}
9298
}
9399
switch state {
94100
case "SUCCESS", "NEUTRAL", "SKIPPED":
95101
summary.Passing++
96102
case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
97103
summary.Failing++
98-
case "EXPECTED", "QUEUED", "PENDING", "IN_PROGRESS":
104+
case "EXPECTED", "REQUESTED", "QUEUED", "PENDING", "IN_PROGRESS":
99105
summary.Pending++
100106
default:
101107
panic(fmt.Errorf("unsupported status: %q", state))
@@ -150,6 +156,7 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st
150156
state
151157
}
152158
...on CheckRun {
159+
status
153160
conclusion
154161
}
155162
}

0 commit comments

Comments
 (0)
X Tutup