X Tutup
Skip to content

Commit ebc5d01

Browse files
committed
Merge remote-tracking branch 'origin' into auto-merge
2 parents 203397b + c2c211d commit ebc5d01

File tree

3 files changed

+55
-23
lines changed

3 files changed

+55
-23
lines changed

api/queries_pr.go

Lines changed: 36 additions & 19 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 {
@@ -28,16 +29,17 @@ type PullRequestAndTotalCount struct {
2829
}
2930

3031
type PullRequest struct {
31-
ID string
32-
Number int
33-
Title string
34-
State string
35-
Closed bool
36-
URL string
37-
BaseRefName string
38-
HeadRefName string
39-
Body string
40-
Mergeable string
32+
ID string
33+
Number int
34+
Title string
35+
State string
36+
Closed bool
37+
URL string
38+
BaseRefName string
39+
HeadRefName string
40+
Body string
41+
Mergeable string
42+
MergeStateStatus string
4143

4244
Author struct {
4345
Login string
@@ -281,7 +283,10 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
281283
type response struct {
282284
Repository struct {
283285
DefaultBranchRef struct {
284-
Name string
286+
Name string
287+
BranchProtectionRule struct {
288+
RequiresStrictStatusChecks bool
289+
}
285290
}
286291
PullRequests edges
287292
PullRequest *PullRequest
@@ -333,6 +338,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
333338
state
334339
url
335340
headRefName
341+
mergeStateStatus
336342
headRepositoryOwner {
337343
login
338344
}
@@ -349,7 +355,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
349355
queryPrefix := `
350356
query PullRequestStatus($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
351357
repository(owner: $owner, name: $repo) {
352-
defaultBranchRef { name }
358+
defaultBranchRef {
359+
name
360+
branchProtectionRule {
361+
requiresStrictStatusChecks
362+
}
363+
}
353364
pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) {
354365
totalCount
355366
edges {
@@ -364,7 +375,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
364375
queryPrefix = `
365376
query PullRequestStatus($owner: String!, $repo: String!, $number: Int!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
366377
repository(owner: $owner, name: $repo) {
367-
defaultBranchRef { name }
378+
defaultBranchRef {
379+
name
380+
branchProtectionRule {
381+
requiresStrictStatusChecks
382+
}
383+
}
368384
pullRequest(number: $number) {
369385
...prWithReviews
370386
}
@@ -451,8 +467,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
451467
PullRequests: reviewRequested,
452468
TotalCount: resp.ReviewRequested.TotalCount,
453469
},
454-
CurrentPR: currentPR,
455-
DefaultBranch: resp.Repository.DefaultBranchRef.Name,
470+
CurrentPR: currentPR,
471+
DefaultBranch: resp.Repository.DefaultBranchRef.Name,
472+
StrictProtection: resp.Repository.DefaultBranchRef.BranchProtectionRule.RequiresStrictStatusChecks,
456473
}
457474

458475
return &payload, nil

pkg/cmd/factory/http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ func NewHTTPClient(io *iostreams.IOStreams, cfg config.Config, appVersion string
8787
api.AddHeaderFunc("Accept", func(req *http.Request) (string, error) {
8888
// antiope-preview: Checks
8989
accept := "application/vnd.github.antiope-preview+json"
90+
// introduced for #2952: pr branch up to date status
91+
accept += ", application/vnd.github.merge-info-preview+json"
9092
if ghinstance.IsEnterprise(req.URL.Hostname()) {
9193
// shadow-cat-preview: Draft pull requests
9294
accept += ", application/vnd.github.shadow-cat-preview"

pkg/cmd/pr/status/status.go

Lines changed: 17 additions & 4 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

@@ -227,6 +227,19 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
227227
} else if reviews.Approved {
228228
fmt.Fprint(w, cs.Green("✓ Approved"))
229229
}
230+
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, " ")
235+
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+
}
241+
}
242+
230243
} else {
231244
fmt.Fprintf(w, " - %s", shared.StateTitleWithColor(cs, pr))
232245
}

0 commit comments

Comments
 (0)
X Tutup