-
-
Notifications
You must be signed in to change notification settings - Fork 92
76 lines (70 loc) · 3.27 KB
/
Copy pathnotify-new-issue.yml
File metadata and controls
76 lines (70 loc) · 3.27 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
name: Notify on Issue Events
on:
issues:
types: [opened, closed, edited]
issue_comment:
types: [created]
permissions:
issues: read
jobs:
notify-new-issue:
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: Send Message to Discord
uses: chase-roohms/discord-notify@v1 # zizmor: ignore[unpinned-uses]
with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }}
username: ${{ github.repository }}
avatar_url: https://avatars.githubusercontent.com/u/262247112
embed-titles: "Issue: ${{ github.event.issue.title }}"
embed-descriptions: ${{ github.event.issue.body }}
embed-urls: ${{ github.event.issue.html_url }}
embed-colors: "#DC2626"
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'