-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from wayofdev/feat/auto-approve-action
feat: composite actions to work with github PRs
- Loading branch information
Showing
10 changed files
with
293 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
|
||
# 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/issues/assignees#add-assignees-to-an-issue | ||
# 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: 🙋♂️ Add assignee to pull request | ||
|
||
description: Adds an assignee to a pull request | ||
|
||
inputs: | ||
assignee: | ||
description: Username of user to add as an assignee to a pull request | ||
required: true | ||
github-token: | ||
description: GitHub token of a user with permission to add assignees to a pull request | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
|
||
steps: | ||
- name: 🤔 Determine pull request number | ||
uses: actions/github-script@v7.0.1 | ||
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: 🙋♂️ Add assignee to pull request | ||
uses: actions/github-script@v7.0.1 | ||
env: | ||
ASSIGNEE: "${{ inputs.assignee }}" | ||
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 assignees = [ | ||
process.env.ASSIGNEE, | ||
]; | ||
try { | ||
await github.rest.issues.addAssignees({ | ||
assignees: assignees, | ||
issue_number: process.env.PULL_REQUEST_NUMBER, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
|
||
# 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/pulls/reviews#create-a-review-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: ✅ Approve pull request | ||
|
||
description: Approves a pull request | ||
|
||
inputs: | ||
github-token: | ||
description: GitHub token of a user with permission to approve a pull request | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
|
||
steps: | ||
- name: 🤔 Determine pull request number | ||
uses: actions/github-script@v7.0.1 | ||
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: ✅ Approve pull request | ||
uses: actions/github-script@v7.0.1 | ||
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; | ||
} | ||
try { | ||
await github.rest.pulls.createReview({ | ||
event: "APPROVE", | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: process.env.PULL_REQUEST_NUMBER, | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
|
||
# 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/pulls/pulls#merge-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: 📥 Merge pull request | ||
|
||
description: Merges a pull request | ||
|
||
inputs: | ||
github-token: | ||
description: GitHub token of a user with permission to merge a pull request | ||
required: true | ||
merge-method: | ||
default: merge | ||
description: 'Which merge method to use, one "merge", "rebase", "squash"' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
|
||
steps: | ||
- name: 🤔 Determine pull request number | ||
uses: actions/github-script@v7.0.1 | ||
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: 📥 Merge pull request | ||
uses: actions/github-script@v7.0.1 | ||
env: | ||
MERGE_METHOD: "${{ inputs.merge-method }}" | ||
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; | ||
} | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
|
||
# 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/pulls/review-requests#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@v7.0.1 | ||
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@v7.0.1" | ||
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); | ||
} |