Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Doeunnkimm committed Jun 25, 2024
1 parent 9ea0504 commit c7c03e9
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions .github/workflows/slack-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ jobs:
name: Send Slack Notification
runs-on: ubuntu-latest
steps:
- name: Determine color for PR creation
id: determine_color_pr
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "color=good" >> $GITHUB_ENV
elif [ "${{ job.status }}" == "failure" ]; then
echo "color=danger" >> $GITHUB_ENV
else
echo "color=warning" >> $GITHUB_ENV
fi
- name: Send Slack Notification for PR creation
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
uses: 8398a7/action-slack@v3
Expand All @@ -19,10 +31,9 @@ jobs:
fields: author,pullRequest
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `Actor: ${process.env.AS_AUTHOR}
PR: ${process.env.AS_PULL_REQUEST}`,
"attachments": [{
"color": "${{ env.color }}",
"text": "Actor: ${{ github.actor }}\nPR: ${{ github.event.pull_request.html_url }}"
}]
}
env:
Expand All @@ -33,41 +44,51 @@ jobs:
if: github.event_name == 'issue_comment'
run: |
mentions=$(echo "${{ github.event.comment.body }}" | grep -o '@[[:alnum:]_-]\+' | paste -sd ' ' -)
echo "::set-output name=mentions::$mentions"
echo "mentions=$mentions" >> $GITHUB_ENV
- name: Map GitHub mentions to Slack user IDs
id: map_to_slack_ids
if: github.event_name == 'issue_comment'
run: |
declare -A slack_ids
slack_ids=(["@Doeunnkimm"]="U07600UQG3T" ["@semnil5202"]="U075KR29RGR" ["@Andrevile"]="U07545VMS21" ["@LeeJeongHooo"]="U075C1A16LT")
mentions="${{ steps.extract_mentions_comment.outputs.mentions }}"
mentions="${{ env.mentions }}"
slack_mentions=""
for mention in $mentions; do
if [[ -n "${slack_ids[$mention]}" ]]; then
slack_mentions="$slack_mentions <@${slack_ids[$mention]}>"
fi
done
echo "::set-output name=slack_mentions::$slack_mentions"
echo "slack_mentions=$slack_mentions" >> $GITHUB_ENV
- name: Determine color for comment mention
id: determine_color_comment
if: github.event_name == 'issue_comment' && env.slack_mentions != ''
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "color=good" >> $GITHUB_ENV
elif [ "${{ job.status }}" == "failure" ]; then
echo "color=danger" >> $GITHUB_ENV
else
echo "color=warning" >> $GITHUB_ENV
fi
- name: Send Slack Notification for comment if team members mentioned
if: ${{ github.event_name == 'issue_comment' && steps.map_to_slack_ids.outputs.slack_mentions != '' }}
if: github.event_name == 'issue_comment' && env.slack_mentions != ''
uses: 8398a7/action-slack@v3
with:
status: custom
fields: pullRequest
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_PULL_REQUEST} μ—μ„œ ${{ steps.map_to_slack_ids.outputs.slack_mentions }} λ‹˜μ„ μ–ΈκΈ‰ν–ˆμŠ΅λ‹ˆλ‹€.
κΌ­ λ‚˜μ€‘μ— λ“€μ–΄κ°€μ„œ ν™•μΈν•˜κΈ°!
λ©”μ‹œμ§€: ${{ github.event.comment.body }}`,
"attachments": [{
"color": "${{ env.color }}",
"text": "${{ github.event.pull_request.html_url }} μ—μ„œ ${{ env.slack_mentions }} λ‹˜μ„ μ–ΈκΈ‰ν–ˆμŠ΅λ‹ˆλ‹€.\nκΌ­ λ‚˜μ€‘μ— λ“€μ–΄κ°€μ„œ ν™•μΈν•˜κΈ°!\nλ©”μ‹œμ§€: ${{ github.event.comment.body }}"
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

- name: Debug mentions
if: ${{ github.event_name == 'issue_comment' && steps.map_to_slack_ids.outputs.slack_mentions == '' }}
if: github.event_name == 'issue_comment' && env.slack_mentions == ''
run: echo "No team members mentioned in the comment."

0 comments on commit c7c03e9

Please sign in to comment.