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

Allow to specify github pullrequest merge method #514

Merged
merged 5 commits into from
Feb 15, 2022

Conversation

olblak
Copy link
Member

@olblak olblak commented Feb 6, 2022

Signed-off-by: Olblak me@olblak.com

Allow to specify github pullrequest merge method

Fix #492

Allow to specify a pullrequest merge method by using the key mergemethod set to ["","squash", "merge","rebase"]

Test

To test this pull request, you can run the following commands:

go build -o bin/updatecli
# Then test using an updatecli manifest that tries to open a pullrequest 

Additional Information

Tradeoff

Potential improvement

@olblak olblak added this to the 0.20.0 milestone Feb 6, 2022
@olblak olblak marked this pull request as draft February 6, 2022 16:11
@olblak olblak removed this from the 0.20.0 milestone Feb 7, 2022
dduportal
dduportal previously approved these changes Feb 9, 2022
Copy link
Contributor

@dduportal dduportal left a comment

Choose a reason for hiding this comment

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

go for it I guess ? :)

@olblak
Copy link
Member Author

olblak commented Feb 9, 2022

I still needs additional testing 😁

@olblak
Copy link
Member Author

olblak commented Feb 14, 2022

It's now ready to be merged. The last commit fix the issue identified during testing

olblak and others added 5 commits February 14, 2022 21:57
Signed-off-by: Olblak <me@olblak.com>
Co-authored-by: Hervé Le Meur <91831478+lemeurherve@users.noreply.github.com>
Co-authored-by: Hervé Le Meur <91831478+lemeurherve@users.noreply.github.com>
Github Api expected mergemethod value to be capital letter

Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
@@ -83,6 +91,27 @@ type PullRequest struct {
remotePullRequest PullRequestApi
}

// isMergeMethodValid ensure that we specified a valid merge method.
func isMergeMethodValid(method string) (bool, error) {
if len(method) == 0 ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(method) == 0 ||
if method == "" ||

NITPICK: "Idiomatic" way to check for empty strings: when reading it clear that method is a string (while len(method) is ambiguous: is it a slice or a string or something else ?)

err := p.gh.client.Mutate(context.Background(), &mutation, input, nil)
// The Github Api expects the merge method to be capital letter and don't allows empty value
// hence the reason to set input.MergeMethod only if the value is not nil
if len(p.spec.MergeMethod) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(p.spec.MergeMethod) > 0 {
if p.spec.MergeMethod != "" {

NITPICK: "Idiomatic" way to check for empty strings: when reading it clear that p.spec.MergeMethod is a string (while len(p.spec.MergeMethod) is ambiguous: is it a slice or a string or something else ?)

var mutation mutationEnablePullRequestAutoMerge

input := githubv4.EnablePullRequestAutoMergeInput{
PullRequestID: githubv4.String(p.remotePullRequest.ID),
}

err := p.gh.client.Mutate(context.Background(), &mutation, input, nil)
// The Github Api expects the merge method to be capital letter and don't allows empty value
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The Github Api expects the merge method to be capital letter and don't allows empty value
// The Github API expects the merge method to be in upper case and does not allow empty values

return false, ErrBadMergeMethod
}

// Validate ensure that a pullrequest spec contains validate fields
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Validate ensure that a pullrequest spec contains validate fields
// Validate ensures that a pullrequest specification contains validate fields

@@ -83,6 +91,27 @@ type PullRequest struct {
remotePullRequest PullRequestApi
}

// isMergeMethodValid ensure that we specified a valid merge method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// isMergeMethodValid ensure that we specified a valid merge method.
// isMergeMethodValid ensures that the specified merge method is valid

Copy link
Contributor

@dduportal dduportal left a comment

Choose a reason for hiding this comment

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

Looks good to me (a few non blocking nitpicks/comments).

Let's go for 0.20.0

@olblak olblak merged commit a7d3118 into updatecli:main Feb 15, 2022
@dduportal dduportal added the enhancement New feature or request label Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pullrequest-github
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a mergeMethod parameter to the pull request spec
3 participants