-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgitlab.sh
33 lines (30 loc) · 1.06 KB
/
gitlab.sh
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
#!/bin/bash
send_message() {
curl \
--data-urlencode "text=$1" \
--data-urlencode "parse_mode=HTML" \
--data-urlencode "chat_id=$CHAT_ID" \
--data-urlencode "disable_web_page_preview=true" \
-X POST \
https://api.telegram.org/bot$BOT_TOKEN/sendMessage;
}
escape_html () {
local s
s=${@//&/&}
s=${s//</<}
s=${s//>/>}
echo -n $s
}
INSTANCE_URL="https://git.vanutp.dev"
REPO_LINK="$INSTANCE_URL/$CI_PROJECT_PATH"
COMMIT_LINK="$REPO_LINK/-/commit/$CI_COMMIT_SHA"
BUILD_LINK="<a href=\"$(escape_html $REPO_LINK/-/pipelines/$CI_PIPELINE_ID)\">#$CI_PIPELINE_ID</a>"
COMMIT="<a href=\"$(escape_html $COMMIT_LINK)\">${CI_COMMIT_SHA::7}</a>"
REPO="<a href=\"$(escape_html $REPO_LINK)\">$(escape_html $CI_PROJECT_PATH)</a>"
if [[ $1 == "--start" ]]; then
send_message "⚙️ Pipeline $BUILD_LINK for $REPO (commit $COMMIT) started."
elif [[ $1 == "--fail" ]]; then
send_message "❌ Pipeline $BUILD_LINK for $REPO (commit $COMMIT) failed!"
else
send_message "✅ Pipeline $BUILD_LINK for $REPO (commit $COMMIT) succeed!"
fi