ZedThree / clang-tidy-review

Create a pull request review based on clang-tidy warnings
MIT License
90 stars 45 forks source link

Error while posting empty review output in split workflow mode #59

Closed marcelwa closed 1 year ago

marcelwa commented 2 years ago

It seems like there is bug that occurs when clang-tidy-review tries to post its LGTM message to a dependabot PR. I get the following message on two different PRs where only one of them affects clang-tidy-review:

Traceback (most recent call last):
No warnings to report, LGTM!
  File "/action/review.py", line 205, in <module>
    main(
  File "/action/review.py", line 62, in main
    post_review(pull_request, review, max_comments, lgtm_comment_body, dry_run)
  File "/action/post/clang_tidy_review/__init__.py", line 799, in post_review
    pull_request.post_lgtm_comment(lgtm_comment_body)
  File "/action/post/clang_tidy_review/__init__.py", line 165, in post_lgtm_comment
    self._pull_request.create_issue_comment(body)
  File "/usr/local/lib/python3.10/dist-packages/github/PullRequest.py", line 456, in create_issue_comment
    headers, data = self._requester.requestJsonAndCheck(
  File "/usr/local/lib/python3.10/dist-packages/github/Requester.py", line 353, in requestJsonAndCheck
    return self.__check(
  File "/usr/local/lib/python3.10/dist-packages/github/Requester.py", line 378, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.GithubException: 403 {"message": "Resource not accessible by integration", "documentation_url": "https://docs.github.com/rest/reference/issues#create-an-issue-comment"}

You can find the runs in question here and here.

Thanks for your help!

FlorianReimold commented 2 years ago

I think you have to switch to the split workflow to make this work. The Dependabot doesn't have enough permissions to create reviews in your repository. The same happens with PRs from external forks.

When enabling the split workflow, the GH Action running with Dependabot permissions will only generate a file with the review content. A second workflow running with elevated permissions will then post it. Just check out the main readme, there is an example you can copy to your repo.

marcelwa commented 2 years ago

Thank you for your explanation and recommendation to split the workflow! I did that and while it seems to solve the original issue, a new one now appears. Namely that if no clang-tidy-review-output.json was created by clang-tidy-review, then the uploaded ZIP artifact will only contain the clang-tidy-review-metadata.json which leads to clang-tidy-review/post failing with:

Traceback (most recent call last):
  File "/action/post.py", line 65, in <module>
    main(
  File "/action/post.py", line 30, in main
    review = load_review()
             ^^^^^^^^^^^^^
  File "/action/clang_tidy_review/__init__.py", line 704, in load_review
    with open(REVIEW_FILE, "r") as review_file:
         ^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'clang-tidy-review-output.json'

Here is an example workflow run.