-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add flags to add additional metadata to issue/pr create
#787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de59f6a
d3a89b8
39c4a5b
a7d0617
6ed50c6
42baf4c
90c8e0e
c6d8a4c
aeb0852
2089b15
b59407d
0bf4f16
d0f168f
72e99e9
7160361
df14492
cedf94f
34fc345
1f774b4
d7e6d21
1128439
8c84d68
4a3588d
c682d90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,7 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter | |
| mutation CreatePullRequest($input: CreatePullRequestInput!) { | ||
| createPullRequest(input: $input) { | ||
| pullRequest { | ||
| id | ||
| url | ||
| } | ||
| } | ||
|
|
@@ -588,7 +589,10 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter | |
| "repositoryId": repo.ID, | ||
| } | ||
| for key, val := range params { | ||
| inputParams[key] = val | ||
| switch key { | ||
| case "title", "body", "draft", "baseRefName", "headRefName": | ||
| inputParams[key] = val | ||
| } | ||
| } | ||
| variables := map[string]interface{}{ | ||
| "input": inputParams, | ||
|
|
@@ -604,8 +608,70 @@ func CreatePullRequest(client *Client, repo *Repository, params map[string]inter | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| pr := &result.CreatePullRequest.PullRequest | ||
|
|
||
| // metadata parameters aren't currently available in `createPullRequest`, | ||
| // but they are in `updatePullRequest` | ||
| updateParams := make(map[string]interface{}) | ||
| for key, val := range params { | ||
| switch key { | ||
| case "assigneeIds", "labelIds", "projectIds", "milestoneId": | ||
| if !isBlank(val) { | ||
| updateParams[key] = val | ||
| } | ||
| } | ||
| } | ||
| if len(updateParams) > 0 { | ||
| updateQuery := ` | ||
| mutation UpdatePullRequest($input: UpdatePullRequestInput!) { | ||
| updatePullRequest(input: $input) { clientMutationId } | ||
| }` | ||
| updateParams["pullRequestId"] = pr.ID | ||
| variables := map[string]interface{}{ | ||
| "input": updateParams, | ||
| } | ||
| err := client.GraphQL(updateQuery, variables, &result) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
|
||
| return &result.CreatePullRequest.PullRequest, nil | ||
| // reviewers are requested in yet another additional mutation | ||
| reviewParams := make(map[string]interface{}) | ||
| if ids, ok := params["userReviewerIds"]; ok && !isBlank(ids) { | ||
| reviewParams["userIds"] = ids | ||
| } | ||
| if ids, ok := params["teamReviewerIds"]; ok && !isBlank(ids) { | ||
| reviewParams["teamIds"] = ids | ||
| } | ||
|
|
||
| if len(reviewParams) > 0 { | ||
| reviewQuery := ` | ||
| mutation RequestReviews($input: RequestReviewsInput!) { | ||
| requestReviews(input: $input) { clientMutationId } | ||
| }` | ||
| reviewParams["pullRequestId"] = pr.ID | ||
| variables := map[string]interface{}{ | ||
| "input": reviewParams, | ||
| } | ||
| err := client.GraphQL(reviewQuery, variables, &result) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it looks like the reviewQuery and the updateQuery are not dependent on each other, I was wondering if we could combine the queries and variables and just make one call to the server?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting suggestion! That should definitely be possible, even though we don't have a clean mechanism of merging GraphQL queries just yet. I will look into whether this is feasible |
||
|
|
||
| return pr, nil | ||
| } | ||
|
|
||
| func isBlank(v interface{}) bool { | ||
| switch vv := v.(type) { | ||
| case string: | ||
| return vv == "" | ||
| case []string: | ||
| return len(vv) == 0 | ||
| default: | ||
| return true | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very handy! |
||
| } | ||
|
|
||
| func AddReview(client *Client, pr *PullRequest, input *PullRequestReviewInput) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not used to golang's "while" loops