Skip to content

Commit e441fdc

Browse files
committed
Enhance Telegram notification format with component metadata
1 parent fb1bf83 commit e441fdc

File tree

1 file changed

+89
-13
lines changed

1 file changed

+89
-13
lines changed

.github/workflows/telegram-new-components.yml

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,100 @@ jobs:
3535
exit 0
3636
fi
3737
38-
COMPONENTS="$(git diff --name-status "$BEFORE_SHA" "$AFTER_SHA" -- docs/components \
39-
| awk '$1 == "A" {print $2}' \
40-
| sed -nE \
41-
-e 's#^docs/components/([^/]+)/index\.md$#\1#p' \
42-
-e 's#^docs/components/([^/]+)\.md$#\1#p' \
43-
| grep -v '^index$' \
44-
| sort -u || true)"
45-
46-
if [[ -z "$COMPONENTS" ]]; then
38+
ADDED_COMPONENTS="$(
39+
git diff --name-status "$BEFORE_SHA" "$AFTER_SHA" -- docs/components \
40+
| awk '$1 == "A" {print $2}' \
41+
| while IFS= read -r file; do
42+
slug=""
43+
if [[ "$file" =~ ^docs/components/([^/]+)/index\.md$ ]]; then
44+
slug="${BASH_REMATCH[1]}"
45+
elif [[ "$file" =~ ^docs/components/([^/]+)\.md$ ]]; then
46+
slug="${BASH_REMATCH[1]}"
47+
fi
48+
if [[ -n "$slug" && "$slug" != "index" ]]; then
49+
printf "%s|%s\n" "$slug" "$file"
50+
fi
51+
done \
52+
| awk -F'|' '!seen[$1]++' \
53+
| sort -t'|' -k1,1 || true
54+
)"
55+
56+
if [[ -z "$ADDED_COMPONENTS" ]]; then
4757
echo "has_new_components=false" >> "$GITHUB_OUTPUT"
4858
exit 0
4959
fi
5060
51-
MESSAGE="Добавлены новые компоненты в документацию:\n"
52-
while IFS= read -r slug; do
61+
trim_quotes() {
62+
local value="$1"
63+
value="${value%\"}"
64+
value="${value#\"}"
65+
value="${value%\'}"
66+
value="${value#\'}"
67+
printf "%s" "$value"
68+
}
69+
70+
extract_frontmatter() {
71+
local key="$1"
72+
local file="$2"
73+
awk -v key="$key" '
74+
BEGIN { in_fm = 0 }
75+
/^---[[:space:]]*$/ {
76+
if (in_fm == 0) { in_fm = 1; next }
77+
exit
78+
}
79+
in_fm == 1 {
80+
line = $0
81+
sub(/^[[:space:]]+/, "", line)
82+
if (line ~ ("^" key ":[[:space:]]*")) {
83+
sub("^" key ":[[:space:]]*", "", line)
84+
print line
85+
exit
86+
}
87+
}
88+
' "$file"
89+
}
90+
91+
escape_html() {
92+
local text="$1"
93+
text="${text//&/&}"
94+
text="${text//</&lt;}"
95+
text="${text//>/&gt;}"
96+
text="${text//\"/&quot;}"
97+
printf "%s" "$text"
98+
}
99+
100+
count=0
101+
MESSAGE="Добавлен новый компонент в документацию\n"
102+
while IFS='|' read -r slug file; do
53103
[[ -z "$slug" ]] && continue
54-
MESSAGE+="• <a href=\"https://docs.modx.pro/components/${slug}/\">${slug}</a>\n"
55-
done <<< "$COMPONENTS"
104+
[[ -z "$file" ]] && continue
105+
106+
title="$(extract_frontmatter "title" "$file" || true)"
107+
description="$(extract_frontmatter "description" "$file" || true)"
108+
author="$(extract_frontmatter "author" "$file" || true)"
109+
110+
title="$(trim_quotes "$title")"
111+
description="$(trim_quotes "$description")"
112+
author="$(trim_quotes "$author")"
113+
114+
[[ -z "$title" ]] && title="$slug"
115+
[[ -z "$description" ]] && description="Описание не указано"
116+
[[ -z "$author" ]] && author="Автор не указан"
117+
118+
title="$(escape_html "$title")"
119+
description="$(escape_html "$description")"
120+
author="$(escape_html "$author")"
121+
122+
MESSAGE+="\n<b>${title}</b> — ${description}\n"
123+
MESSAGE+="Автор: ${author}\n"
124+
MESSAGE+="<a href=\"https://docs.modx.pro/components/${slug}/\">Открыть в документации</a>\n"
125+
count=$((count + 1))
126+
done <<< "$ADDED_COMPONENTS"
127+
128+
if [[ "$count" -gt 1 ]]; then
129+
MESSAGE="Добавлены новые компоненты в документацию\n${MESSAGE#*$'\n'}"
130+
fi
131+
56132
MESSAGE+="\nCommit: <a href=\"${{ github.server_url }}/${{ github.repository }}/commit/${AFTER_SHA}\">${AFTER_SHA:0:7}</a>"
57133
58134
echo "has_new_components=true" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)