Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
17 changes: 2 additions & 15 deletions .github/workflows/merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,10 @@ jobs:

steps:
- name: "Request review from @ergebnis-bot"
uses: "actions/github-script@v5"
uses: "ergebnis/.github/actions/github/pull-request/request-review@main"
with:
github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}"
script: |
const pullRequest = context.payload.workflow_run.pull_requests[0];
const repository = context.repo;

const reviewers = [
"ergebnis-bot",
]

await github.rest.pulls.requestReviewers({
owner: repository.owner,
repo: repository.repo,
pull_number: pullRequest.number,
reviewers: reviewers,
});
reviewer: "ergebnis-bot"

- name: "Assign @ergebnis-bot"
uses: "ergebnis/.github/actions/github/pull-request/add-assignee@main"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For a full diff see [`1.2.1...main`][1.2.1...main].
- Added composite action `github/pull-request/merge` ([#64]), by [@localheinz]
- Added composite action `github/pull-request/add-label-based-on-branch-name` ([#67]), by [@localheinz]
- Added composite action `github/release/create` ([#72]), by [@localheinz]
- Added composite action `github/pull-request/request-review` ([#73]), by [@localheinz]

## [`1.2.1`][1.2.1]

Expand Down Expand Up @@ -68,5 +69,6 @@ For a full diff see [`1.0.0...main`][1.0.0...main].
[#64]: https://github.com/ergebnis/.github/pull/64
[#67]: https://github.com/ergebnis/.github/pull/67
[#72]: https://github.com/ergebnis/.github/pull/72
[#73]: https://github.com/ergebnis/.github/pull/73

[@localheinz]: https://github.com/localheinz
72 changes: 72 additions & 0 deletions actions/github/pull-request/request-review/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions
# https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_run

name: "Request review from reviewer for pull request"

description: "Requests a review from a reviewer for a pull request"

inputs:
github-token:
description: "GitHub token of a user with permission to request reviewers for a pull request"
required: true
reviewer:
description: "Username of user to request review from for a pull request"
required: true

runs:
using: "composite"

steps:
- name: "Determine pull request number"
uses: "actions/github-script@v5"
with:
github-token: "${{ inputs.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: "Request reviewer"
uses: "actions/github-script@v5"
env:
REVIEWER: "${{ inputs.reviewer }}"
with:
github-token: "${{ inputs.github-token }}"
script: |
if (!process.env.PULL_REQUEST_NUMBER) {
core.setFailed("The environment variable PULL_REQUEST_NUMBER is not defined.");

return;
}

const reviewers = [
process.env.REVIEWER,
];

try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
pull_number: process.env.PULL_REQUEST_NUMBER,
repo: context.repo.repo,
reviewers: reviewers,
});
} catch (error) {
core.setFailed(error.message);
}