|
12 | 12 | fetch-depth: 0 |
13 | 13 | ref: ${{ github.event.pull_request.head.sha }} |
14 | 14 | - name: Run clang-format |
15 | | - shell: bash |
16 | | - run: git clang-format-16 --diff ${{ github.base_ref }} |
| 15 | + run: | |
| 16 | + { |
| 17 | + echo 'CLANG_FORMAT_DIFF<<EOF' |
| 18 | + git clang-format-16 --diff origin/${{ github.base_ref }} || true |
| 19 | + echo EOF |
| 20 | + } >> "$GITHUB_ENV" |
| 21 | + - uses: actions/github-script@v7 |
| 22 | + with: |
| 23 | + script: | |
| 24 | + let commentId = -1 |
| 25 | + for await (const { data : comments } of github.paginate.iterator( |
| 26 | + github.rest.issues.listComments, { |
| 27 | + owner: context.repo.owner, |
| 28 | + repo: context.repo.repo, |
| 29 | + issue_number: context.issue.number |
| 30 | + } |
| 31 | + )) { |
| 32 | + const foundComment = comments.find((comment) => |
| 33 | + comment.body.startsWith( |
| 34 | + '`clang-format` output for this changeset:' |
| 35 | + ) |
| 36 | + ) |
| 37 | + if (foundComment) { |
| 38 | + commentId = foundComment.id |
| 39 | + break |
| 40 | + } |
| 41 | + } |
| 42 | +
|
| 43 | + const { CLANG_FORMAT_DIFF } = process.env |
| 44 | + const commentBody = '`clang-format` output for this changeset:\n```diff\n' + CLANG_FORMAT_DIFF + '\n```' |
| 45 | + if (commentId === -1) { |
| 46 | + await github.rest.issues.createComment({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + issue_number: context.issue.number, |
| 50 | + body: commentBody |
| 51 | + }) |
| 52 | + } else { |
| 53 | + await github.rest.issues.updateComment({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + comment_id: commentId, |
| 57 | + body: commentBody |
| 58 | + }) |
| 59 | + } |
0 commit comments