1
1
#! /bin/bash
2
2
3
- set -e
3
+ # Fail script on errors, print each command
4
+ set -euo pipefail
5
+ set -x # Enable command echoing for debug
4
6
5
- # Fallback defaults (optional safety)
7
+ # Fallback defaults
6
8
COMMIT_TIME=" ${COMMIT_TIME:- Unknown} "
7
9
COMMIT_MSG=" ${COMMIT_MSG:- (no message)} "
8
10
SUMMARY=" ${SUMMARY:- No summary provided.} "
9
11
RESULTS=" ${RESULTS:- } "
12
+ REPO=" ${REPO:- } "
13
+ SHA=" ${SHA:- } "
10
14
11
- # Format commit message to escape backticks or special chars
15
+ # Format commit message to escape backticks or special characters
12
16
ESCAPED_MSG=$( echo " $COMMIT_MSG " | sed ' s/`/\\`/g' )
13
17
14
- # If no validation results, say so
18
+ # If no validation results, provide a placeholder
15
19
if [[ -z " $RESULTS " ]]; then
16
20
RESULTS=" _No files were validated in this run._"
17
21
fi
18
22
23
+ # Construct markdown comment
19
24
COMMENT=" $( cat << EOF
20
25
🧪 **KubeCheck Validation Results**
21
26
@@ -30,13 +35,23 @@ ${RESULTS}
30
35
EOF
31
36
) "
32
37
33
- # Print for debug
38
+ # Print comment preview for log/debugging
39
+ echo " Generated comment content:"
34
40
echo " $COMMENT "
35
41
36
- # Escape for JSON and send
42
+ # Escape for JSON
37
43
jq -n --arg body " $COMMENT " ' {body: $body}' > comment.json
38
44
45
+ # Perform the API call and capture HTTP response
46
+ RESPONSE_FILE=" curl_response.log"
47
+
39
48
curl -s -X POST " https://api.github.com/repos/${REPO} /commits/${SHA} /comments" \
40
- -H " Authorization: token ${GH_TOKEN } " \
49
+ -H " Authorization: token ${GITHUB_TOKEN } " \
41
50
-H " Content-Type: application/json" \
42
- --data-binary @comment.json
51
+ --data-binary @comment.json \
52
+ -w " \n\nHTTP Status: %{http_code}\n" \
53
+ -o " $RESPONSE_FILE "
54
+
55
+ # Output the response content to logs
56
+ echo " GitHub API response:"
57
+ cat " $RESPONSE_FILE "
0 commit comments