Skip to content

Commit

Permalink
Add ability to ignore merge conflicts (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-gomez authored Feb 10, 2020
1 parent 8b7ece6 commit 699da47
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ All configuration values, except `GITHUB_TOKEN`, are optional.

* `RETRY_SLEEP`: The amount of time (in milliseconds) that _autoupdate_ should wait between branch update attempts (default: `"300"`).

* `MERGE_CONFLICT_ACTION`: Controls how _autoupdate_ handles a merge conflict when updating a PR. Possible values are:
* `"fail"` (default): _autoupdate_ will report a failure on each PR that has a merge conflict.
* `"ignore"`: _autoupdate_ will silently ignore merge conflicts.

Here's an example workflow file with all of the above options specified:

```yaml
Expand Down
10 changes: 10 additions & 0 deletions src/autoupdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class AutoUpdater {

const retryCount = this.config.retryCount();
const retrySleep = this.config.retrySleep();
const mergeConflictAction = this.config.mergeConflictAction();

let retries = 0;

while (true) {
Expand All @@ -232,6 +234,14 @@ class AutoUpdater {
await doMerge();
break;
} catch (e) {
if (e.message === "Merge conflict" && mergeConflictAction === "ignore") {
ghCore.info('Merge conflict detected, skipping update.');
return;
} else if (e.message === "Merge conflict") {
ghCore.error("Merge conflict error trying to update branch");
throw e;
}

ghCore.error(`Caught error trying to update branch: ${e.message}`);

if (retries < retryCount) {
Expand Down
5 changes: 5 additions & 0 deletions src/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class ConfigLoader {
), 10);
}

mergeConflictAction() {
// one of 'fail' or 'ignore'.
return this.getValue('MERGE_CONFLICT_ACTION', false, 'fail');
}

getValue(key, required = false, defaulVal = null) {
if (key in this.env
&& this.env[key] !== null
Expand Down

0 comments on commit 699da47

Please sign in to comment.