Skip to content

Add Draft PR support#1173

Merged
kuychaco merged 32 commits intomasterfrom
kuychaco/draft-prs
Jun 5, 2019
Merged

Add Draft PR support#1173
kuychaco merged 32 commits intomasterfrom
kuychaco/draft-prs

Conversation

@kuychaco
Copy link
Contributor

@kuychaco kuychaco commented May 23, 2019

On dotcom users can create draft pull requests to indicate that their PR is a work in progress and not yet ready for review.

With this PR, users may submit draft pull requests using the GitHub Pull Requests: Create Draft Pull Request command. When viewing the description of a draft PR in the editor, a Draft badge is displayed in the header.

This PR also includes upgrades of @octokit/rest and typescript. In order to use the Draft Pull Request rest API we needed to upgrade octokit, which required a typescript upgrade.

Fixes #1129
Fixes #1190

TODO:

  • Upgrade octokit and typescript
  • Create draft PR using GitHub Pull Requests: Create Draft Pull Request
  • Add Draft badge to PR description header
  • Indicate if PR is draft in PR list
  • "Ready for Review", disable "Merge pull request" button
  • Handle Unprocessable Entity error when clicking "Approve" and "Request changes" buttons while in draft mode
  • Style
  • Add telemetry
  • Tests

kuychaco and others added 7 commits May 22, 2019 15:40
Co-authored-by: Ashi Krishnan <ashi@queerlyamorous.org>
Co-authored-by: Ashi Krishnan <ashi@queerlyamorous.org>
Co-authored-by: Ashi Krishnan <ashi@queerlyamorous.org>
Co-authored-by: Ashi Krishnan <ashi@queerlyamorous.org>clear
@msftclas
Copy link

msftclas commented May 23, 2019

CLA assistant check
All CLA requirements met.

@kuychaco kuychaco marked this pull request as ready for review May 24, 2019 01:01
@kuychaco kuychaco requested a review from queerviolet May 24, 2019 01:01
@kuychaco
Copy link
Contributor Author

Current UI/UX below...

Feedback is welcome!

_Extension_Development_Host__-_thing_txt_—_test-repo

_Extension_Development_Host__-_Pull_Request__16_—_test-repo

draft-pr

Copy link
Contributor

@queerviolet queerviolet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have some UI for making the draft not a draft ("Ready for Review" on dotcom).

Also, when I try to Approve or Request Changes, it fails with Unprocessable Entity. Are those things we can do to Draft PRs? If not, we should remove the buttons.

@queerviolet
Copy link
Contributor

One UX thing and a small code nit, otherwise LG!

@kuychaco
Copy link
Contributor Author

Also, when I try to Approve or Request Changes, it fails with Unprocessable Entity. Are those things we can do to Draft PRs? If not, we should remove the buttons.

Looks like this is due to the fact that a PR author is trying to approve/request changes on their own PR. Which is not allowed. I checked master and this is a pre-existing bug. So let's call this out-of-scope and tackle it separately

kuychaco added 3 commits May 30, 2019 18:05
Due to lack of graphql support
Strangely the extension was working even without it listed explicitly. It was listed in the yarn.lock, and I guess that was getting us by...

In any case, we started seeing this error with the stack trace pointing to lodash:
```
```Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'nonce-i53qcjvFaMb4cikgwqc758pL4aWAtfGk'".```
```
@kuychaco kuychaco requested a review from queerviolet May 31, 2019 02:45
Copy link
Contributor

@smashwilson smashwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random drive-by diff comments 👀

"graphql": "^14.0.2",
"iconv-lite": "0.4.23",
"js-base64": "^2.4.9",
"lodash": "^4.17.11",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually depending on lodash.isequal in #1169. I'll have to consolidate after this is merged so it isn't redundant 🙈

<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'unsafe-eval' 'nonce-${nonce}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh I bet this is the change that caused that EvalError you were seeing yesterday ☝️

It's a very good change to make, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh yup, and totally!

Copy link
Contributor

@RMacfarlane RMacfarlane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool!

"command": "pr.merge",
"when": "config.git.enabled && github:inReviewMode"
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also scope pr.createDraft to be when you're not in review mode. Looks like something funky is happening with pr.create and that context key right now, the bang operator should work but I still see the command when checked out. Changing the syntax to github:inReviewMode == 'false' fixes it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know about that funkiness! Made the fix 👍

agent,
baseUrl,
headers: { 'user-agent': 'GitHub VSCode Pull Requests' }
headers: { 'user-agent': 'GitHub VSCode Pull Requests', Accept: 'application/vnd.github.shadow-cat-preview+json' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, why is this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! It's required for access to the Draft PR API while it's in preview -- https://developer.github.com/v3/previews/#draft-pull-requests

I'll add a comment to the code to increase clarity 👍

}

export interface PullRequest {
id?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a required property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would certainly be ideal! However, as long as we fall back to using REST, this field must be optional. id refers specifically to the graphql object id and is required for making mutations (such as updating draft status).

And unfortunately the REST API doesn't currently support updating the draft status of PRs (and the GitHub pull requests team doesn't seem to have plans to add support). So for now users simply cannot convert from draft status to ready-for-review unless graphql is supported https://github.com/microsoft/vscode-pull-request-github/pull/1173/files#diff-4c377281588b3e01e164412d5a23724aR1229)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we dealt with this in some way—making this id either the GraphQL node id, or the database ID as returned by the REST API. @RMacfarlane do you recall?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(IMO this isn't a blocker, as going from an optional field to a required field is always non-breaking.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah! On comments we have an id property and a graphNodeId property. id is the database id, graphNodeId is the GraphQL node id. Both are always present, the REST API had a node_id property that we used to fill in the graphNodeId. I think we still have some mixed usage of REST and GraphQL when dealing with comments, even when GraphQL is supported

},
"dependencies": {
"@octokit/rest": "^15.15.1",
"@octokit/rest": "^16.21.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for updating this!

kuychaco and others added 5 commits June 3, 2019 16:09
The bang operator doesn't seem to be working as expected,  hence using the more verbose `github:inReviewMode == 'false'` syntax

Co-authored-by: Rachel Macfarlane <ramacfar@microsoft.com>
Co-authored-by: Rachel Macfarlane <ramacfar@microsoft.com>
Co-authored-by: Rachel Macfarlane <ramacfar@microsoft.com>
Co-authored-by: Rachel Macfarlane <ramacfar@microsoft.com>
Co-authored-by: Rachel Macfarlane <ramacfar@microsoft.com>
kuychaco added 2 commits June 4, 2019 16:17
Looks like there's a bug in VS Code. Currently the pr.create and pr.createDraft commands always show up regardless of review mode. I'll go ahead and ship and hope that the bug gets fixed soon.

    Version: 1.35.0-insider
    Commit: 2737cde4facc8411982862742f5c6cd3dabef323
    Date: 2019-05-31T05:16:11.646Z
    Electron: 3.1.8
    Chrome: 66.0.3359.181
    Node.js: 10.2.0
    V8: 6.6.346.32
    OS: Darwin x64 17.7.0
@kuychaco kuychaco force-pushed the kuychaco/draft-prs branch from ca80c6f to 14b067e Compare June 4, 2019 23:18
@kuychaco kuychaco merged commit df2a052 into master Jun 5, 2019
@kuychaco kuychaco deleted the kuychaco/draft-prs branch June 5, 2019 00:05
@smashwilson smashwilson mentioned this pull request Jun 5, 2019
11 tasks
@alif1993
Copy link

That's weird that I cannot find create draft pull request command!!!!
Any clue??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add telemetry for creating PRs Add Draft PR support

6 participants