Skip to content

Commit

Permalink
Add config for automerge method
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Mar 22, 2024
1 parent ad44973 commit cc7a85a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function getDefaultConfig()
'allow_update_indirect_with_direct' => 0,
'automerge' => 0,
'automerge_security' => 0,
'automerge_method' => 'merge',
'automerge_method_security' => 'merge',
'labels' => [],
'labels_security' => [],
];
Expand Down Expand Up @@ -114,6 +116,33 @@ public function shouldAutoMerge($is_security_update = false)
return (bool) $this->config->automerge;
}

public function getAutomergeMethod($is_security_update = false) : string
{
if (!$is_security_update) {
return $this->getAutoMergeMethodWithFallback($is_security_update);
}
// Otherwise, let's see if it's even set in config. Otherwise this
// should be set to the value (or fallback value) of the general
// automerge method.
if (!$this->hasConfigForKey('automerge_method_security')) {
return $this->getAutoMergeMethodWithFallback('automerge_method_security');
}
return $this->getAutoMergeMethodWithFallback('automerge_method');
}

protected function getAutoMergeMethodWithFallback($automerge_property) : string
{
if (!in_array($this->config->{$automerge_property}, [
'merge',
'rebase',
'squash',
])
) {
return 'merge';
}
return $this->config->{$automerge_property};
}

public function shouldAutoMergeSecurity()
{
return (bool) $this->config->automerge_security;
Expand Down

0 comments on commit cc7a85a

Please sign in to comment.