X Tutup
Skip to content

Commit 9be9229

Browse files
committed
adds strict status checks
1 parent 8511365 commit 9be9229

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

api/queries_pr.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616
)
1717

1818
type PullRequestsPayload struct {
19-
ViewerCreated PullRequestAndTotalCount
20-
ReviewRequested PullRequestAndTotalCount
21-
CurrentPR *PullRequest
22-
DefaultBranch string
19+
ViewerCreated PullRequestAndTotalCount
20+
ReviewRequested PullRequestAndTotalCount
21+
CurrentPR *PullRequest
22+
DefaultBranch string
23+
StrictProtection bool
2324
}
2425

2526
type PullRequestAndTotalCount struct {
@@ -302,7 +303,10 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
302303
type response struct {
303304
Repository struct {
304305
DefaultBranchRef struct {
305-
Name string
306+
Name string
307+
BranchProtectionRule struct {
308+
RequiresStrictStatusChecks bool
309+
}
306310
}
307311
PullRequests edges
308312
PullRequest *PullRequest
@@ -371,7 +375,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
371375
queryPrefix := `
372376
query PullRequestStatus($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
373377
repository(owner: $owner, name: $repo) {
374-
defaultBranchRef { name }
378+
defaultBranchRef {
379+
name
380+
branchProtectionRule {
381+
requiresStrictStatusChecks
382+
}
383+
}
375384
pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) {
376385
totalCount
377386
edges {
@@ -386,7 +395,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
386395
queryPrefix = `
387396
query PullRequestStatus($owner: String!, $repo: String!, $number: Int!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
388397
repository(owner: $owner, name: $repo) {
389-
defaultBranchRef { name }
398+
defaultBranchRef {
399+
name
400+
branchProtectionRule {
401+
requiresStrictStatusChecks
402+
}
403+
}
390404
pullRequest(number: $number) {
391405
...prWithReviews
392406
}
@@ -473,8 +487,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
473487
PullRequests: reviewRequested,
474488
TotalCount: resp.ReviewRequested.TotalCount,
475489
},
476-
CurrentPR: currentPR,
477-
DefaultBranch: resp.Repository.DefaultBranchRef.Name,
490+
CurrentPR: currentPR,
491+
DefaultBranch: resp.Repository.DefaultBranchRef.Name,
492+
StrictProtection: resp.Repository.DefaultBranchRef.BranchProtectionRule.RequiresStrictStatusChecks,
478493
}
479494

480495
return &payload, nil

pkg/cmd/pr/status/status.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func statusRun(opts *StatusOptions) error {
114114
currentPR = nil
115115
}
116116
if currentPR != nil {
117-
printPrs(opts.IO, 1, *currentPR)
117+
printPrs(opts.IO, 1, prPayload.StrictProtection, *currentPR)
118118
} else if currentPRHeadRef == "" {
119119
shared.PrintMessage(opts.IO, " There is no current branch")
120120
} else {
@@ -124,15 +124,15 @@ func statusRun(opts *StatusOptions) error {
124124

125125
shared.PrintHeader(opts.IO, "Created by you")
126126
if prPayload.ViewerCreated.TotalCount > 0 {
127-
printPrs(opts.IO, prPayload.ViewerCreated.TotalCount, prPayload.ViewerCreated.PullRequests...)
127+
printPrs(opts.IO, prPayload.ViewerCreated.TotalCount, prPayload.StrictProtection, prPayload.ViewerCreated.PullRequests...)
128128
} else {
129129
shared.PrintMessage(opts.IO, " You have no open pull requests")
130130
}
131131
fmt.Fprintln(out)
132132

133133
shared.PrintHeader(opts.IO, "Requesting a code review from you")
134134
if prPayload.ReviewRequested.TotalCount > 0 {
135-
printPrs(opts.IO, prPayload.ReviewRequested.TotalCount, prPayload.ReviewRequested.PullRequests...)
135+
printPrs(opts.IO, prPayload.ReviewRequested.TotalCount, prPayload.StrictProtection, prPayload.ReviewRequested.PullRequests...)
136136
} else {
137137
shared.PrintMessage(opts.IO, " You have no pull requests to review")
138138
}
@@ -178,7 +178,7 @@ func prSelectorForCurrentBranch(baseRepo ghrepo.Interface, prHeadRef string, rem
178178
return
179179
}
180180

181-
func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
181+
func printPrs(io *iostreams.IOStreams, totalCount int, strictProtection bool, prs ...api.PullRequest) {
182182
w := io.Out
183183
cs := io.ColorScheme()
184184

@@ -228,13 +228,16 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
228228
fmt.Fprint(w, cs.Green("✓ Approved"))
229229
}
230230

231-
// add padding between reviews & merge status
232-
fmt.Fprint(w, " ")
231+
// only check if the "up to date" setting is checked in repo settings
232+
if strictProtection {
233+
// add padding between reviews & merge status
234+
fmt.Fprint(w, " ")
233235

234-
if pr.MergeStateStatus == "BEHIND" {
235-
fmt.Fprint(w, cs.Yellow("- Not up to date"))
236-
} else {
237-
fmt.Fprint(w, cs.Green("✓ Up to date"))
236+
if pr.MergeStateStatus == "BEHIND" {
237+
fmt.Fprint(w, cs.Yellow("- Not up to date"))
238+
} else {
239+
fmt.Fprint(w, cs.Green("✓ Up to date"))
240+
}
238241
}
239242

240243
} else {

0 commit comments

Comments
 (0)
X Tutup