From a80c55e6127762b66748818889e2badd991018d4 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:31:17 +0100 Subject: [PATCH 1/7] added unstable branches logic to merger --- src/github/merger.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/github/merger.ts b/src/github/merger.ts index 2f03b98..70734e9 100644 --- a/src/github/merger.ts +++ b/src/github/merger.ts @@ -35,8 +35,26 @@ export class Merger { private readonly gql: typeof graphql, private readonly logger: ActionLogger, private readonly mergeMethod: PullRequestMergeMethod, + private readonly allowUnstable: boolean = false, ) {} + errorPermitsToMerge(error: Error): boolean { + // If it's clean it can be merged + if (error.message.includes("Pull request is in clean status")) { + return true; + } + + // If it is unstable and allowed, it can also be merged + if (error.message.includes("Pull request is in unstable status")) { + this.logger.warn( + "PR is unstable! Some non required status check is failing.", + ); + return this.allowUnstable; + } + + return false; + } + async enableAutoMerge(): Promise { try { await this.gql<{ @@ -48,10 +66,7 @@ export class Merger { this.logger.info("Succesfully enabled auto-merge"); } catch (error) { this.logger.warn(error as Error); - if ( - error instanceof Error && - error.message.includes("Pull request is in clean status") - ) { + if (error instanceof Error && this.errorPermitsToMerge(error)) { this.logger.warn( "Pull Request is ready to merge. Running merge command instead", ); From 9285f2f1bfab50271986b8c3a96faa626990f3bf Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:32:44 +0100 Subject: [PATCH 2/7] added unstable method to entry point --- src/index.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7710034..6c42b87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,6 +52,11 @@ const getMergeMethod = (): PullRequestMergeMethod => { return method; }; +/** If it should allow PRs that have failed NON REQUIRED status check to be merged */ +const getAllowUnstable = (): boolean => { + return getInput("ALLOW_UNSTABLE", { required: false }) === "true"; +}; + const silentMode = getInput("SILENT", { required: false }) === "true"; logger.info( @@ -80,7 +85,15 @@ if (context.payload.comment) { const gql = getOctokit(token).graphql.defaults({ headers: { authorization: `token ${token}` }, }) as graphql; - const merger = new Merger(issue.node_id, gql, logger, getMergeMethod()); + const mergeMethod = getMergeMethod(); + const unstableAllowed = getAllowUnstable(); + const merger = new Merger( + issue.node_id, + gql, + logger, + mergeMethod, + unstableAllowed, + ); const bot = new Bot( comment, issue, From 617fb64c9aa82818d5f1276556020cb8de1f912d Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:36:08 +0100 Subject: [PATCH 3/7] added docs --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 699a61d..09f1cfa 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ jobs: with: GITHUB_TOKEN: '${{ github.token }}' MERGE_METHOD: "SQUASH" + ALLOW_UNSTABLE: true ``` #### Inputs @@ -48,6 +49,10 @@ You can find all the inputs in [the action file](./action.yml), but let's walk t - `ALLOWLIST`: List of user accounts which are allowed to use the bot aside from the author and org members. - **Optional** - Must be a comma separated value: `user-1,user-2,user-3`. +- `ALLOW_UNSTABLE`: If unstable, ready to merge, PRs can be merged + - An [unstable PR](https://docs.github.com/en/graphql/reference/enums#mergestatestatus) is a PR that can be merged, but a *non required status check* is failing. + - This is only relevant once the PR can be merged. GitHub's auto-merge always merges unstable PRs + - **Optional**: Defaults to `true` ## Usage From bae2009faaeea37a1d43eeda6af4f4da61527851 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:36:52 +0100 Subject: [PATCH 4/7] changed to be true by default --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6c42b87..39de748 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,7 +54,7 @@ const getMergeMethod = (): PullRequestMergeMethod => { /** If it should allow PRs that have failed NON REQUIRED status check to be merged */ const getAllowUnstable = (): boolean => { - return getInput("ALLOW_UNSTABLE", { required: false }) === "true"; + return getInput("ALLOW_UNSTABLE", { required: false }) !== "false"; }; const silentMode = getInput("SILENT", { required: false }) === "true"; From 8778c38fc9bd9bf9a52f317992fde8a5f56a6a80 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:38:00 +0100 Subject: [PATCH 5/7] added input in action.yml --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 5b11377..59a4e42 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,9 @@ inputs: ALLOWLIST: required: false description: List of users which are allowed to use the bot. Separated by commas (abc,def,ghi) + ALLOW_UNSTABLE: + required: false + description: If unstable, ready to merge, PRs can be merged. Defaults to true outputs: repo: description: 'The name of the repo in owner/repo pattern' From 26c23202800651338aed73cf0cab948620c54219 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:38:06 +0100 Subject: [PATCH 6/7] updated version --- action.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 59a4e42..dc042b6 100644 --- a/action.yml +++ b/action.yml @@ -27,4 +27,4 @@ outputs: runs: using: 'docker' - image: 'docker://ghcr.io/paritytech/auto-merge-bot/action:1.0.0' + image: 'docker://ghcr.io/paritytech/auto-merge-bot/action:1.0.1' diff --git a/package.json b/package.json index 77a659f..f074b63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auto-merge-bot", - "version": "1.0.0", + "version": "1.0.1", "description": "Bot which enables or disable auto-merge", "main": "src/index.ts", "scripts": { From 4f64fb69927a3078e4dc41e82f495032d5f3ac89 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Wed, 6 Mar 2024 14:40:13 +0100 Subject: [PATCH 7/7] fixed typo in plurality --- src/github/merger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/github/merger.ts b/src/github/merger.ts index 70734e9..86d1a07 100644 --- a/src/github/merger.ts +++ b/src/github/merger.ts @@ -47,7 +47,7 @@ export class Merger { // If it is unstable and allowed, it can also be merged if (error.message.includes("Pull request is in unstable status")) { this.logger.warn( - "PR is unstable! Some non required status check is failing.", + "PR is unstable! Some non required status checks are failing.", ); return this.allowUnstable; }