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

feat: Add merge-method option #105

Merged
merged 3 commits into from
Aug 12, 2021
Merged

feat: Add merge-method option #105

merged 3 commits into from
Aug 12, 2021

Conversation

simenandre
Copy link
Contributor

As per #103, this adds the option to set which merge method to use (e.g. squash or rebase).

fixes #103

@simenandre simenandre requested review from nathanleiby and a team as code owners August 7, 2021 13:33
@simenandre simenandre requested review from tnsardesai and removed request for a team August 7, 2021 13:33
Copy link
Contributor

@nathanleiby nathanleiby left a comment

Choose a reason for hiding this comment

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

Thanks so much for the contribution! This looks great.

One small request: let's add some validation within the command to error if any invalid string value is passed (i.e. only allow "merge", "squash", and "rebase"). This way it will fail immediately at the start rather than doing a fan out and failing for all the parallelized commands.

Something like the "custom validator" logic shown here:
https://github.com/spf13/cobra/blob/master/user_guide.md#positional-and-custom-arguments

@simenandre
Copy link
Contributor Author

simenandre commented Aug 9, 2021

Hi @nathanleiby, AFAIK, custom validation applies for the whole command (merge in our case), not just the flag. Trying to use something standardized, I went over to pflag to see what it had to offer, and find this: spf13/pflag#236

I see four options.

  1. Use/create a fork of pflag while Add capability to restrict flag values to a set of allowed values spf13/pflag#236 is waiting.
  2. Write custom validation for the whole command, like described above
  3. Write something in cmd/merge.go
  4. Let either Github or GitLab validate it.

@nathanleiby
Copy link
Contributor

@cobraz thanks for digging into this.

Elsewhere in the repo we've followed an approach I think is (2) or (3) in your list. Here's an example of validating that the string passed to --throttle can be parsed as a Golang duration. Suggest that we follow the same approach here.

@nathanleiby
Copy link
Contributor

@cobraz I realized I didn't link the suggested code with validation logic. I'm sorry about that! The code I meant to link is here:

microplane/cmd/merge.go

Lines 36 to 47 in bc56dbb

throttle, err := cmd.Flags().GetString("throttle")
if err != nil {
log.Fatal(err)
}
if throttle != "" {
// Try parsing it and updating the limiter
dur, err := time.ParseDuration(throttle)
if err != nil {
log.Fatalf("Error parsing --throttle flag: %s", err.Error())
}
mergeThrottle = time.NewTicker(dur)
}

Hope this isn't stepping on your toes too much, but I went ahead and implemented the same sort of check for --merge-method, so we can go ahead and merge your change. Thank you again for the the PR!

@nathanleiby nathanleiby merged commit b365e25 into Clever:master Aug 12, 2021
@nathanleiby
Copy link
Contributor

@simenandre
Copy link
Contributor Author

Thank you 🙏

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.

Squash instead of merge commit
2 participants