Skip to content

Commit 46fef26

Browse files
Merge pull request #30 from joshjohanning/refactor-comment
refactor: combine failure comment logic into 1 step
2 parents 90c3a61 + e20da5e commit 46fef26

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

action.yml

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,23 @@ runs:
8484
fi
8585
fi
8686
87-
- if: ${{ steps.check-approval.outputs.approved == 'false' && inputs.fail-if-approval-not-found == 'true' }}
87+
- if: ${{ steps.check-approval.outputs.approved == 'false' }}
8888
name: Create completed comment
8989
uses: actions/github-script@v6
9090
with:
9191
github-token: ${{ inputs.token }}
9292
script: |
93+
const isFailure = '${{ inputs.fail-if-approval-not-found }}' === 'true';
94+
const statusLine = isFailure
95+
? '_:no_entry_sign: :no_entry: Marking the [workflow run](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) as failed_'
96+
: '_:warning: :pause_button: See [workflow run](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) for reference_';
97+
9398
let commentBody = `Hey, @${{ github.event.comment.user.login }}!
94-
: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
99+
:cry: No one approved your run yet! Have someone from the @${context.repo.owner}/${{ inputs.team-name }} team ${isFailure ? 'comment' : 'run'} \`${{ inputs.approve-command }}\` and then try your command again
95100
96-
_:no_entry_sign: :no_entry: Marking the [workflow run](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) as failed_
97-
`
98-
await github.rest.issues.createComment({
99-
issue_number: context.issue.number,
100-
owner: context.repo.owner,
101-
repo: context.repo.repo,
102-
body: commentBody
103-
})
104-
105-
- if: ${{ steps.check-approval.outputs.approved == 'false' && inputs.fail-if-approval-not-found == 'false' }}
106-
name: Create completed comment
107-
uses: actions/github-script@v6
108-
with:
109-
github-token: ${{ inputs.token }}
110-
script: |
111-
let commentBody = `Hey, @${{ github.event.comment.user.login }}!
112-
: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
113-
114-
_:warning: :pause_button: See [workflow run](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) for reference_
115-
`
101+
${statusLine}
102+
`;
103+
116104
await github.rest.issues.createComment({
117105
issue_number: context.issue.number,
118106
owner: context.repo.owner,

0 commit comments

Comments
 (0)