@@ -1109,10 +1109,86 @@ EOF
11091109 }
11101110 }
11111111 /* ######################
1112- Send status to Discord
1112+ Comment on PR (failed test) and Send status to Discord
11131113 ###################### */
11141114 post {
11151115 always {
1116+ if (env. EXIT_STATUS != " ABORTED" ){
1117+ if (currentBuild. currentResult != " SUCCESS" ){
1118+ if (env. GITHUBIMAGE =~ / lspipepr/ ){
1119+ if (env. CI_TEST_ATTEMPTED == " true" ){
1120+ sh ''' #! /bin/bash
1121+ # Function to retrieve JSON data from URL
1122+ get_json() {
1123+ local url="$1"
1124+ local response=$(curl -s "$url")
1125+ if [ $? -ne 0 ]; then
1126+ echo "Failed to retrieve JSON data from $url"
1127+ return 1
1128+ fi
1129+ local json=$(echo "$response" | jq .)
1130+ if [ $? -ne 0 ]; then
1131+ echo "Failed to parse JSON data from $url"
1132+ return 1
1133+ fi
1134+ echo "$json"
1135+ }
1136+
1137+ build_table() {
1138+ local data="$1"
1139+
1140+ # Get the keys in the JSON data
1141+ local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1142+
1143+ # Check if keys are empty
1144+ if [ -z "$keys" ]; then
1145+ echo "JSON report data does not contain any keys or the report does not exist."
1146+ return 1
1147+ fi
1148+
1149+ # Build table header
1150+ local header="| Tag | Passed |\\ n| --- | --- |\\ n"
1151+
1152+ # Loop through the JSON data to build the table rows
1153+ local rows=""
1154+ for build in $keys; do
1155+ local status=$(echo "$data" | jq -r ".[\\ "$build\\ "].test_success")
1156+ if [ "$status" = "true" ]; then
1157+ status="✅"
1158+ else
1159+ status="❌"
1160+ fi
1161+ local row="| "$build" | "$status" |\\ n"
1162+ rows="${rows}${row}"
1163+ done
1164+
1165+ local table="${header}${rows}"
1166+ local escaped_table=$(echo "$table" | sed 's/\" /\\\\ "/g')
1167+ echo "$escaped_table"
1168+ }
1169+
1170+ if [[ "${CI}" = "true" ]]; then
1171+ # Retrieve JSON data from URL
1172+ data=$(get_json "$CI_JSON_URL")
1173+ # Create table from JSON data
1174+ table=$(build_table "$data")
1175+ echo -e "$table"
1176+
1177+ curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1178+ -H "Accept: application/vnd.github.v3+json" \
1179+ "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1180+ -d "{\\ "body\\ ": \\ "I am a bot, here are the test results for this PR: \\ n${CI_URL}\\ n${SHELLCHECK_URL}\\ n${table}\\ "}"
1181+ else
1182+ curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1183+ -H "Accept: application/vnd.github.v3+json" \
1184+ "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1185+ -d "{\\ "body\\ ": \\ "I am a bot, here is the pushed image/manifest for this PR: \\ n\\ n\\ `${GITHUBIMAGE}:${META_TAG}\\ `\\ "}"
1186+ fi
1187+ '''
1188+ }
1189+ }
1190+ }
1191+ }
11161192 sh ''' #!/bin/bash
11171193 rm -rf /config/.ssh/id_sign
11181194 rm -rf /config/.ssh/id_sign.pub
0 commit comments