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

sync: main to develop #68

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
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
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ inputs:
description: "JSON array of GitHub team `slug`s that will be requested to review the PR. Example: '['js-team']'"
required: false
default: '[]'
LABELS:
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
28 changes: 27 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +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 @@ -67,8 +70,31 @@ async function run() {
});
}

if (labels.length > 0) {
octokit.rest.issues.addLabels({
owner,
repo,
issue_number: pullRequest.number,
labels
})
}

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
Loading
Loading