-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (125 loc) · 4.5 KB
/
discord.yml
File metadata and controls
135 lines (125 loc) · 4.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Notifications Discord
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: discord-${{ github.ref }}
cancel-in-progress: true
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Préparer les données
id: prep
env:
EVENT_NAME: ${{ github.event_name }}
REPOSITORY: ${{ github.repository }}
ACTOR: ${{ github.actor }}
REF_NAME: ${{ github.ref_name }}
SHA: ${{ github.sha }}
COMPARE_URL: ${{ github.event.compare }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
MODIFIED_FILES: ${{ join(github.event.head_commit.modified, ', ') }}
ADDED_FILES: ${{ join(github.event.head_commit.added, ', ') }}
REMOVED_FILES: ${{ join(github.event.head_commit.removed, ', ') }}
run: |
SHORT_SHA="${SHA::7}"
if [ "$EVENT_NAME" = "push" ]; then
TITLE="Nouveau push"
COLOR=5763719
URL="${COMPARE_URL:-https://github.com/$REPOSITORY}"
MESSAGE="${COMMIT_MESSAGE:-"(pas de message disponible)"}"
else
TITLE="Test manuel du workflow"
COLOR=16776960
URL="https://github.com/$REPOSITORY/actions"
MESSAGE="Exécution déclenchée manuellement"
fi
limit_text () {
value="$1"
if [ -z "$value" ]; then
printf 'Aucun'
elif [ ${#value} -gt 900 ]; then
printf '%s…' "$(printf '%s' "$value" | cut -c1-900)"
else
printf '%s' "$value"
fi
}
MODIFIED="$(limit_text "$MODIFIED_FILES")"
ADDED="$(limit_text "$ADDED_FILES")"
REMOVED="$(limit_text "$REMOVED_FILES")"
MESSAGE="$(limit_text "$MESSAGE")"
{
echo "title=$TITLE"
echo "color=$COLOR"
echo "url=$URL"
echo "short_sha=$SHORT_SHA"
echo "message<<EOF"
echo "$MESSAGE"
echo "EOF"
echo "modified<<EOF"
echo "$MODIFIED"
echo "EOF"
echo "added<<EOF"
echo "$ADDED"
echo "EOF"
echo "removed<<EOF"
echo "$REMOVED"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Envoyer la notification Discord
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
TITLE: ${{ steps.prep.outputs.title }}
COLOR: ${{ steps.prep.outputs.color }}
URL: ${{ steps.prep.outputs.url }}
SHORT_SHA: ${{ steps.prep.outputs.short_sha }}
MESSAGE: ${{ steps.prep.outputs.message }}
MODIFIED: ${{ steps.prep.outputs.modified }}
ADDED: ${{ steps.prep.outputs.added }}
REMOVED: ${{ steps.prep.outputs.removed }}
REPOSITORY: ${{ github.repository }}
ACTOR: ${{ github.actor }}
REF_NAME: ${{ github.ref_name }}
run: |
jq -n \
--arg username "GitHub" \
--arg title "$TITLE" \
--arg url "$URL" \
--arg repo "$REPOSITORY" \
--arg actor "$ACTOR" \
--arg branch "$REF_NAME" \
--arg sha "$SHORT_SHA" \
--arg msg "$MESSAGE" \
--arg modified "$MODIFIED" \
--arg added "$ADDED" \
--arg removed "$REMOVED" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--argjson color "$COLOR" \
'{
username: $username,
embeds: [
{
title: $title,
url: $url,
color: $color,
timestamp: $timestamp,
fields: [
{name: "Dépôt", value: $repo, inline: true},
{name: "Auteur", value: $actor, inline: true},
{name: "Branche", value: $branch, inline: true},
{name: "Commit", value: $sha, inline: true},
{name: "Message", value: $msg, inline: false},
{name: "Modifiés", value: $modified, inline: false},
{name: "Ajoutés", value: $added, inline: false},
{name: "Supprimés", value: $removed, inline: false}
]
}
]
}' > payload.json
curl -sS -H "Content-Type: application/json" \
-X POST \
-d @payload.json \
"$DISCORD_WEBHOOK_URL"