diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml index e0dab4ba3..c5e4d7503 100644 --- a/.github/workflows/check-links.yml +++ b/.github/workflows/check-links.yml @@ -97,24 +97,13 @@ jobs: fi - name: Suggest fixes as review comments - # One suggested change per added line with a fix. Suggestions already on - # the PR (same file, line, and text) are not posted again. - if: steps.check.outputs.broken == 'true' && github.event.pull_request.head.repo.full_name == github.repository + # One suggested change per finding with a fix, kept in sync with the + # findings; see dev/sync-review-comments.sh + if: github.event.pull_request.head.repo.full_name == github.repository env: GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/comments" --paginate \ - --jq '.[] | {path, line, body}' | jq -s . > "$RUNNER_TEMP/posted.json" - jq --slurpfile posted "$RUNNER_TEMP/posted.json" \ - '.comments |= map(select(. as $comment | $posted[0] | index({path: $comment.path, line: $comment.line, body: $comment.body}) | not))' \ - "$RUNNER_TEMP/review.json" > "$RUNNER_TEMP/review-new.json" - - if [ "$(jq '.comments | length' "$RUNNER_TEMP/review-new.json")" -gt 0 ]; then - gh api --method POST "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/reviews" \ - --input "$RUNNER_TEMP/review-new.json" > /dev/null \ - || echo "::warning::Could not post the suggested fixes; they are in the report above" - fi + run: dev/sync-review-comments.sh '`, + `Link: \`${url}\``, + `Problem: ${error}`, + `Fix: \`${fix}\``, + '````suggestion', + source.split(url).join(fix), + '````' + ]; + return { path: file, line, side: 'RIGHT', body: body.join('\n') }; }); - return { - event: 'COMMENT', - body: 'Suggested fixes for the links this PR adds; details in the check-links comment.', - comments - }; + return { event: 'COMMENT', body: '', comments }; } const FORMATTERS = { diff --git a/dev/sync-review-comments.sh b/dev/sync-review-comments.sh new file mode 100755 index 000000000..6ecd7b806 --- /dev/null +++ b/dev/sync-review-comments.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh +# Make a check's suggested-change review comments on a PR match a review.json +# ({comments: [{path, line, start_line?, body}]}): post the new ones, update +# the ones whose text changed, and delete the ones whose finding is gone. +# GitHub sets line to null on comments it could not carry to the new revision, +# so those are deleted too. Comments are matched by file, line, and the +# marker comment on their first line, e.g. "". +# +# Usage: dev/sync-review-comments.sh '