|
17 | 17 |
|
18 | 18 | FILES=$(git diff --name-only HEAD~1 HEAD --diff-filter=d "*.adoc" ':(exclude)_unused_topics/*' ':(exclude)rest_api/*' ':(exclude)microshift_rest_api/*' ':(exclude)modules/virt-runbook-*' ':(exclude)modules/oc-by-example-content.adoc' ':(exclude)modules/oc-adm-by-example-content.adoc' ':(exclude)monitoring/config-map-reference-for-the-cluster-monitoring-operator.adoc' ':(exclude)modules/microshift-oc-adm-by-example-content.adoc' ':(exclude)modules/microshift-oc-by-example-content.adoc') |
19 | 19 |
|
20 | | -function post_review_comment { |
21 | 20 |
|
| 21 | +function post_review_comment { |
22 | 22 | LINE_NUMBER=$3 |
23 | 23 | BODY=$1 |
24 | 24 | FILENAME=$2 |
25 | | - echo "Sending review comment curl request..." |
| 25 | + SUBJECT_TYPE=${4:-"line"} # Default to "line", but will use "file" for file-level comments |
26 | 26 | # Use jq to excruciatingly craft JSON payload |
27 | 27 | # jq -n because we're constructing from scratch per https://jqlang.org/manual/ |
28 | 28 | # --arg for string, --argjson for integer |
29 | 29 | # body constructed from https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request |
30 | | - payload=$(jq -n \ |
31 | | - --arg body "$BODY" \ |
32 | | - --arg commit_id "$COMMIT_ID" \ |
33 | | - --arg path "$FILENAME" \ |
34 | | - --argjson line "$LINE_NUMBER" \ |
35 | | - '{body: $body, commit_id: $commit_id, path: $path, line: $line, side: "RIGHT"}') |
| 30 | + |
| 31 | + echo "Sending review comment curl request..." |
| 32 | + if [[ "$SUBJECT_TYPE" == "file" ]]; then |
| 33 | + # File-level comment - no diff to apply to |
| 34 | + payload=$(jq -n \ |
| 35 | + --arg body "$BODY" \ |
| 36 | + --arg commit_id "$COMMIT_ID" \ |
| 37 | + --arg path "$FILENAME" \ |
| 38 | + '{body: $body, commit_id: $commit_id, path: $path, subject_type: "file"}') |
| 39 | + else |
| 40 | + # Line-level comment |
| 41 | + payload=$(jq -n \ |
| 42 | + --arg body "$BODY" \ |
| 43 | + --arg commit_id "$COMMIT_ID" \ |
| 44 | + --arg path "$FILENAME" \ |
| 45 | + --argjson line "$LINE_NUMBER" \ |
| 46 | + '{body: $body, commit_id: $commit_id, path: $path, line: $line, side: "RIGHT"}') |
| 47 | + fi |
| 48 | + |
36 | 49 | echo "DEBUG payload:" "$payload" |
37 | 50 | curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_AUTH_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/openshift/openshift-docs/pulls/$PULL_NUMBER/comments -d "$payload" |
38 | 51 | } |
|
103 | 116 | FILENAME=$(echo "$object" | jq -r '.path') |
104 | 117 | LINE_NUMBER=$(echo "$object" | jq -r '.line') |
105 | 118 |
|
106 | | - # Line 1 errors are file-level issues. Always post these! |
| 119 | + # Line 1 errors from Vale likely to be file-level issues - post as file-level comment |
107 | 120 | if [[ "$LINE_NUMBER" -eq 1 ]]; then |
108 | | - post_review_comment "$BODY" "$FILENAME" "$LINE_NUMBER" |
| 121 | + post_review_comment "$BODY" "$FILENAME" "" "file" |
109 | 122 | sleep 1 |
110 | 123 | continue |
111 | 124 | fi |
|
163 | 176 | done |
164 | 177 |
|
165 | 178 | done |
166 | | - |
|
0 commit comments