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
Issue a PR to GH from extension #1
Conversation
cc @felixfbecker teach me things about TS :)) |
tsconfig.json
Outdated
@@ -0,0 +1,14 @@ | |||
{ | |||
"extends": "./node_modules/@sourcegraph/tsconfig/tsconfig.json", |
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.
"extends": "./node_modules/@sourcegraph/tsconfig/tsconfig.json", | |
"extends": "@sourcegraph/tsconfig", |
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 don't think I touched this file (I ran the Sourcegraph script to set up extensions). Unsure, but thanks for catching.
src/pull-request-core.ts
Outdated
baseBranch: string, | ||
commitBranch: string | ||
): Promise<string> { | ||
return new Promise((resolve, reject) => { |
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.
You almost never need the Promise constructor, unless you need to convert some other callback API to Promises. When you do need to use it, you should minimize the code inside it. Here you already have a Promise at hand so you can just return and chain that (or use async/await).
If you were looking for a way to reject the Promise, you just need to throw
inside a handler or async function.
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.
Makes sense. Is throw new Error(...)
a reasonable thing or are there better conventions for error handling?
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.
throw new Error()
is the way to go for errors.
Here ya go :) |
That was really helpful thanks Felix! |
An extension for issuing a GitHub pull request on the client side (given a changeset and commit/PR metadata).
Doing this as a PR because I want feedback on TypeScript things :)
Exposes a top-level function
issuePullRequestWithToken
which kicks off the following sequence:All of the PR logic lives in
pull-request-core.ts
. I pulled this out of the extension due to sourcegraph/sourcegraph#733, so I could set up testing.The extension entry point exposes the main command as
pr.issuePullRequest
.Some simplifying assumptions for now:
See other comments inline.