Skip to content

Commit f5fb3da

Browse files
committed
attempt to use file-level comments for vale's 1:1 errors
1 parent 4cf9fb2 commit f5fb3da

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

scripts/prow-vale-review.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,36 @@ fi
1717

1818
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')
1919

20-
function post_review_comment {
2120

21+
function post_review_comment {
2222
LINE_NUMBER=$3
2323
BODY=$1
2424
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
2626
# Use jq to excruciatingly craft JSON payload
2727
# jq -n because we're constructing from scratch per https://jqlang.org/manual/
2828
# --arg for string, --argjson for integer
2929
# 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+
--arg subject_type "file" \
39+
'{body: $body, commit_id: $commit_id, path: $path, subject_type: $subject_type}')
40+
else
41+
# Line-level comment
42+
payload=$(jq -n \
43+
--arg body "$BODY" \
44+
--arg commit_id "$COMMIT_ID" \
45+
--arg path "$FILENAME" \
46+
--argjson line "$LINE_NUMBER" \
47+
'{body: $body, commit_id: $commit_id, path: $path, line: $line, side: "RIGHT"}')
48+
fi
49+
3650
echo "DEBUG payload:" "$payload"
3751
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"
3852
}
@@ -103,9 +117,9 @@ do
103117
FILENAME=$(echo "$object" | jq -r '.path')
104118
LINE_NUMBER=$(echo "$object" | jq -r '.line')
105119

106-
# Line 1 errors are file-level issues. Always post these!
120+
# Line 1 errors from Vale likely to be file-level issues - post as file-level comment
107121
if [[ "$LINE_NUMBER" -eq 1 ]]; then
108-
post_review_comment "$BODY" "$FILENAME" "$LINE_NUMBER"
122+
post_review_comment "$BODY" "$FILENAME" "" "file"
109123
sleep 1
110124
continue
111125
fi
@@ -163,4 +177,3 @@ do
163177
done
164178

165179
done
166-

0 commit comments

Comments
 (0)