Skip to content

Commit 7dbaaf2

Browse files
authored
Merge pull request cli#3804 from cli/pr-status-checks
Fix showing Checks information in `pr status`
2 parents 75abeb1 + a4d1ce7 commit 7dbaaf2

File tree

2 files changed

+13
-55
lines changed

2 files changed

+13
-55
lines changed

api/queries_pr.go

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func PullRequestStatus(client *Client, repo ghrepo.Interface, options StatusOpti
396396
// these are always necessary to find the PR for the current branch
397397
fields.AddValues([]string{"isCrossRepository", "headRepositoryOwner", "headRefName"})
398398
gr := PullRequestGraphQL(fields.ToSlice())
399-
fragments = fmt.Sprintf("fragment pr on PullRequest{%[1]s}fragment prWithReviews on PullRequest{%[1]s}", gr)
399+
fragments = fmt.Sprintf("fragment pr on PullRequest{%s}fragment prWithReviews on PullRequest{...pr}", gr)
400400
} else {
401401
var err error
402402
fragments, err = pullRequestFragment(client.http, repo.RepoHost())
@@ -531,67 +531,23 @@ func pullRequestFragment(httpClient *http.Client, hostname string) (string, erro
531531
return "", err
532532
}
533533

534-
var reviewsFragment string
535-
if prFeatures.HasReviewDecision {
536-
reviewsFragment = "reviewDecision"
534+
fields := []string{
535+
"number", "title", "state", "url", "isDraft", "isCrossRepository",
536+
"requiresStrictStatusChecks", "headRefName", "headRepositoryOwner", "mergeStateStatus",
537537
}
538-
539-
var statusesFragment string
540538
if prFeatures.HasStatusCheckRollup {
541-
statusesFragment = `
542-
commits(last: 1) {
543-
nodes {
544-
commit {
545-
statusCheckRollup {
546-
contexts(last: 100) {
547-
nodes {
548-
...on StatusContext {
549-
state
550-
}
551-
...on CheckRun {
552-
conclusion
553-
status
554-
}
555-
}
556-
}
557-
}
558-
}
559-
}
560-
}
561-
`
539+
fields = append(fields, "statusCheckRollup")
562540
}
563541

564-
var requiresStrictStatusChecks string
565-
if prFeatures.HasBranchProtectionRule {
566-
requiresStrictStatusChecks = `
567-
baseRef {
568-
branchProtectionRule {
569-
requiresStrictStatusChecks
570-
}
571-
}`
542+
var reviewFields []string
543+
if prFeatures.HasReviewDecision {
544+
reviewFields = append(reviewFields, "reviewDecision")
572545
}
573546

574547
fragments := fmt.Sprintf(`
575-
fragment pr on PullRequest {
576-
number
577-
title
578-
state
579-
url
580-
headRefName
581-
mergeStateStatus
582-
headRepositoryOwner {
583-
login
584-
}
585-
%s
586-
isCrossRepository
587-
isDraft
588-
%s
589-
}
590-
fragment prWithReviews on PullRequest {
591-
...pr
592-
%s
593-
}
594-
`, requiresStrictStatusChecks, statusesFragment, reviewsFragment)
548+
fragment pr on PullRequest {%s}
549+
fragment prWithReviews on PullRequest {...pr,%s}
550+
`, PullRequestGraphQL(fields), PullRequestGraphQL(reviewFields))
595551
return fragments, nil
596552
}
597553

api/query_builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ func PullRequestGraphQL(fields []string) string {
216216
q = append(q, `commits(last:1){nodes{commit{oid}}}`)
217217
case "commitsCount": // pseudo-field
218218
q = append(q, `commits{totalCount}`)
219+
case "requiresStrictStatusChecks": // pseudo-field
220+
q = append(q, `baseRef{branchProtectionRule{requiresStrictStatusChecks}}`)
219221
case "statusCheckRollup":
220222
q = append(q, StatusCheckRollupGraphQL(""))
221223
default:

0 commit comments

Comments
 (0)