-
Notifications
You must be signed in to change notification settings - Fork 1
88 lines (82 loc) · 3.77 KB
/
notify-issue.yml
File metadata and controls
88 lines (82 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Notify on Issue Events
on:
issues:
types: [opened, closed, edited]
issue_comment:
types: [created]
permissions:
issues: read
jobs:
notify-on-issue:
if: ${{ github.actor != github.repository_owner }}
runs-on: ubuntu-latest
steps:
- name: Get Embed
id: get-embed
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_STATE: ${{ github.event.issue.state }}
ISSUE_LABELS: ${{ toJson(github.event.issue.labels) }}
COMMENT_BODY: ${{ github.event.comment.body }}
EVENT_ACTION: ${{ github.event.action }}
run: |
# Create individual field objects
FIELD_NUMBER=$(jq -nc --arg value "$ISSUE_NUMBER" \
'{"name":"#️⃣ Number","value":$value, "inline": true}')
FIELD_STATE=$(jq -nc --arg value "$ISSUE_STATE" \
'{"name":"📋 State","value":$value, "inline": true}')
FIELD_LABELS=$(jq -nc --argjson value "$ISSUE_LABELS" \
'{"name":"🏷️ Labels","value":($value | map(.name) | join(", ")), "inline": false}')
# Add comment/update field if applicable
if [ "$EVENT_ACTION" = "created" ] && [ -n "$COMMENT_BODY" ]; then
FIELD_COMMENT=$(jq -nc --arg value "$COMMENT_BODY" --arg user "$GITHUB_ACTOR" \
'{"name":"💬 Comment from \($user)","value":$value, "inline": false}')
FIELDS_JSON=$(jq -nc \
--argjson number "$FIELD_NUMBER" \
--argjson state "$FIELD_STATE" \
--argjson labels "$FIELD_LABELS" \
--argjson comment "$FIELD_COMMENT" \
'[$number, $state, $labels, $comment]')
elif [ "$EVENT_ACTION" = "edited" ]; then
FIELD_UPDATE=$(jq -nc --arg value "Issue was updated by $GITHUB_ACTOR" \
'{"name":"✏️ Update","value":$value, "inline": false}')
FIELDS_JSON=$(jq -nc \
--argjson number "$FIELD_NUMBER" \
--argjson state "$FIELD_STATE" \
--argjson labels "$FIELD_LABELS" \
--argjson update "$FIELD_UPDATE" \
'[$number, $state, $labels, $update]')
else
FIELDS_JSON=$(jq -nc \
--argjson number "$FIELD_NUMBER" \
--argjson state "$FIELD_STATE" \
--argjson labels "$FIELD_LABELS" \
'[$number, $state, $labels]')
fi
echo "fields_json=$FIELDS_JSON" >> $GITHUB_OUTPUT
- name: Check for Discord Webhook URL
id: discord-check
run: |
if [ -z "${{ secrets.DISCORD_WEBHOOK_URL }}" ]; then
echo "::warning::DISCORD_WEBHOOK_URL is not set."
echo "has_webhook=false" >> $GITHUB_OUTPUT
else
echo "::notice::DISCORD_WEBHOOK_URL is set."
echo "has_webhook=true" >> $GITHUB_OUTPUT
fi
- name: Send Message to Discord
if: ${{ steps.discord-check.outputs.has_webhook == 'true' }}
uses: chase-roohms/discord-notify@v1
with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: ${{ github.repository }}
avatar_url: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
embed-titles: "Issue: ${{ github.event.issue.title }}"
embed-descriptions: ${{ github.event.issue.body }}
embed-urls: ${{ github.event.issue.html_url }}
embed-colors: "#E5A00D"
embed-fields: ${{ steps.get-embed.outputs.fields_json }}
embed-authors: ${{ github.event.issue.user.login }}
embed-author-urls: ${{ github.event.issue.user.html_url }}
embed-author-icons: ${{ github.event.issue.user.avatar_url }}
embed-timestamps: 'now'