Skip to content

Add pr create command#38

Merged
mislav merged 20 commits intomasterfrom
pr-create
Nov 14, 2019
Merged

Add pr create command#38
mislav merged 20 commits intomasterfrom
pr-create

Conversation

@vilmibm
Copy link
Copy Markdown
Contributor

@vilmibm vilmibm commented Oct 30, 2019

WIP, reopening since I ported to new context/client.

Still working to add tests.

Copy link
Copy Markdown
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Just some preliminary notes to hopefully make your life easier 💫

api/queries.go Outdated
}{}
err := client.GraphQL(query, variables, &result)
if err != nil {
return "", fmt.Errorf("failed to determine GH repo ID: %s", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since Go 1.13 we can use errors.Wrap for the pattern of annotating errors with more information: https://godoc.org/github.com/pkg/errors#Wrap

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh hell yeah, thanks

api/queries.go Outdated
if err != nil {
return "", err
}
if repoId == "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will repoId ever be blank after GitHubRepoId succeeded without error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes; if the target struct to unmarshal into is messed up the graphql call will succeed but repoId will just end up as its zero value. It can only happen if the target struct is wrong (which tests should catch) or if the graphql output changes (which shouldn't happen except when we change graphql versions).

It came up during development/testing and led to a confusing state where I was submitting a bad payload to graphql due to the repoId being blank.


query := `
mutation CreatePullRequest($input: CreatePullRequestInput!) {
createPullRequest(input: $input) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good stuff! Following these guides will make it so much more easier for me to implement issue create this week

}

func init() {
prCreateCmd.Flags().BoolVarP(&_draftF, "draft", "d", false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're wary of defining the variables for these flags on the package-level scope (I can see how the commands package will get noisy like this really soon), you can also skip linking the flag to a variable in the first place:

Suggested change
prCreateCmd.Flags().BoolVarP(&_draftF, "draft", "d", false,
prCreateCmd.Flags().BoolP("draft", "d", false, "...")

And then within the command body itself:

isDraft, err := cmd.Flags().GetBool("draft")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

whoa TIL, I think I prefer this. Thanks!

@vilmibm vilmibm added the master label Nov 6, 2019
@mislav mislav changed the title [WIP] pr create Add pr create command Nov 11, 2019
@mislav mislav marked this pull request as ready for review November 11, 2019 16:09
@vilmibm
Copy link
Copy Markdown
Contributor Author

vilmibm commented Nov 12, 2019

Thanks for picking this up <3

Given that we're just all in master this week would you like to keep working on this (adding tests, wrapping errors, and cleaning up flag definitions) or should i?

@vilmibm vilmibm removed the master label Nov 12, 2019
@mislav
Copy link
Copy Markdown
Contributor

mislav commented Nov 13, 2019

@vilmibm Good question! I'm adding some tweaks right now but after I'm done, feel free to take this and run with it if you have time

@vilmibm
Copy link
Copy Markdown
Contributor Author

vilmibm commented Nov 13, 2019

sounds good! lemme know when i should take over.

@mislav
Copy link
Copy Markdown
Contributor

mislav commented Nov 13, 2019

@vilmibm Pushed some tweaks; thank you for your patience

remote, err := guessRemote(ctx)
if err != nil {
return err
return errors.Wrap(err, "could not determine suitable remote")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks to me like guessRemote() already adds the "could not determine suitable remote" error text within its implementation? So we can either avoid adding that here, or avoid adding that within guessRemote

@mislav mislav merged commit 8e7f73d into master Nov 14, 2019
@mislav mislav deleted the pr-create branch November 14, 2019 18:33
@vilmibm
Copy link
Copy Markdown
Contributor Author

vilmibm commented Nov 15, 2019

@mislav do you have thoughts about testing the interactive bits of pr create? we don't need to test that survey works, but it seems like it might be wise to exercise the interactive code path.

vilmibm pushed a commit that referenced this pull request Jun 29, 2021
Redefined browse output, and added in more test cases
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.

2 participants