adds strict status checks
This commit is contained in:
parent
8511365afb
commit
9be9229a48
2 changed files with 37 additions and 19 deletions
|
|
@ -16,10 +16,11 @@ import (
|
|||
)
|
||||
|
||||
type PullRequestsPayload struct {
|
||||
ViewerCreated PullRequestAndTotalCount
|
||||
ReviewRequested PullRequestAndTotalCount
|
||||
CurrentPR *PullRequest
|
||||
DefaultBranch string
|
||||
ViewerCreated PullRequestAndTotalCount
|
||||
ReviewRequested PullRequestAndTotalCount
|
||||
CurrentPR *PullRequest
|
||||
DefaultBranch string
|
||||
StrictProtection bool
|
||||
}
|
||||
|
||||
type PullRequestAndTotalCount struct {
|
||||
|
|
@ -302,7 +303,10 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
type response struct {
|
||||
Repository struct {
|
||||
DefaultBranchRef struct {
|
||||
Name string
|
||||
Name string
|
||||
BranchProtectionRule struct {
|
||||
RequiresStrictStatusChecks bool
|
||||
}
|
||||
}
|
||||
PullRequests edges
|
||||
PullRequest *PullRequest
|
||||
|
|
@ -371,7 +375,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
queryPrefix := `
|
||||
query PullRequestStatus($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
defaultBranchRef { name }
|
||||
defaultBranchRef {
|
||||
name
|
||||
branchProtectionRule {
|
||||
requiresStrictStatusChecks
|
||||
}
|
||||
}
|
||||
pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) {
|
||||
totalCount
|
||||
edges {
|
||||
|
|
@ -386,7 +395,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
queryPrefix = `
|
||||
query PullRequestStatus($owner: String!, $repo: String!, $number: Int!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
|
||||
repository(owner: $owner, name: $repo) {
|
||||
defaultBranchRef { name }
|
||||
defaultBranchRef {
|
||||
name
|
||||
branchProtectionRule {
|
||||
requiresStrictStatusChecks
|
||||
}
|
||||
}
|
||||
pullRequest(number: $number) {
|
||||
...prWithReviews
|
||||
}
|
||||
|
|
@ -473,8 +487,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
|
|||
PullRequests: reviewRequested,
|
||||
TotalCount: resp.ReviewRequested.TotalCount,
|
||||
},
|
||||
CurrentPR: currentPR,
|
||||
DefaultBranch: resp.Repository.DefaultBranchRef.Name,
|
||||
CurrentPR: currentPR,
|
||||
DefaultBranch: resp.Repository.DefaultBranchRef.Name,
|
||||
StrictProtection: resp.Repository.DefaultBranchRef.BranchProtectionRule.RequiresStrictStatusChecks,
|
||||
}
|
||||
|
||||
return &payload, nil
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func statusRun(opts *StatusOptions) error {
|
|||
currentPR = nil
|
||||
}
|
||||
if currentPR != nil {
|
||||
printPrs(opts.IO, 1, *currentPR)
|
||||
printPrs(opts.IO, 1, prPayload.StrictProtection, *currentPR)
|
||||
} else if currentPRHeadRef == "" {
|
||||
shared.PrintMessage(opts.IO, " There is no current branch")
|
||||
} else {
|
||||
|
|
@ -124,7 +124,7 @@ func statusRun(opts *StatusOptions) error {
|
|||
|
||||
shared.PrintHeader(opts.IO, "Created by you")
|
||||
if prPayload.ViewerCreated.TotalCount > 0 {
|
||||
printPrs(opts.IO, prPayload.ViewerCreated.TotalCount, prPayload.ViewerCreated.PullRequests...)
|
||||
printPrs(opts.IO, prPayload.ViewerCreated.TotalCount, prPayload.StrictProtection, prPayload.ViewerCreated.PullRequests...)
|
||||
} else {
|
||||
shared.PrintMessage(opts.IO, " You have no open pull requests")
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ func statusRun(opts *StatusOptions) error {
|
|||
|
||||
shared.PrintHeader(opts.IO, "Requesting a code review from you")
|
||||
if prPayload.ReviewRequested.TotalCount > 0 {
|
||||
printPrs(opts.IO, prPayload.ReviewRequested.TotalCount, prPayload.ReviewRequested.PullRequests...)
|
||||
printPrs(opts.IO, prPayload.ReviewRequested.TotalCount, prPayload.StrictProtection, prPayload.ReviewRequested.PullRequests...)
|
||||
} else {
|
||||
shared.PrintMessage(opts.IO, " You have no pull requests to review")
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ func prSelectorForCurrentBranch(baseRepo ghrepo.Interface, prHeadRef string, rem
|
|||
return
|
||||
}
|
||||
|
||||
func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
|
||||
func printPrs(io *iostreams.IOStreams, totalCount int, strictProtection bool, prs ...api.PullRequest) {
|
||||
w := io.Out
|
||||
cs := io.ColorScheme()
|
||||
|
||||
|
|
@ -228,13 +228,16 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
|
|||
fmt.Fprint(w, cs.Green("✓ Approved"))
|
||||
}
|
||||
|
||||
// add padding between reviews & merge status
|
||||
fmt.Fprint(w, " ")
|
||||
// only check if the "up to date" setting is checked in repo settings
|
||||
if strictProtection {
|
||||
// add padding between reviews & merge status
|
||||
fmt.Fprint(w, " ")
|
||||
|
||||
if pr.MergeStateStatus == "BEHIND" {
|
||||
fmt.Fprint(w, cs.Yellow("- Not up to date"))
|
||||
} else {
|
||||
fmt.Fprint(w, cs.Green("✓ Up to date"))
|
||||
if pr.MergeStateStatus == "BEHIND" {
|
||||
fmt.Fprint(w, cs.Yellow("- Not up to date"))
|
||||
} else {
|
||||
fmt.Fprint(w, cs.Green("✓ Up to date"))
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue