Skip to content

Commit

Permalink
Add auto merge option (#76)
Browse files Browse the repository at this point in the history
* Add auto merge option

* Update README

* Update action.yml
  • Loading branch information
ZimGil authored Aug 23, 2023
1 parent 19c35d4 commit 3428e61
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ githubContextExample.js

# Editors
.vscode
.idea

# Logs
logs
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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 =
core.getInput("CONTENT_COMPARISON").toLowerCase() === "true";
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?`
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 3428e61

Please sign in to comment.