-
-
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ jobs: | |
runs-on: ${{ inputs.os }} | ||
steps: | ||
- name: 📦 Check out the codebase | ||
uses: actions/checkout@v4 | ||
uses: actions/checkout@v4.1.7 | ||
|
||
- name: 🛠️ Install goss and dgoss | ||
uses: e1himself/[email protected] | ||
|
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 |
---|---|---|
|
@@ -19,10 +19,10 @@ jobs: | |
pull-requests: read | ||
steps: | ||
- name: 📦 Check out the codebase | ||
uses: actions/[email protected].5 | ||
uses: actions/[email protected].7 | ||
|
||
- name: 🧐 Lint commits using "commitlint" | ||
uses: wagoid/commitlint-github-action@v6.0.1 | ||
uses: wagoid/commitlint-github-action@v6.1.1 | ||
with: | ||
configFile: ${{ github.workspace }}/.github/.commitlint.config.mjs | ||
failOnWarnings: false | ||
|
@@ -37,7 +37,7 @@ jobs: | |
group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
steps: | ||
- name: 📦 Check out the codebase | ||
uses: actions/[email protected].5 | ||
uses: actions/[email protected].7 | ||
|
||
- name: 🧐 Lint YAML files | ||
uses: ibiqlik/[email protected] | ||
|
@@ -54,7 +54,7 @@ jobs: | |
group: markdown-linting-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
steps: | ||
- name: 📦 Check out the codebase | ||
uses: actions/[email protected].5 | ||
uses: actions/[email protected].7 | ||
|
||
- name: 🧐 Lint Markdown files | ||
uses: DavidAnson/[email protected] | ||
|
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ name: 🏷️ Add labels | |
|
||
jobs: | ||
label: | ||
uses: wayofdev/gh-actions/.github/workflows/[email protected].0 | ||
uses: wayofdev/gh-actions/.github/workflows/[email protected].1 | ||
with: | ||
os: ubuntu-latest | ||
secrets: | ||
|
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/[email protected] | ||
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/[email protected] | ||
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/[email protected] | ||
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/[email protected] | ||
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/[email protected] | ||
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/[email protected] | ||
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/[email protected] | ||
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/[email protected]" | ||
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); | ||
} |