chdsbd / kodiak

🔮 A bot to automatically update and merge GitHub PRs
https://kodiakhq.com
GNU Affero General Public License v3.0
1.03k stars 65 forks source link

Dynamic configuration depending on PR properties #783

Open jdnavarro opened 2 years ago

jdnavarro commented 2 years ago

I'm aware you can already override some settings, like the merge method, by passing them on the automerge label, but would it be possible to have the overrides automatically picked (or apply a different configuration altogether) depending on certain properties of the PR?

The particular case I have in mind looks like this:

  1. If a branch PR is only one commit ahead of the target: Fast forward the extra commit as it is.

  2. Otherwise: Merge avoiding fast-forwarding. The merge commit message will be extracted from the PR description.

Would it be too difficult to implement? Is it something you would accept a PR for?

sbdchd commented 2 years ago

Hmm, I'm curious what the API would be like in terms of the config settings & labels for the PR to trigger the behavior.

Having labels override more settings is pretty straightforward to implement, would the different config mean there would be multiple kodiak.toml files in a repo? Maybe different sections in the toml file?

Definitely open to it, but it might be easier to do with a github action

jdnavarro commented 2 years ago

Ideally, it'd be great to have something along how cargo deals with configuration overrides, see platform specific dependencies.

In the case of kodiak it could look like this:

['pr_predicate(number_commits > 1)'.merge]
method = "merge"
message.title = "pull_request_title"

# Fallback
[merge]
method = "squash"
# message.title already defaults to github_default, 
# which in the case of squash would be the commit message.
# message.title = "github_default"
message.include_coauthors = true # will be always true

I wouldn't mess with specifity rules, later matching keys would override earlier declared ones by default. Perhaps you can have special cases where instead of overriding, the second property would be appended, like adding an extra co-author.

In addition to the number of commits, these predicates could be useful too:

Separate configuration files could be implemented as file includes, but that would be a different feature, orthogonal to configuration predicates.