Skip to content

Commit

Permalink
Fix: Determine pull request number
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Oct 4, 2022
1 parent a8ef014 commit af8a015
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions .github/workflows/merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,48 @@ jobs:
)
steps:
- name: "Determine pull request number"
uses: "actions/github-script@v6.3.1"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
if (
context.eventName == 'pull_request' ||
context.eventName == 'pull_request_target'
) {
core.exportVariable("PULL_REQUEST_NUMBER", context.payload.pull_request.number);
return;
}
if (context.eventName == 'workflow_run') {
core.exportVariable("PULL_REQUEST_NUMBER", context.payload.workflow_run.pull_requests[0].number);
return;
}
core.setFailed(`Unable to determine the pull request number for event "${context.eventName}"`);
- name: "Merge pull request"
uses: "actions/github-script@v3"
uses: "actions/github-script@v6.3.1"
env:
MERGE_METHOD: "${{ inputs.merge-method }}"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const pullRequest = context.payload.pull_request;
const repository = context.repo;
await github.pulls.merge({
merge_method: "merge",
owner: repository.owner,
pull_number: pullRequest.number,
repo: repository.repo,
})
if (!process.env.PULL_REQUEST_NUMBER) {
core.setFailed("The environment variable PULL_REQUEST_NUMBER is not defined.");
return;
}
try {
await github.rest.pulls.merge({
merge_method: process.env.MERGE_METHOD,
owner: context.repo.owner,
pull_number: process.env.PULL_REQUEST_NUMBER,
repo: context.repo.repo,
});
} catch (error) {
core.setFailed(error.message);
} -

0 comments on commit af8a015

Please sign in to comment.