@@ -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
@@ -80,45 +82,33 @@ type PullRequest struct {
8082 }
8183 }
8284 }
83- ReviewRequests struct {
84- Nodes []struct {
85- RequestedReviewer struct {
86- TypeName string `json:"__typename"`
87- Login string
88- Name string
89- }
90- }
91- TotalCount int
92- }
93- Assignees struct {
94- Nodes []struct {
95- Login string
96- }
97- TotalCount int
98- }
99- Labels struct {
100- Nodes []struct {
101- Name string
102- }
103- TotalCount int
104- }
105- ProjectCards struct {
106- Nodes []struct {
107- Project struct {
108- Name string
109- }
110- Column struct {
111- Name string
112- }
113- }
114- TotalCount int
115- }
116- Milestone struct {
117- Title string
118- }
85+ Assignees Assignees
86+ Labels Labels
87+ ProjectCards ProjectCards
88+ Milestone Milestone
11989 Comments Comments
12090 ReactionGroups ReactionGroups
12191 Reviews PullRequestReviews
92+ ReviewRequests ReviewRequests
93+ }
94+
95+ type ReviewRequests struct {
96+ Nodes []struct {
97+ RequestedReviewer struct {
98+ TypeName string `json:"__typename"`
99+ Login string
100+ Name string
101+ }
102+ }
103+ TotalCount int
104+ }
105+
106+ func (r ReviewRequests ) Logins () []string {
107+ logins := make ([]string , len (r .Nodes ))
108+ for i , a := range r .Nodes {
109+ logins [i ] = a .RequestedReviewer .Login
110+ }
111+ return logins
122112}
123113
124114type NotFoundError struct {
@@ -301,7 +291,10 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
301291 type response struct {
302292 Repository struct {
303293 DefaultBranchRef struct {
304- Name string
294+ Name string
295+ BranchProtectionRule struct {
296+ RequiresStrictStatusChecks bool
297+ }
305298 }
306299 PullRequests edges
307300 PullRequest * PullRequest
@@ -353,6 +346,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
353346 state
354347 url
355348 headRefName
349+ mergeStateStatus
356350 headRepositoryOwner {
357351 login
358352 }
@@ -369,7 +363,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
369363 queryPrefix := `
370364 query PullRequestStatus($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
371365 repository(owner: $owner, name: $repo) {
372- defaultBranchRef { name }
366+ defaultBranchRef {
367+ name
368+ branchProtectionRule {
369+ requiresStrictStatusChecks
370+ }
371+ }
373372 pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) {
374373 totalCount
375374 edges {
@@ -384,7 +383,12 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
384383 queryPrefix = `
385384 query PullRequestStatus($owner: String!, $repo: String!, $number: Int!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) {
386385 repository(owner: $owner, name: $repo) {
387- defaultBranchRef { name }
386+ defaultBranchRef {
387+ name
388+ branchProtectionRule {
389+ requiresStrictStatusChecks
390+ }
391+ }
388392 pullRequest(number: $number) {
389393 ...prWithReviews
390394 }
@@ -471,8 +475,9 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu
471475 PullRequests : reviewRequested ,
472476 TotalCount : resp .ReviewRequested .TotalCount ,
473477 },
474- CurrentPR : currentPR ,
475- DefaultBranch : resp .Repository .DefaultBranchRef .Name ,
478+ CurrentPR : currentPR ,
479+ DefaultBranch : resp .Repository .DefaultBranchRef .Name ,
480+ StrictProtection : resp .Repository .DefaultBranchRef .BranchProtectionRule .RequiresStrictStatusChecks ,
476481 }
477482
478483 return & payload , nil
@@ -814,6 +819,7 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
814819 reviewParams ["teamIds" ] = ids
815820 }
816821
822+ //TODO: How much work to extract this into own method and use for create and edit?
817823 if len (reviewParams ) > 0 {
818824 reviewQuery := `
819825 mutation PullRequestCreateRequestReviews($input: RequestReviewsInput!) {
@@ -833,6 +839,34 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter
833839 return pr , nil
834840}
835841
842+ func UpdatePullRequest (client * Client , repo ghrepo.Interface , params githubv4.UpdatePullRequestInput ) error {
843+ var mutation struct {
844+ UpdatePullRequest struct {
845+ PullRequest struct {
846+ ID string
847+ }
848+ } `graphql:"updatePullRequest(input: $input)"`
849+ }
850+ variables := map [string ]interface {}{"input" : params }
851+ gql := graphQLClient (client .http , repo .RepoHost ())
852+ err := gql .MutateNamed (context .Background (), "PullRequestUpdate" , & mutation , variables )
853+ return err
854+ }
855+
856+ func UpdatePullRequestReviews (client * Client , repo ghrepo.Interface , params githubv4.RequestReviewsInput ) error {
857+ var mutation struct {
858+ RequestReviews struct {
859+ PullRequest struct {
860+ ID string
861+ }
862+ } `graphql:"requestReviews(input: $input)"`
863+ }
864+ variables := map [string ]interface {}{"input" : params }
865+ gql := graphQLClient (client .http , repo .RepoHost ())
866+ err := gql .MutateNamed (context .Background (), "PullRequestUpdateRequestReviews" , & mutation , variables )
867+ return err
868+ }
869+
836870func isBlank (v interface {}) bool {
837871 switch vv := v .(type ) {
838872 case string :
0 commit comments