approve-command #64
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
name: New repo approve | |
# trigger by chatops '/approve' | |
on: | |
repository_dispatch: | |
types: [approve-command] | |
jobs: | |
approve: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Link to this workflow in command comment | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
body: "[Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
- name: Check preconditions | |
id: check | |
uses: actions/github-script@v1 | |
with: | |
script: | | |
const issue = context.payload.client_payload.github.payload.issue | |
if (issue.state !== 'open' || !issue.labels.some(x => x.name === 'new repo')) { | |
const msg = "Issue must be open and labeled 'new repo'" | |
core.setOutput('error', msg) | |
core.setFailed(msg) | |
} | |
- uses: actions/checkout@v2 | |
- name: Run repo creation script | |
id: create_script | |
uses: Amadevus/pwsh-script@v2 | |
env: | |
TOKEN: ${{ secrets.BSDATA_BOT_TOKEN }} | |
with: | |
script: | | |
./.github/scripts/HandleApproveComment.ps1 $github.event.client_payload.github.payload -Token $env:TOKEN | |
- name: Add reaction to command comment on failure | |
uses: peter-evans/create-or-update-comment@v1 | |
if: failure() | |
with: | |
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
body: ":poop: ${{ steps.create_script.outputs.error }} ${{ steps.check.outputs.error }}" | |
reactions: "-1" | |
- name: Add reaction to command comment on success | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
reactions: hooray | |
- name: Add 'created' label | |
uses: actions/github-script@v3 | |
with: | |
script: | | |
await github.issues.addLabels({ | |
...context.repo, | |
issue_number: context.payload.client_payload.github.payload.issue.number, | |
labels: ['created'] | |
}) | |
- name: Format closing comment | |
id: format | |
uses: Amadevus/pwsh-script@v2 | |
env: | |
CREATE_RESULT: ${{ steps.create_script.outputs.result }} | |
with: | |
script: | | |
$text = Get-Content ./.github/scripts/RepoCreatedComment.md -Raw | |
$login = $github.event.client_payload.github.payload.issue.user.login | |
$repoUrl = ($env:CREATE_RESULT | ConvertFrom-Json).html_url | |
return $text -f $login, $repoUrl | |
- name: Comment and close issue | |
uses: peter-evans/close-issue@v1 | |
with: | |
issue-number: ${{ github.event.client_payload.github.payload.issue.number }} | |
comment: ${{ steps.format.outputs.result }} |