diff --git a/.gitignore b/.gitignore index 67ea5c67..eb1fadaf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ githubContextExample.js # Editors .vscode +.idea # Logs logs diff --git a/README.md b/README.md index 979fc084..d5204977 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,13 @@ JSON array of GitHub team `slug`s that will be requested to review the PR. Example: `'["js-team"]'` Default: `[]` +### `PULL_REQUEST_AUTO_MERGE_METHOD` + +Set a merge method for auto merging. + +Options: `merge`, `squash`, `rebase` + +Default: `false` ## Outputs diff --git a/action.yml b/action.yml index c91fa3bf..fd55ebae 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,10 @@ inputs: description: "JSON array of label names that will be added to the PR. Example: '['sync']'" required: false default: '[]' + PULL_REQUEST_AUTO_MERGE_METHOD: + description: "Set a merge method for auto merging. Options: 'merge', 'squash', 'rebase'" + required: false + default: 'false' outputs: PULL_REQUEST_URL: description: "URL for either the generated pull request or the currently open one" diff --git a/index.js b/index.js index 2a13d800..c2e3840a 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ async function run() { const githubToken = core.getInput("GITHUB_TOKEN", { required: true }); const pullRequestTitle = core.getInput("PULL_REQUEST_TITLE"); const pullRequestBody = core.getInput("PULL_REQUEST_BODY"); + const pullRequestAutoMergeMethod = core.getInput("PULL_REQUEST_AUTO_MERGE_METHOD"); const pullRequestIsDraft = core.getInput("PULL_REQUEST_IS_DRAFT").toLowerCase() === "true"; const contentComparison = @@ -17,6 +18,7 @@ async function run() { const reviewers = JSON.parse(core.getInput("REVIEWERS")); const team_reviewers = JSON.parse(core.getInput("TEAM_REVIEWERS")); const labels = JSON.parse(core.getInput("LABELS")); + let isMerged = false; console.log( `Should a pull request to ${toBranch} from ${fromBranch} be created?` @@ -77,8 +79,22 @@ async function run() { }) } + if (pullRequestAutoMergeMethod) { + try { + await octokit.rest.pulls.merge({ + owner, + repo, + pull_number: pullRequest.number, + merge_method: pullRequestAutoMergeMethod + }); + isMerged = true; + } catch (err) { + isMerged = false; + } + } + console.log( - `Pull request (${pullRequest.number}) successful! You can view it here: ${pullRequest.url}` + `Pull request (${pullRequest.number}) successfully created${isMerged ? ' and merged' : ' '}! You can view it here: ${pullRequest.url}` ); core.setOutput("PULL_REQUEST_URL", pullRequest.url.toString());