|
3 | 3 | # To debug the current script, please uncomment the following 'set -x' line |
4 | 4 | #set -x |
5 | 5 |
|
6 | | -# Argument |
7 | | -COMMIT=$1 |
8 | | - |
9 | | -# Get PR number |
10 | | -PR=${GITHUB_REF#"refs/pull/"} |
11 | | -PRNUM=${PR%"/merge"} |
12 | | - |
13 | 6 | # Generate email style commit message |
14 | 7 | PATCHMAIL=$(git show --format=email $1 | checkpatch.pl --no-tree -) |
15 | 8 |
|
16 | | -# Github REST API endpoints |
17 | | -BODY_URL=https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PRNUM}/comments |
18 | | -CODE_URL=https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PRNUM}/comments |
19 | | - |
20 | 9 | # Internal state variables |
21 | 10 | RESULT=0 |
22 | 11 | FOUND=0 |
23 | 12 | MESSAGE= |
24 | 13 |
|
25 | | -# Write message to specific file and line |
26 | | -function post_code_message() |
27 | | -{ |
28 | | - echo "POST to ${CODE_URL} with ${MESSAGE}" |
29 | | - curl ${CODE_URL} -s \ |
30 | | - -H "Authorization: token ${GITHUB_TOKEN}" \ |
31 | | - -H "Content-Type: application/json" \ |
32 | | - -X POST --data "$(cat <<EOF |
33 | | -{ |
34 | | - "commit_id": "$COMMIT", |
35 | | - "path": "${FILE}", |
36 | | - "position": ${LINE}, |
37 | | - "body": "${MESSAGE}" |
38 | | -} |
39 | | -EOF |
40 | | -)" |
41 | | -} |
42 | | - |
43 | | -# Write message to pull-request comment |
44 | | -function post_comment_message() |
45 | | -{ |
46 | | - echo "POST to ${BODY_URL} with ${MESSAGE}" |
47 | | - curl ${BODY_URL} -s \ |
48 | | - -H "Authorization: token ${GITHUB_TOKEN}" \ |
49 | | - -H "Content-Type: application/json" \ |
50 | | - -X POST --data "$(cat <<EOF |
51 | | -{ |
52 | | - "body": ":warning: ${COMMIT} - ${MESSAGE}" |
53 | | -} |
54 | | -EOF |
55 | | -)" |
56 | | -} |
57 | | - |
58 | 14 | # |
59 | 15 | # checkpatch.pl result format |
60 | 16 | # --------------------------- |
|
107 | 63 | else |
108 | 64 | # An empty line means the paragraph is over. |
109 | 65 | if [[ -z $row ]]; then |
110 | | - if [[ ! -z "$GITHUB_TOKEN" ]]; then |
111 | | - echo "Post comment to Github" |
112 | | - if [[ -z $FILE ]]; then |
113 | | - post_comment_message |
114 | | - else |
115 | | - post_code_message |
116 | | - fi |
| 66 | + if [[ -z $FILE ]]; then |
| 67 | + echo "::error ::${MESSAGE}" |
117 | 68 | else |
118 | | - # Output empty line |
119 | | - echo |
| 69 | + echo "::error file=${FILE},line=${LINE}::${MESSAGE}" |
120 | 70 | fi |
| 71 | + # Output empty line |
| 72 | + echo |
121 | 73 |
|
122 | 74 | # Code review found a problem. |
123 | 75 | RESULT=1 |
|
0 commit comments