@@ -16,10 +16,11 @@ import (
1616)
1717
1818type 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
2526type PullRequestAndTotalCount struct {
@@ -28,16 +29,17 @@ type PullRequestAndTotalCount struct {
2829}
2930
3031type 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
@@ -138,14 +140,6 @@ type PullRequestReviewStatus struct {
138140 ReviewRequired bool
139141}
140142
141- type PullRequestMergeMethod int
142-
143- const (
144- PullRequestMergeMethodMerge PullRequestMergeMethod = iota
145- PullRequestMergeMethodRebase
146- PullRequestMergeMethodSquash
147- )
148-
149143func (pr * PullRequest ) ReviewStatus () PullRequestReviewStatus {
150144 var status PullRequestReviewStatus
151145 switch pr .ReviewDecision {
@@ -289,7 +283,10 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
289283 type response struct {
290284 Repository struct {
291285 DefaultBranchRef struct {
292- Name string
286+ Name string
287+ BranchProtectionRule struct {
288+ RequiresStrictStatusChecks bool
289+ }
293290 }
294291 PullRequests edges
295292 PullRequest * PullRequest
@@ -341,6 +338,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
341338 state
342339 url
343340 headRefName
341+ mergeStateStatus
344342 headRepositoryOwner {
345343 login
346344 }
@@ -357,7 +355,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
357355 queryPrefix := `
358356 query PullRequestStatus($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
359357 repository(owner: $owner, name: $repo) {
360- defaultBranchRef { name }
358+ defaultBranchRef {
359+ name
360+ branchProtectionRule {
361+ requiresStrictStatusChecks
362+ }
363+ }
361364 pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) {
362365 totalCount
363366 edges {
@@ -372,7 +375,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
372375 queryPrefix = `
373376 query PullRequestStatus($owner: String!, $repo: String!, $number: Int!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
374377 repository(owner: $owner, name: $repo) {
375- defaultBranchRef { name }
378+ defaultBranchRef {
379+ name
380+ branchProtectionRule {
381+ requiresStrictStatusChecks
382+ }
383+ }
376384 pullRequest(number: $number) {
377385 ...prWithReviews
378386 }
@@ -459,8 +467,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
459467 PullRequests : reviewRequested ,
460468 TotalCount : resp .ReviewRequested .TotalCount ,
461469 },
462- CurrentPR : currentPR ,
463- DefaultBranch : resp .Repository .DefaultBranchRef .Name ,
470+ CurrentPR : currentPR ,
471+ DefaultBranch : resp .Repository .DefaultBranchRef .Name ,
472+ StrictProtection : resp .Repository .DefaultBranchRef .BranchProtectionRule .RequiresStrictStatusChecks ,
464473 }
465474
466475 return & payload , nil
@@ -1071,47 +1080,6 @@ func PullRequestReopen(client *Client, repo ghrepo.Interface, pr *PullRequest) e
10711080 return err
10721081}
10731082
1074- func PullRequestMerge (client * Client , repo ghrepo.Interface , pr * PullRequest , m PullRequestMergeMethod , body * string ) error {
1075- mergeMethod := githubv4 .PullRequestMergeMethodMerge
1076- switch m {
1077- case PullRequestMergeMethodRebase :
1078- mergeMethod = githubv4 .PullRequestMergeMethodRebase
1079- case PullRequestMergeMethodSquash :
1080- mergeMethod = githubv4 .PullRequestMergeMethodSquash
1081- }
1082-
1083- var mutation struct {
1084- MergePullRequest struct {
1085- PullRequest struct {
1086- ID githubv4.ID
1087- }
1088- } `graphql:"mergePullRequest(input: $input)"`
1089- }
1090-
1091- input := githubv4.MergePullRequestInput {
1092- PullRequestID : pr .ID ,
1093- MergeMethod : & mergeMethod ,
1094- }
1095-
1096- if m == PullRequestMergeMethodSquash {
1097- commitHeadline := githubv4 .String (fmt .Sprintf ("%s (#%d)" , pr .Title , pr .Number ))
1098- input .CommitHeadline = & commitHeadline
1099- }
1100- if body != nil {
1101- commitBody := githubv4 .String (* body )
1102- input .CommitBody = & commitBody
1103- }
1104-
1105- variables := map [string ]interface {}{
1106- "input" : input ,
1107- }
1108-
1109- gql := graphQLClient (client .http , repo .RepoHost ())
1110- err := gql .MutateNamed (context .Background (), "PullRequestMerge" , & mutation , variables )
1111-
1112- return err
1113- }
1114-
11151083func PullRequestReady (client * Client , repo ghrepo.Interface , pr * PullRequest ) error {
11161084 var mutation struct {
11171085 MarkPullRequestReadyForReview struct {
0 commit comments