When applying metadata to the new PR such as assignees or reviewers, if
the operation fails, an error message would get printed:
failed to create pull request: <API error text>
This was misleading, because the PR did get created; it's just that
updating it failed. The new error message is:
https://github.com/OWNER/REPO/pull/123
pull request update failed: <API error text>
The PR URL is printed on stdout and the error message is printed on
stderr. In case of any errors, the exit code is still non-zero.
Ensure the response body is fully read and closed to reuse the same TCPconnection.
Co-authored-by: Kumar Saurabh <kumarsaurabh@Kumars-MacBook-Air.local>
Any errors from fetching and rendering the README were silenced and
ignored in `repo view`. This change:
- Tolerates HTTP 404, but will raise exceptions for any other error;
- Moves markdown rendering from `api` package to command implementation;
- Ensures markdown rendering errors are correctly reported.
First, consolidate the functionality between `pr merge` and `pr
checkout` that resolves the default branch name of the base repo. With
an added bonus, the new approach avoids an API request when one isn't
necessary.
Then, ensure that checking out 3rd-party PRs will result in local branch
name such as `<owner>/<branch>` when the head branch of the repository
matches the default branch of the base repository. We already have had
code in place to take care of this, but it only took effect in the `pr
checkout <number>`-style invocation.
`admin:org` is inclusive of `read:org`, so if we find the former listed
in response headers, we can conclude that the token has necessary scopes
instead of letting a warning notice be shown.
If a GitHub repo is configured to automatically delete branches after PR
is merged, `gh pr merge` fails with error like:
failed to delete remote branch: ... (422): 'Reference does not exist'
Gracefully handle such case and don't report the error.
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
`fmt.Errorf` hides information and makes it hard to test for specific
conditions in returned error. Return a structured error instead.
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>