Skip to content

Commit 4cd43cc

Browse files
committed
Merge remote-tracking branch 'origin' into auth-with-ssh
2 parents 9550ad0 + c2c211d commit 4cd43cc

File tree

25 files changed

+2401
-226
lines changed

25 files changed

+2401
-226
lines changed

api/queries_issue.go

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,76 @@ type IssuesAndTotalCount struct {
2424
}
2525

2626
type Issue struct {
27-
ID string
28-
Number int
29-
Title string
30-
URL string
31-
State string
32-
Closed bool
33-
Body string
34-
CreatedAt time.Time
35-
UpdatedAt time.Time
36-
Comments Comments
37-
Author Author
38-
Assignees struct {
39-
Nodes []struct {
40-
Login string
41-
}
42-
TotalCount int
27+
ID string
28+
Number int
29+
Title string
30+
URL string
31+
State string
32+
Closed bool
33+
Body string
34+
CreatedAt time.Time
35+
UpdatedAt time.Time
36+
Comments Comments
37+
Author Author
38+
Assignees Assignees
39+
Labels Labels
40+
ProjectCards ProjectCards
41+
Milestone Milestone
42+
ReactionGroups ReactionGroups
43+
}
44+
45+
type Assignees struct {
46+
Nodes []struct {
47+
Login string
48+
}
49+
TotalCount int
50+
}
51+
52+
func (a Assignees) Logins() []string {
53+
logins := make([]string, len(a.Nodes))
54+
for i, a := range a.Nodes {
55+
logins[i] = a.Login
56+
}
57+
return logins
58+
}
59+
60+
type Labels struct {
61+
Nodes []struct {
62+
Name string
4363
}
44-
Labels struct {
45-
Nodes []struct {
64+
TotalCount int
65+
}
66+
67+
func (l Labels) Names() []string {
68+
names := make([]string, len(l.Nodes))
69+
for i, l := range l.Nodes {
70+
names[i] = l.Name
71+
}
72+
return names
73+
}
74+
75+
type ProjectCards struct {
76+
Nodes []struct {
77+
Project struct {
4678
Name string
4779
}
48-
TotalCount int
49-
}
50-
ProjectCards struct {
51-
Nodes []struct {
52-
Project struct {
53-
Name string
54-
}
55-
Column struct {
56-
Name string
57-
}
80+
Column struct {
81+
Name string
5882
}
59-
TotalCount int
6083
}
61-
Milestone struct {
62-
Title string
84+
TotalCount int
85+
}
86+
87+
func (p ProjectCards) ProjectNames() []string {
88+
names := make([]string, len(p.Nodes))
89+
for i, c := range p.Nodes {
90+
names[i] = c.Project.Name
6391
}
64-
ReactionGroups ReactionGroups
92+
return names
93+
}
94+
95+
type Milestone struct {
96+
Title string
6597
}
6698

6799
type IssuesDisabledError struct {
@@ -488,6 +520,20 @@ func IssueDelete(client *Client, repo ghrepo.Interface, issue Issue) error {
488520
return err
489521
}
490522

523+
func IssueUpdate(client *Client, repo ghrepo.Interface, params githubv4.UpdateIssueInput) error {
524+
var mutation struct {
525+
UpdateIssue struct {
526+
Issue struct {
527+
ID string
528+
}
529+
} `graphql:"updateIssue(input: $input)"`
530+
}
531+
variables := map[string]interface{}{"input": params}
532+
gql := graphQLClient(client.http, repo.RepoHost())
533+
err := gql.MutateNamed(context.Background(), "IssueUpdate", &mutation, variables)
534+
return err
535+
}
536+
491537
// milestoneNodeIdToDatabaseId extracts the REST Database ID from the GraphQL Node ID
492538
// This conversion is necessary since the GraphQL API requires the use of the milestone's database ID
493539
// for querying the related issues.

api/queries_pr.go

Lines changed: 89 additions & 55 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
@@ -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

124114
type 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+
836870
func isBlank(v interface{}) bool {
837871
switch vv := v.(type) {
838872
case string:

api/queries_repo.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"net/http"
109
"sort"
@@ -497,7 +496,7 @@ func (m *RepoMetadataResult) MilestoneToID(title string) (string, error) {
497496
return m.ID, nil
498497
}
499498
}
500-
return "", errors.New("not found")
499+
return "", fmt.Errorf("'%s' not found", title)
501500
}
502501

503502
func (m *RepoMetadataResult) Merge(m2 *RepoMetadataResult) {

0 commit comments

Comments
 (0)