-
Notifications
You must be signed in to change notification settings - Fork 2
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 #20 from joshjohanning/enhancements
feat: using github-script for commentsand updating readme
- Loading branch information
Showing
2 changed files
with
52 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ inputs: | |
required: true | ||
token: | ||
description: "GitHub App installation token or PAT that has access to read the comments and check the org team's membership" | ||
default: ${{ github.token }} # this doesn't allow tagging of the approval team; better to use GitHub App | ||
required: true | ||
fail-if-approval-not-found: | ||
description: "Fail the action (i.e. show the action run as red) if the command is not found in the comments from someone in the approver team" | ||
|
@@ -43,7 +44,7 @@ runs: | |
GH_TOKEN: ${{ inputs.token }} | ||
shell: bash | ||
run: | | ||
# "checking for a ${{ inputs.approve-command }} command in the comments from someone in the approver team" | ||
# "checking for a ${{ inputs.approve-command }} command in the comments from someone in the ${{ inputs.team-name}} team" | ||
users=$(gh api --paginate '/orgs/${{ github.repository_owner }}/teams/${{ inputs.team-name }}/members' | jq -c '.[].login') | ||
approveCommand="${{ inputs.approve-command }}" | ||
authorized=false | ||
|
@@ -67,48 +68,66 @@ runs: | |
echo "Approval not found or not authorized" | ||
echo "approved=false" >> $GITHUB_OUTPUT | ||
if !(${{ inputs.fail-if-approval-not-found }}); then | ||
echo "::notice title=Not Approved::There is no ${{ inputs.approve-command }} command in the comments from someone in the ${{ github.repository_owner }}/${{ inputs.team-name }} team" | ||
echo "::notice title=Not Approved::There is no ${{ inputs.approve-command }} command in the comments from someone in the @${{ github.repository_owner }}/${{ inputs.team-name }} team" | ||
fi | ||
fi | ||
- if: ${{ steps.check-approval.outputs.approved == 'false' && inputs.fail-if-approval-not-found == 'true' }} | ||
name: Create completed comment | ||
uses: peter-evans/[email protected] | ||
uses: actions/github-script@v6 | ||
with: | ||
token: ${{ inputs.token }} | ||
issue-number: ${{ github.event.issue.number }} | ||
body: | | ||
Hey, @${{ github.event.comment.user.login }}! | ||
:cry: No one approved your run yet! Have someone from the @${{ github.repository_owner }}/${{ inputs.team-name }} team run `${{ inputs.approve-command }}` and then try your command again | ||
github-token: ${{ inputs.token }} | ||
script: | | ||
let commentBody = `Hey, @${{ github.event.comment.user.login }}! | ||
:cry: No one approved your run yet! Have someone from the @${context.repo.owner}/${{ inputs.team-name }} team comment \`${{ inputs.approve-command }}\` and then try your command again | ||
_:no_entry_sign: :no_entry: Marking the [workflow run](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) as failed_ | ||
` | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: commentBody | ||
}) | ||
- if: ${{ steps.check-approval.outputs.approved == 'false' && inputs.fail-if-approval-not-found == 'false' }} | ||
name: Create completed comment | ||
uses: peter-evans/[email protected] | ||
uses: actions/github-script@v6 | ||
with: | ||
token: ${{ inputs.token }} | ||
issue-number: ${{ github.event.issue.number }} | ||
body: | | ||
Hey, @${{ github.event.comment.user.login }}! | ||
:cry: No one approved your run yet! Have someone from the @${{ github.repository_owner }}/${{ inputs.team-name }} team run `${{ inputs.approve-command }}` and then try your command again | ||
github-token: ${{ inputs.token }} | ||
script: | | ||
let commentBody = `Hey, @${{ github.event.comment.user.login }}! | ||
:cry: No one approved your run yet! Have someone from the @${context.repo.owner}/${{ inputs.team-name }} team run `${{ inputs.approve-command }}` and then try your command again | ||
_:warning: :pause_button: See [workflow run](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) for reference_ | ||
` | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: commentBody | ||
}) | ||
- if: ${{ steps.check-approval.outputs.approved == 'true' && inputs.post-successful-approval-comment == 'true' }} | ||
name: Create completed comment | ||
uses: peter-evans/[email protected] | ||
uses: actions/github-script@v6 | ||
with: | ||
token: ${{ inputs.token }} | ||
issue-number: ${{ github.event.issue.number }} | ||
body: | | ||
Hey, @${{ github.event.comment.user.login }}! | ||
github-token: ${{ inputs.token }} | ||
script: | | ||
let commentBody = `Hey, @${{ github.event.comment.user.login }}! | ||
${{ inputs.successful-approval-comment }} | ||
` | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: commentBody | ||
}) | ||
# if specified, exit with an error if approval is not found | ||
- name: exit and fail workflow if not approved | ||
if: ${{ inputs.fail-if-approval-not-found == 'true' && steps.check-approval.outputs.approved == 'false' }} | ||
uses: actions/github-script@v6.4.0 | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setFailed("There is no ${{ inputs.approve-command }} command in the comments from someone in the ${{ github.repository_owner }}/${{ inputs.team-name }} team"); | ||
core.setFailed(`There is no ${{ inputs.approve-command }} command in the comments from someone in the @${context.repo.owner}/${{ inputs.team-name }} team`); |