Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ZedThree/clang-tidy-review
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.18.0
Choose a base ref
...
head repository: ZedThree/clang-tidy-review
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.19.0
Choose a head ref
  • 6 commits
  • 5 files changed
  • 4 contributors

Commits on Apr 5, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    65fbe78 View commit details

Commits on May 5, 2024

  1. Add clang-tidy 18

    Switch to Ubuntu 24.04
    Remove version 13 as it's no longer available
    daljit46 committed May 5, 2024
    Copy the full SHA
    9bde8c5 View commit details

Commits on May 11, 2024

  1. Add links to check documentation in review

    bwrsandman committed May 11, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    Copy the full SHA
    dbe658e View commit details

Commits on May 13, 2024

  1. Merge pull request #123 from bwrsandman/links-in-comments

    Add links to check documentation in review
    ZedThree authored May 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3ff13b4 View commit details
  2. Merge pull request #121 from daljit46/clang_tidy_18

    Add clang-tidy 18
    ZedThree authored May 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b719737 View commit details
  3. Merge pull request #120 from m-kuhn/patch-1

    Add a hint for generating the compile command outside the container
    ZedThree authored May 13, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    85799d6 View commit details
Showing with 76 additions and 12 deletions.
  1. +3 −2 Dockerfile
  2. +7 −4 README.md
  3. +2 −2 action.yml
  4. +29 −4 post/clang_tidy_review/clang_tidy_review/__init__.py
  5. +35 −0 tests/test_review.py
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM ubuntu:23.04
FROM ubuntu:24.04

RUN apt update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends\
build-essential cmake git \
tzdata \
clang-tidy-13 \
clang-tidy-14 \
clang-tidy-15 \
clang-tidy-16 \
clang-tidy-17 \
clang-tidy-18 \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -88,9 +88,8 @@ at once, so `clang-tidy-review` will only attempt to post the first
- `base_dir`: Absolute path to initial working directory
`GITHUB_WORKSPACE`.
- default: `GITHUB_WORKSPACE`
- `clang_tidy_version`: Version of clang-tidy to use; one of
13, 14, 15, 16
- default: '16'
- `clang_tidy_version`: Version of clang-tidy to use; one of 14, 15, 16, 17, 18
- default: '18'
- `clang_tidy_checks`: List of checks
- default: `'-*,performance-*,readability-*,bugprone-*,clang-analyzer-*,cppcoreguidelines-*,mpi-*,misc-*'`
- `config_file`: Path to clang-tidy config file, replaces `clang_tidy_checks`
@@ -123,7 +122,7 @@ at once, so `clang-tidy-review` will only attempt to post the first

- `total_comments`: Total number of warnings from clang-tidy

## Generating `compile_commands.json` inside the container
## Generating `compile_commands.json`

Very simple projects can get away without a `compile_commands.json`
file, but for most projects `clang-tidy` needs this file in order to
@@ -158,6 +157,10 @@ jobs:
If you don't use CMake, this may still work for you if you can use a
tool like [bear](https://github.com/rizsotto/Bear) for example.

You can also generate this file outside the container, e.g. by adding
`-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` to a cmake command in an earlier
action and omitting the `cmake_command` paramter.

## Use in a non-default location

If you're using the `container` argument in your GitHub workflow,
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ inputs:
default: ${{ github.workspace }}
require: false
clang_tidy_version:
description: 'Version of clang-tidy to use; one of 13, 14, 15, 16'
default: '16'
description: 'Version of clang-tidy to use; one of 14, 15, 16, 17, 18'
default: '18'
required: false
clang_tidy_checks:
description: 'List of checks'
33 changes: 29 additions & 4 deletions post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
@@ -1085,6 +1085,29 @@ def set_output(key: str, val: str) -> bool:
return True


def decorate_comment_body(comment: str) -> str:
"""
Split on first dash into two groups of string in [] at end of line
exception: if the first group starts with 'clang' such as 'clang-diagnostic-error'
exception to the exception: if the string starts with 'clang-analyzer', in which case, make it the first group
"""
version = "extra"
url = f"https://clang.llvm.org/{version}/clang-tidy/checks"
regex = r"(\[((?:clang-analyzer)|(?:(?!clang)[\w]+))-([\.\w-]+)\]$)"
subst = f"[\\g<1>({url}/\\g<2>/\\g<3>.html)]"
return re.sub(regex, subst, comment, 1, re.MULTILINE)


def decorate_comment(comment: PRReviewComment) -> PRReviewComment:
comment["body"] = decorate_comment_body(comment["body"])
return comment


def decorate_comments(review: PRReview) -> PRReview:
review["comments"] = list(map(decorate_comment, review["comments"]))
return review


def post_review(
pull_request: PullRequest,
review: Optional[PRReview],
@@ -1104,21 +1127,23 @@ def post_review(

total_comments = len(review["comments"])

set_output("total_comments", total_comments)
set_output("total_comments", str(total_comments))

print("Removing already posted or extra comments", flush=True)
trimmed_review = cull_comments(pull_request, review, max_comments)

if trimmed_review["comments"] == []:
if not trimmed_review["comments"]:
print("Everything already posted!")
return total_comments

if dry_run:
pprint.pprint(review, width=130)
return total_comments

print("Posting the review:\n", pprint.pformat(trimmed_review), flush=True)
pull_request.post_review(trimmed_review)
decorated_review = decorate_comments(trimmed_review)

print("Posting the review:\n", pprint.pformat(decorated_review), flush=True)
pull_request.post_review(decorated_review)

return total_comments

35 changes: 35 additions & 0 deletions tests/test_review.py
Original file line number Diff line number Diff line change
@@ -427,3 +427,38 @@ def test_config_file(monkeypatch, tmp_path):
"not-clang-tidy", clang_tidy_checks="readability", config_file=""
)
assert flag == "--checks=readability"


def test_decorate_comment_body():
# No link to generic error so the message shouldn't be changed
error_message = (
"warning: no member named 'ranges' in namespace 'std' [clang-diagnostic-error]"
)
assert ctr.decorate_comment_body(error_message) == error_message

todo_message = "warning: missing username/bug in TODO [google-readability-todo]"
todo_message_decorated = "warning: missing username/bug in TODO [[google-readability-todo](https://clang.llvm.org/extra/clang-tidy/checks/google/readability-todo.html)]"
assert ctr.decorate_comment_body(todo_message) == todo_message_decorated

naming_message = "warning: invalid case style for constexpr variable 'foo' [readability-identifier-naming]"
naming_message_decorated = "warning: invalid case style for constexpr variable 'foo' [[readability-identifier-naming](https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html)]"
assert ctr.decorate_comment_body(naming_message) == naming_message_decorated

clang_analyzer_message = "warning: Array access (from variable 'foo') results in a null pointer dereference [clang-analyzer-core.NullDereference]"
clang_analyzer_message_decorated = "warning: Array access (from variable 'foo') results in a null pointer dereference [[clang-analyzer-core.NullDereference](https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer/core.NullDereference.html)]"
assert (
ctr.decorate_comment_body(clang_analyzer_message)
== clang_analyzer_message_decorated
)

# Not sure it's necessary to link to prior version documentation especially since we have to map versions such as
# "17" to "17.0.1" and "18" to "18.1.0" because no other urls exist
# version_message_pre_15_version = "14.0.0"
# version_message_pre_15 = "warning: missing username/bug in TODO [google-readability-todo]"
# version_message_pre_15_decorated = "warning: missing username/bug in TODO [[google-readability-todo](https://releases.llvm.org/14.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/google-readability-todo.html)]"
# assert ctr.decorate_comment_body(version_message_pre_15, version_message_pre_15_version) == version_message_pre_15_decorated
#
# version_message_1500_version = "15.0.0"
# version_message_1500 = "warning: missing username/bug in TODO [google-readability-todo]"
# version_message_1500_decorated = "warning: missing username/bug in TODO [[google-readability-todo](https://releases.llvm.org/15.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/google/readability-todo.html)]"
# assert ctr.decorate_comment_body(version_message_1500, version_message_1500_version) == version_message_1500_decorated