Skip to content

add file-annotations option #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ jobs:
- Default: false
- NOTE: If run on a private repository, then this feature is disabled because the GitHub REST API behaves differently for thread comments on a private repository.

#### `file-annotations`

- **Description**: Set this option to false to disable the use of file annotations as feedback.
- Default: true

#### `database`

- **Description**: The directory containing compilation database (like compile_commands.json) file.
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ branding:
color: "green"
inputs:
thread-comments:
description: Set this option to false to disable the use of thread comments as feedback. Defaults to true.
description: Set this option to false to disable the use of thread comments as feedback. Defaults to false.
required: false
default: false
file-annotations:
description: Set this option to false to disable the use of file annotations as feedback. Defaults to true.
required: false
default: true
style:
description: >
The style rules to use (defaults to 'llvm').
Expand Down Expand Up @@ -88,3 +92,4 @@ runs:
- --thread-comments=${{ inputs.thread-comments }}
- --ignore=${{ inputs.ignore }}
- --database=${{ inputs.database }}
- --file-annotations=${{ inputs.file-annotations }}
18 changes: 14 additions & 4 deletions cpp_linter/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
help="Set this option to false to disable the use of thread comments as feedback."
"Defaults to %(default)s.",
)
cli_arg_parser.add_argument(
"-a",
"--file-annotations",
default="true",
type=lambda input: input.lower() == "true",
help="Set this option to false to disable the use of file annotations as feedback."
"Defaults to %(default)s.",
)


def set_exit_code(override: int = None) -> int:
Expand Down Expand Up @@ -695,7 +703,7 @@ def post_results(use_diff_comments: bool, user_id: int = 41898282):
set_exit_code(1 if checks_passed else 0)


def make_annotations(style: str) -> bool:
def make_annotations(style: str, file_annotations: bool) -> bool:
"""Use github log commands to make annotations from clang-format and
clang-tidy output.

Expand All @@ -709,11 +717,13 @@ def make_annotations(style: str) -> bool:
for note in GlobalParser.format_advice:
if note.replaced_lines:
ret_val = True
log_commander.info(note.log_command(style))
if file_annotations:
log_commander.info(note.log_command(style))
count += 1
for note in GlobalParser.tidy_notes:
ret_val = True
log_commander.info(note.log_command())
if file_annotations:
log_commander.info(note.log_command())
count += 1
logger.info("Created %d annotations", count)
return ret_val
Expand Down Expand Up @@ -818,7 +828,7 @@ def main():
)
if args.thread_comments and thread_comments_allowed:
post_results(False) # False is hard-coded to disable diff comments.
set_exit_code(int(make_annotations(args.style)))
set_exit_code(int(make_annotations(args.style, args.file_annotations)))
end_log_group()


Expand Down