# [PATCH] ci: make the whitespace checker more robust

2 messages from 2020-11-03 to 2020-11-03. Participants: Johannes Schindelin via GitGitGadget, Junio C Hamano.
Thread: https://gitlist.dev/t/54564

## Johannes Schindelin via GitGitGadget, 2020-11-03 15:55

Subject: [PATCH] ci: make the whitespace checker more robust
Message-ID: <pull.778.git.1604418931303.gitgitgadget@gmail.com>
URL: https://gitlist.dev/e/pull.778.git.1604418931303.gitgitgadget%40gmail.com

```
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In 32c83afc2c69 (ci: github action - add check for whitespace errors,
2020-09-22), we introduced a GitHub workflow that automatically checks
Pull Requests for whitespace problems.

However, when affected lines contain one or more double quote
characters, this workflow failed to attach the informative comment
because the Javascript snippet incorrectly interpreted these quotes
instead of using the `git log` output as-is.

Let's fix that.

While at it, let's `await` the result of the `createComment()` function.

Finally, we enclose the log in the comment with ˋˋˋ...ˋˋˋ to avoid
having the diff marker be misinterpreted as an enumeration bullet.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    ci: make the whitespace checker more robust
    
    I noticed that the checker failed to add a comment
    [https://github.com/gitgitgadget/git/runs/1344883313?check_suite_focus=true] 
    in one of my PRs. Turns out that the double-quote characters in the log
    output made it fail.
    
    One thing we discussed earlier whether the log should be pasted as
    pre-formatted text or not, and we fell on the side of not pre-formatting
    it. However, in my tests, this does not look right
    [https://github.com/dscho/git/pull/18#issuecomment-721160985], and it 
    looks much better pre-formatted
    [https://github.com/dscho/git/pull/18#issuecomment-721167209] (even if
    we unfortunately lose the direct link to the commit
    [https://github.com/dscho/git/commit/68317764849af81b17c4b31906da20bdf2c52082]
    ).

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-778%2Fdscho%2Ffix-whitespace-github-workflow-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-778/dscho/fix-whitespace-github-workflow-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/778

 .github/workflows/check-whitespace.yml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
index 9d070b9cdf..80a961716b 100644
--- a/.github/workflows/check-whitespace.yml
+++ b/.github/workflows/check-whitespace.yml
@@ -58,12 +58,14 @@ jobs:
     - name: Add Check Output as Comment
       uses: actions/github-script@v3
       id: add-comment
+      env:
+        log: ${{ steps.check_out.outputs.checkout }}
       with:
         script: |
-            github.issues.createComment({
+            await github.issues.createComment({
               issue_number: context.issue.number,
               owner: context.repo.owner,
               repo: context.repo.repo,
-              body: "Whitespace errors found in workflow ${{ github.workflow }}:\n\n${{ steps.check_out.outputs.checkout }}"
+              body: `Whitespace errors found in workflow ${{ github.workflow }}:\n\n\`\`\`\n${process.env.log.replace(/\\n/g, "\n")}\n\`\`\``
             })
       if: ${{ failure() }}

base-commit: 32c83afc2c69aa51b82aa223f2099389f1f0be0a
-- 
gitgitgadget

```

## Junio C Hamano, 2020-11-03 22:02

Subject: Re: [PATCH] ci: make the whitespace checker more robust
Message-ID: <xmqqsg9qp08x.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqsg9qp08x.fsf%40gitster.c.googlers.com
In-Reply-To: <pull.778.git.1604418931303.gitgitgadget@gmail.com>

```
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:

>     One thing we discussed earlier whether the log should be pasted as
>     pre-formatted text or not, and we fell on the side of not pre-formatting
>     it. However, in my tests, this does not look right
>     [https://github.com/dscho/git/pull/18#issuecomment-721160985], and it 
>     looks much better pre-formatted
>     [https://github.com/dscho/git/pull/18#issuecomment-721167209] (even if
>     we unfortunately lose the direct link to the commit
>     [https://github.com/dscho/git/commit/68317764849af81b17c4b31906da20bdf2c52082]
>     ).

What is shown in the log are lines from the source files that were
checked, and we expect our source files are shown and edited in
monospace with tabwidth=8, I think it does make sense to force the
"pre-formatted" output.

Thanks.

```
