peter-evans / link-checker

A GitHub action for link checking repository Markdown and HTML files
MIT License
49 stars 11 forks source link

How do I comment to the pull request where the link checker failed? #7

Closed tamalsaha closed 5 years ago

tamalsaha commented 5 years ago

Thanks for this GitHub action. I would like to comment to the pr where the link checker was run with the report attached to the comment. I saw your other action https://github.com/peter-evans/commit-comment but I don't see any way to attach a file to the comment.

Is this possible? If not, can this be supported?

Thanks.

peter-evans commented 5 years ago

Interesting idea! Before I make any changes to commit-comment I want to check if I understand what you want to do correctly. Please could you test this workflow and let me know.

name: Check markdown links
on: pull_request
jobs:
  linkChecker:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Link Checker
        uses: peter-evans/link-checker@v1.0.0
        with:
          args: -v -r *
      - name: Add commit comment
        run: |
          git fetch origin $GITHUB_HEAD_REF:$GITHUB_HEAD_REF
          jq -nc \
          --arg body "$(cat ./link-checker/out.md)" \
          '{$body}' | \
          curl -sL  -X POST -d @- \
            -H "Content-Type: application/json" \
            -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
            "https://api.github.com/repos/$GITHUB_REPOSITORY/commits/$(git rev-parse $GITHUB_HEAD_REF)/comments"

If this is what you want to do then I will consider adding an input parameter to commit-comment to set the comment body from a file. Unfortunately, multiline input parameters don't seem to be supported, so reading it directly from file is probably the only option right now.

An alternative to this is annotating links in the PR that are broken. This would require a lot more work to achieve.

tamalsaha commented 5 years ago

Sorry for late reply. We decided to not use the action but rather use the underlying liche tool directly. We need to customize its behavior. So, that was the way to do. https://github.com/appscodelabs/liche/commits/master

For now, I am just using the CI view in Github to find all the broken links.

So, I don't know when I will be able to try your suggestion. Thanks for helping me find the liche tool and your response.

peter-evans commented 5 years ago

No problem. If your PR gets merged I'll update the action to support the new flags you added.

I'll close this issue for now. Please reopen if you have any update or want to continue this discussion.