Skip to content
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

Refactor GitHub client usage for merges #105

Merged
merged 4 commits into from
Mar 26, 2019
Merged

Conversation

bluekeyes
Copy link
Member

Add additional methods to pull.Context (and clean up some of the existing ones) so that bulldozer.MergePR can operate without any direct references to a github.Client. This improves testability (although I don't add any new tests here) and enables a fix for #98 that I'll add in a followup PR.

Fixes #100.

Remove unnecessary context.Context arguments and error returns and add a
function for getting a PR's merge state. This starts to remove a direct
dependence on github.Client from the MergePR() function.
This removes another direct dependency on a *github.Client
Remove the last direct references to github.Client in MergePR. This
theoretically allows testing this function now, although I didn't write
any tests.
Copy link
Member

@asvoboda asvoboda left a comment

Choose a reason for hiding this comment

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

+1 to the additional cleanup, as well.

if err != nil {
logger.Error().Err(errors.WithStack(err)).Msgf("Unable to list open prs against ref %s to compare delete request", ref)
logger.Error().Err(err).Msgf("Unable to determine if ref %s is targeted by other open pull requests before deletion", ref)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Why the change away from errors.WithStack(err)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I assume that pull.Context implementations already wrap errors as needed, so adding a stack again is redundant. It was useful before because the code was mostly dealing with the GitHub client directly.

@@ -67,12 +67,24 @@ func (ghc *GithubContext) Locator() string {
return fmt.Sprintf("%s/%s#%d", ghc.owner, ghc.repo, ghc.number)
}

func (ghc *GithubContext) Title(ctx context.Context) (string, error) {
return ghc.pr.GetTitle(), nil
Copy link
Member

Choose a reason for hiding this comment

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

🥇 Huh. How did this pass in CR previously..

// Delete ref if owner of BASE and HEAD match
// otherwise, its from a fork that we cannot delete
if pr.GetBase().GetUser().GetLogin() == pr.GetHead().GetUser().GetLogin() {
// if head is qualified (contains ":"), PR is from a fork and we don't have delete permission
Copy link
Member

Choose a reason for hiding this comment

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

I think we should address this in a later PR, but if the remote fork has bulldozer installed this assumption is no longer correct. I think it was originally here as a workaround from when this operated using oauth tokens.

We might be able to attempt a delete action, and just fail if it doesn't work. Not blocking, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to support this, I consider it a new feature that requires more refactoring: even if the fork has Bulldozer installed, we need to look up the installation ID and construct a new client using that ID.

I'm also not sure how useful this would be. It seems odd to need Bulldozer for merges on a repository that mostly submits PRs to an upstream repo, so would the only reason to install it be so that it could delete branches?

}

commitMessage = body
commitMessage = pullCtx.Body()
Copy link
Member

Choose a reason for hiding this comment

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

🎉

bulldozer/merge.go Outdated Show resolved Hide resolved
return
default:
logger.Error().Err(errors.WithStack(err)).Msgf("Merge failed unexpectedly %q", gerr.Message)
logger.Error().Msgf("Merge failed with unexpected status: %d: %q", gerr.Response.StatusCode, gerr.Message)
Copy link
Member

Choose a reason for hiding this comment

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

losing the stacktrace on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we already know that the error in this case is an HTTP failure, so the important part is the status code and the message. It's also unambiguous where the error is generated.

@bluekeyes bluekeyes merged commit 60204b4 into develop Mar 26, 2019
@bluekeyes bluekeyes deleted the bkeyes/refactor-merges branch March 26, 2019 18:04
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.

Improve how pull.GithubContext uses PR information
3 participants