Skip to content

Commit

Permalink
Add option for automerge (#17)
Browse files Browse the repository at this point in the history
* Add option for automerge

* Add option for security only. Add test coverage
  • Loading branch information
eiriksm committed Jun 8, 2022
1 parent e6b077a commit 2d0ec99
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Config.php
Expand Up @@ -34,6 +34,8 @@ public function getDefaultConfig()
'branch_prefix' => '',
'commit_message_convention' => '',
'allow_update_indirect_with_direct' => 0,
'automerge' => 0,
'automerge_security' => 0,
];
}

Expand Down Expand Up @@ -72,6 +74,25 @@ public function hasConfigForKey($key)
return !empty($this->configOptionsSet[$key]);
}

public function shouldAutoMerge($is_security_update = false)
{
if (!$is_security_update) {
// It's not a security update. Let's use the option found in the config.
return (bool) $this->config->automerge;
}
if ($this->shouldAutoMergeSecurity()) {
// Meaning we should automerge, no matter what the general automerge config says.
return true;
}
// Fall back to using the actual option.
return (bool) $this->config->automerge;
}

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

public function shouldUpdateIndirectWithDirect()
{
return (bool) $this->config->allow_update_indirect_with_direct;
Expand Down
94 changes: 94 additions & 0 deletions tests/UnitTest.php
Expand Up @@ -213,6 +213,28 @@ public function testAlwaysUpdateAll($filename, $expected_result)
self::assertEquals($expected_result, $data->shouldAlwaysUpdateAll());
}

/**
* Test the automerge option.
*
* @dataProvider getAutoMerge
*/
public function testAutoMerge($filename, $expected_result)
{
$data = $this->createDataFromFixture($filename);
self::assertEquals($expected_result, $data->shouldAutoMerge());
}

/**
* Test the automerge_security option.
*
* @dataProvider getAutoMergeSecurity
*/
public function testAutoMergeSecurity($filename, $expected_result)
{
$data = $this->createDataFromFixture($filename);
self::assertEquals($expected_result, $data->shouldAutoMerge(true));
}

/**
* Test the security updates config option.
*
Expand Down Expand Up @@ -278,6 +300,78 @@ public function getUpdateWithDeps()
];
}

public function getAutoMerge()
{
return [
[
'empty.json',
false,
],
[
'automerge.json',
true,
],
[
'automerge2.json',
true,
],
[
'automerge3.json',
true,
],
[
'automerge4.json',
false,
],
[
'automerge5.json',
false,
]
];
}

public function getAutoMergeSecurity()
{
return [
[
'empty.json',
false,
],
[
'automerge.json',
true,
],
[
'automerge2.json',
true,
],
[
'automerge3.json',
true,
],
[
'automerge4.json',
false,
],
[
'automerge5.json',
false,
],
[
'automerge_security.json',
true,
],
[
'automerge_security2.json',
true,
],
[
'automerge_security3.json',
true,
],
];
}

public function getAlwaysUpdateAll()
{
return [
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/automerge.json
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"automerge": "yes_of_course_this_should_be_an_int_but_this_evaluates_to_true"
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/automerge2.json
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"automerge": "1"
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/automerge3.json
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"automerge": 1
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/automerge4.json
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"automerge": null
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/automerge5.json
@@ -0,0 +1,7 @@
{
"extra": {
"violinist": {
"automerge": 0
}
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/automerge_security.json
@@ -0,0 +1,8 @@
{
"extra": {
"violinist": {
"automerge": 0,
"automerge_security": 1
}
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/automerge_security2.json
@@ -0,0 +1,8 @@
{
"extra": {
"violinist": {
"automerge": 1,
"automerge_security": 1
}
}
}
8 changes: 8 additions & 0 deletions tests/fixtures/automerge_security3.json
@@ -0,0 +1,8 @@
{
"extra": {
"violinist": {
"automerge": 1,
"automerge_security": 0
}
}
}

0 comments on commit 2d0ec99

Please sign in to comment.