-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Conversation
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.
go for it I guess ? :)
I still needs additional testing 😁 |
It's now ready to be merged. The last commit fix the issue identified during testing |
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 || |
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.
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 { |
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.
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 |
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.
// 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 |
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.
// 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. |
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.
// isMergeMethodValid ensure that we specified a valid merge method. | |
// isMergeMethodValid ensures that the specified merge method is valid |
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.
Looks good to me (a few non blocking nitpicks/comments).
Let's go for 0.20.0
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