lindell/multi-gitter

Handle failed merge runs due to branch protection rules more gracefully

klieret opened this issue · 5 comments

Describe the bug

Running multi-gitter merge -U XXX aborts entirely as soon as it hits a repository where it cannot merge due to branch protection rules (e.g., because a review is required).
Instead, it would be more convenient to report the error at the end, but still work on all other repositories (as multi-gitter run does).

 multi-gitter merge -U klieret --branch "pre-commit-ci-update-config" --merge-type squash                                                                                       ─╯
INFO[0005] Merging 6 pull requests
INFO[0005] Merging                                       pr="klieret/RandomFileTree #47"
INFO[0007] Merging                                       pr="klieret/python-cookiecutter #4"
INFO[0010] Merging                                       pr="klieret/.github #5"
INFO[0012] Merging                                       pr="klieret/python-pre-commit-demo-tutorial #7"
Error: PUT https://api.github.com/repos/klieret/python-pre-commit-demo-tutorial/pulls/7/merge: 405 At least 1 approving review is required by reviewers with write access. []
Usage:
  multi-gitter merge [flags]

Flags:
  -g, --base-url string      Base URL of the GitHub API, needs to be changed if GitHub enterprise is used. Or the url to a self-hosted GitLab instance.
  -B, --branch string        The name of the branch where changes are committed. (default "multi-gitter-branch")
      --config string        Path of the config file.
      --fork                 Use pull requests made from forks instead of from the same repository.
      --fork-owner string    If set, use forks from the defined value instead of the logged in user.
  -G, --group strings        The name of a GitLab organization. All repositories in that group will be used.
  -h, --help                 help for merge
      --include-subgroups    Include GitLab subgroups when using the --group flag.
      --insecure             Insecure controls whether a client verifies the server certificate chain and host name. Used only for Bitbucket server.
      --log-file string      The file where all logs should be printed to. "-" means stdout. (default "-")
      --log-format string    The formating of the logs. Available values: text, json, json-pretty. (default "text")
  -L, --log-level string     The level of logging that should be made. Available values: trace, debug, info, error. (default "info")
      --merge-type strings   The type of merge that should be done (GitHub). Multiple types can be used as backup strategies if the first one is not allowed. (default [merge,squash,rebase])
  -O, --org strings          The name of a GitHub organization. All repositories in that organization will be used.
  -p, --platform string      The platform that is used. Available values: github, gitlab, gitea, bitbucket_server. (default "github")
  -P, --project strings      The name, including owner of a GitLab project in the format "ownerName/repoName".
  -R, --repo strings         The name, including owner of a GitHub repository in the format "ownerName/repoName".
      --ssh-auth             Use SSH cloning URL instead of HTTPS + token. This requires that a setup with ssh keys that have access to all repos and that the server is already in known_hosts.
  -T, --token string         The GitHub/GitLab personal access token. Can also be set using the GITHUB_TOKEN/GITLAB_TOKEN/GITEA_TOKEN/BITBUCKET_SERVER_TOKEN environment variable.
  -U, --user strings         The name of a user. All repositories owned by that user will be used.
  -u, --username string      The Bitbucket server username.

PUT https://api.github.com/repos/klieret/python-pre-commit-demo-tutorial/pulls/7/merge: 405 At least 1 approving review is required by reviewers with write access. []

To Reproduce

Steps to reproduce the behavior:

  1. Create a repository where you protect the main branch with "needs approval"
  2. Run multi-gitter merge -U <your user>
  3. See error

Expected behavior

multi-gitter merge reports an error for the corresponding repository but then proceeds to look at the others. Similar to the behavior of multi-gitter run.

Hello.

I agree it should not fail all merges in this case.

Can you check if #310 does what you intended?

You can install and try it with:

go install github.com/lindell/multi-gitter@no-abort-on-merge

@klieret Have you had the time to verify this?

Ah, sorry I completely forgot! I'll try later today and let you know :)

I've created two repositories https://github.com/klieret/multi-gitter-failed-merge-handle-test-repo-1 and https://github.com/klieret/multi-gitter-failed-merge-handle-test-repo-2, where the first one has a "requires review" branch protection rule (set to apply to even admins).

I then run

~/go/bin/multi-gitter merge -U klieret --branch "multi-gitter-test-pr-2" 

And get

INFO[0003] Merging 2 pull requests
INFO[0003] Merging                                       pr="klieret/multi-gitter-failed-merge-handle-test-repo-1 #2"
ERRO[0004] Error occured while merging: PUT https://api.github.com/repos/klieret/multi-gitter-failed-merge-handle-test-repo-1/pulls/2/merge: 405 At least 1 approving review is required by reviewers with write access. []  pr="klieret/multi-gitter-failed-merge-handle-test-repo-1 #2"
INFO[0004] Merging                                       pr="klieret/multi-gitter-failed-merge-handle-test-repo-2 #2"

So #310 definitely does it's job :)

To improve things further, it would of course be nice to have an overview over the failed/successful jobs at the end (like with multi-gitter run, but I'm already very happy.

Thank you again for fixing this!

Included in release v0.43.3 🎉