Use statusCheckRollup internal GraphQL to simplify Statuses+Checks
With the old approach, we had to enumerate all StatusContexts and
CheckRuns to calculate whether a PR has passing or failing CI status.
Using `statusCheckRollup` which is behind the `pe_mobile` feature flag,
this is somewhat simpler because both StatusContexts and CheckRuns are
now behind the same connection.
Additionally, should we decide to *not* show the number of
passing/failing checks, this now approach allows us to consume the
`statusCheckRollup { state }` field and avoid paginated collections
and calculating the "winning" state altogether.
This commit is contained in:
parent
624c44efda
commit
04f20ddb2b
2 changed files with 23 additions and 39 deletions
|
|
@ -35,17 +35,11 @@ type PullRequest struct {
|
|||
Commits struct {
|
||||
Nodes []struct {
|
||||
Commit struct {
|
||||
Status struct {
|
||||
Contexts []struct {
|
||||
State string
|
||||
}
|
||||
}
|
||||
CheckSuites struct {
|
||||
Nodes []struct {
|
||||
CheckRuns struct {
|
||||
Nodes []struct {
|
||||
Conclusion string
|
||||
}
|
||||
StatusCheckRollup struct {
|
||||
Contexts struct {
|
||||
Nodes []struct {
|
||||
State string
|
||||
Conclusion string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -97,32 +91,23 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) {
|
|||
return
|
||||
}
|
||||
commit := pr.Commits.Nodes[0].Commit
|
||||
for _, status := range commit.Status.Contexts {
|
||||
switch status.State {
|
||||
case "SUCCESS":
|
||||
for _, c := range commit.StatusCheckRollup.Contexts.Nodes {
|
||||
state := c.State
|
||||
if state == "" {
|
||||
state = c.Conclusion
|
||||
}
|
||||
switch state {
|
||||
case "SUCCESS", "NEUTRAL", "SKIPPED":
|
||||
summary.Passing++
|
||||
case "EXPECTED", "ERROR", "FAILURE":
|
||||
case "ERROR", "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
|
||||
summary.Failing++
|
||||
case "PENDING":
|
||||
case "EXPECTED", "QUEUED", "PENDING", "IN_PROGRESS":
|
||||
summary.Pending++
|
||||
default:
|
||||
panic(fmt.Errorf("unsupported status: %q", status.State))
|
||||
panic(fmt.Errorf("unsupported status: %q", state))
|
||||
}
|
||||
summary.Total++
|
||||
}
|
||||
for _, checkSuite := range commit.CheckSuites.Nodes {
|
||||
for _, checkRun := range checkSuite.CheckRuns.Nodes {
|
||||
switch checkRun.Conclusion {
|
||||
case "SUCCESS", "NEUTRAL":
|
||||
summary.Passing++
|
||||
case "FAILURE", "CANCELLED", "TIMED_OUT", "ACTION_REQUIRED":
|
||||
summary.Failing++
|
||||
default:
|
||||
panic(fmt.Errorf("unsupported check conclusion: %q", checkRun.Conclusion))
|
||||
}
|
||||
summary.Total++
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -267,15 +252,13 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st
|
|||
commits(last: 1) {
|
||||
nodes {
|
||||
commit {
|
||||
status {
|
||||
contexts {
|
||||
state
|
||||
}
|
||||
}
|
||||
checkSuites(first: 50) {
|
||||
nodes {
|
||||
checkRuns(first: 50) {
|
||||
nodes {
|
||||
statusCheckRollup {
|
||||
contexts(last: 100) {
|
||||
nodes {
|
||||
...on StatusContext {
|
||||
state
|
||||
}
|
||||
...on CheckRun {
|
||||
conclusion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ var apiClientForContext = func(ctx context.Context) (*api.Client, error) {
|
|||
// antiope-preview: Checks
|
||||
// shadow-cat-preview: Draft pull requests
|
||||
api.AddHeader("Accept", "application/vnd.github.antiope-preview+json, application/vnd.github.shadow-cat-preview"),
|
||||
api.AddHeader("GraphQL-Features", "pe_mobile"),
|
||||
}
|
||||
if verbose := os.Getenv("DEBUG"); verbose != "" {
|
||||
opts = append(opts, api.VerboseLog(os.Stderr))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue