77 notify :
88 runs-on : ubuntu-latest
99 steps :
10- - name : Post each commit (plus merge head)
10+ - name : Post all commits (plus merge) in order
1111 env :
1212 WEBHOOK : ${{ secrets.DISCORD_NOTIFY }}
1313 REPO : ${{ github.repository }}
@@ -19,49 +19,51 @@ jobs:
1919 run : |
2020 set -euo pipefail
2121
22- # Parse commits array
23- echo "$COMMITS_JSON" | jq -e . >/dev/ null 2>&1 || echo '[] ' > commits.json
24- echo "$COMMITS_JSON" > commits .json
22+ # Normalize inputs
23+ echo "${ COMMITS_JSON:-[]} " | jq 'if .== null then [] else . end ' > commits.json
24+ echo "${HEAD_JSON:-null}" | jq '.' > head .json
2525
26- # Ensure head_commit is included once
27- head_id=$(echo "$HEAD_JSON" | jq -r '.id')
28- if ! jq -e --arg id "$head_id" 'map(.id)==null or (map(.id) | index($id) == null) | not' commits.json >/dev/null; then
29- # commits was null, use []
30- echo '[]' > commits.json
31- fi
32- if [ -n "$head_id" ] && ! jq -e --arg id "$head_id" 'map(.id) | index($id)' commits.json >/dev/null; then
33- jq -c --argjson head "$HEAD_JSON" '. + [$head]' commits.json > commits2.json && mv commits2.json commits.json
34- fi
26+ # Combine commits + head_commit, de-dup by id, sort by timestamp
27+ jq -cs '
28+ (.[0] // []) + (if .[1]==null or .[1]=={} then [] else [.[1]] end)
29+ | map(select(.id?))
30+ | unique_by(.id)
31+ | sort_by(.timestamp // "")
32+ ' commits.json head.json > list.json
3533
36- repo_short=$(echo "$REPO" | awk -F/ '{print $2}')
34+ repo_short="$( awk -F/ '{print ($2?$2:$0)}' <<< "$REPO")"
3735
38- # Post each unique commit (by id)
39- jq -c '.[] | {id, message, timestamp, author}' commits.json | while read -r c; do
40- id=$(echo "$c" | jq -r '.id // empty')
41- msg=$(echo "$c" | jq -r '.message // ""')
42- ts=$(echo "$c" | jq -r '.timestamp // empty')
43- login=$(echo "$c" | jq -r '.author.username // empty')
36+ jq -c '.[] | {id, message, timestamp, author}' list.json | while read -r c; do
37+ msg="$(jq -r '.message // ""' <<< "$c")"
38+ ts="$(jq -r '.timestamp // empty' <<< "$c")"
39+ login="$(jq -r '.author.username // empty' <<< "$c")"
4440 [ -z "$login" ] && login="$ACTOR_FALLBACK"
4541
46- # Time formatting
47- # Keep commit timezone for footer; ISO UTC for embed timestamp
48- iso_local="$ts"
49- iso_utc=$(date -u -d "$ts" +"%Y-%m-%dT%H:%M:%SZ")
50- time_str=$(date -d "$ts" +"%-H:%M")
42+ # Time handling
43+ if [ -z "$ts" ] || ! date -d "$ts" >/dev/null 2>&1; then ts="$(date -Iseconds)"; fi
44+ c_date="$(date -u -d "$ts" +"%Y-%m-%d")"
45+ n_date="$(date -u +"%Y-%m-%d")"
46+ time_str="$(date -d "$ts" +"%-H:%M")"
47+ if [ "$c_date" = "$n_date" ]; then
48+ foot_extra="Today $time_str"
49+ else
50+ date_str="$(date -d "$ts" +"%d/%m/%Y")"
51+ foot_extra="$date_str $time_str"
52+ fi
53+ iso_utc="$(date -u -d "$ts" +"%Y-%m-%dT%H:%M:%SZ")"
5154
52- # Build payload
5355 jq -n \
5456 --arg login "$login" \
5557 --arg msg "$msg" \
5658 --arg repo "$repo_short" \
5759 --arg branch "$BRANCH" \
58- --arg foot "$repo_short - $BRANCH • $time_str " \
60+ --arg foot "$repo_short - $BRANCH • $foot_extra " \
5961 --arg iso "$iso_utc" \
6062 '{
6163 username: "GitHub",
6264 avatar_url: "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
6365 embeds: [{
64- color: 0x2F81F7 ,
66+ color: 3113463 ,
6567 author: {
6668 name: $login,
6769 url: ("https://github.com/" + $login),
0 commit comments