Skip to content

Commit 2393d05

Browse files
committed
Refactor Vale review script to handle large JSON objects
Attempts to resolve "Argument list too long"
1 parent ab5d1cd commit 2393d05

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

scripts/prow-vale-review.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,24 @@ function get_vale_errors {
5555
local vale_json="$1"
5656
local pull_comments_json="$2"
5757

58+
# Create temp files to avoid shell argument size limits
59+
# Hopefully fixes arg size error...
60+
local vale_file=$(mktemp)
61+
local comments_file=$(mktemp)
62+
echo "$vale_json" > "$vale_file"
63+
echo "$pull_comments_json" > "$comments_file"
64+
5865
# jq map and filter to retain only Vale alerts that don't already have a corresponding review comment on the PR
59-
updated_vale_json=$(jq -n --argjson vale "$vale_json" --argjson comments "$pull_comments_json" '$vale | map(select(. as $v | $comments | any(.path == $v.path and .line == $v.line and .body == $v.body) | not))' | jq)
60-
66+
# read json from temp files
67+
updated_vale_json=$(jq -n \
68+
--slurpfile vale "$vale_file" \
69+
--slurpfile comments "$comments_file" \
70+
'$vale[0] | map(select(. as $v | $comments[0] | any(.path == $v.path and .line == $v.line and .body == $v.body) | not))')
71+
72+
# clean up
73+
rm -f "$vale_file" "$comments_file"
74+
6175
export updated_vale_json
62-
6376
}
6477

6578
# Run vale with the custom template on updated files and determine if a review comment should be posted
@@ -87,7 +100,7 @@ do
87100
echo "Vale errors found in the file..."
88101

89102
#Check if Vale review comments already exist in the PR
90-
pull_comments_json=$(curl -L -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 | jq)
103+
pull_comments_json=$(curl -L -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?per_page=100" | jq)
91104

92105
# If there are existing comments in the response, compare with Vale errors, otherwise proceed with existing Vale errors
93106
if [[ "$pull_comments_json" != "[]" ]]; then

0 commit comments

Comments
 (0)