Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to ignore merge conflicts #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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