Skip to content

Commit 68135b6

Browse files
avtikhonkyukhin
authored andcommitted
github-ci: fix commit message for markdown
Found that commit message may consists of special characters which can be used be Markdown as commands, like '`' or '```'. To avoid of it these characters must be changed to some predefined names like for: '\' - BACKSLASH '`' - BACKTICK Also added filter block to avoid of other not known symbols which we could miss. This block converts commit message to HTML and then takes only text from it.
1 parent c19dcdc commit 68135b6

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

.github/actions/send-telegram-notify/action.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,49 @@ runs:
4242
curl -s https://api.github.com/repos/tarantool/tarantool/actions/runs/${{ github.run_id }}/jobs | jq -r '.jobs[0].id' | tee -a $GITHUB_ENV
4343
echo 'EOF' >> $GITHUB_ENV
4444
shell: bash
45+
# convert commit message to single line with marked new lines as 'TELEGRAMNEWLINE'
46+
- env:
47+
COMMIT_MSG: |
48+
${{ github.event.head_commit.message }}
49+
run: |
50+
# Make changes in the commit message to avoid of its fail on Markdown:
51+
# 1. Convert message from multi lines to single line.
52+
# 2. Add backslashes to single quote marks in message.
53+
# 3. Add backslashes to '`' in message.
54+
if ${{ env.OS_IS_FEDORA_OR_RHEL == 'true' }} || ${{ env.KERNEL_NAME == 'Darwin' }} ; then
55+
msg="${COMMIT_MSG//$'\n'/TELEGRAMNEWLINE}"
56+
msg="${msg//$'\\\\'/BACKSLASH}"
57+
msg="${msg//$'\\\''/\'}"
58+
msg="${msg//$'\`'/BACKTICK}"
59+
else
60+
msg="${COMMIT_MSG//$'\n'/TELEGRAMNEWLINE}"
61+
msg="${msg//$'\\'/BACKSLASH}"
62+
msg="${msg//$'\''/\\\'}"
63+
msg="${msg//$'`'/BACKTICK}"
64+
fi
65+
echo 'COMMIT_MSG_LINE<<EOF' >> $GITHUB_ENV
66+
echo "$msg" | tee -a $GITHUB_ENV
67+
echo 'EOF' >> $GITHUB_ENV
68+
shell: bash
69+
# strip Markdown from commit message
70+
- run: |
71+
pip3 install setuptools
72+
pip3 install markdown bs4
73+
echo "Sending commit message part as a single line: ${{ env.COMMIT_MSG_LINE }}"
74+
msg=`python3 -c "import markdown ; \\
75+
from bs4 import BeautifulSoup ; \\
76+
md = markdown.markdown(\"${{ env.COMMIT_MSG_LINE }}\") ; \\
77+
soup = BeautifulSoup(md, features='html.parser') ; \\
78+
print(soup.get_text())"`
79+
echo "Sending commit message part as a single line: $msg"
80+
echo 'COMMIT_MSG<<EOF' >> $GITHUB_ENV
81+
if ${{ env.OS_IS_FEDORA_OR_RHEL == 'true' }} || ${{ env.KERNEL_NAME == 'Darwin' }} ; then
82+
echo $msg | sed "s#TELEGRAMNEWLINE#\\\n#g" | tee -a $GITHUB_ENV
83+
else
84+
echo $msg | sed "s#TELEGRAMNEWLINE#\n#g" | tee -a $GITHUB_ENV
85+
fi
86+
echo 'EOF' >> $GITHUB_ENV
87+
shell: bash
4588
- env:
4689
MSG: |
4790
🔴 Workflow testing failed:
@@ -54,7 +97,7 @@ runs:
5497
Committer: `${{ github.actor }}`
5598
```
5699
---------------- Commit message -------------------
57-
${{ github.event.head_commit.message }}
100+
${{ env.COMMIT_MSG }}
58101
```
59102
run: |
60103
# convert message from multi lines to single line and

0 commit comments

Comments
 (0)