Skip to content

Commit aaa3b1c

Browse files
2bndy5shenxianpeng
andauthored
feat: Add file-annotations option (#59)
* add file-annotations option * Update docs and images (#57) * Update docs and images * Update display size * Update docs and images (#57) * adjust examples in README * add file-annotations option * adjust examples in README Co-authored-by: Peter Shen <[email protected]>
1 parent a820860 commit aaa3b1c

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ The content of the file should be in the following format.
2626
name: cpp-linter
2727

2828
on:
29-
push:
30-
paths-ignore: "docs/**"
3129
pull_request:
32-
paths-ignore: "docs/**"
30+
types: [opened, reopened] # let PR-synchronize events be handled by push events
31+
push:
3332

3433
jobs:
3534
cpp-linter:
@@ -119,6 +118,11 @@ jobs:
119118
- Default: false
120119
- 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.
121120

121+
#### `file-annotations`
122+
123+
- **Description**: Set this option to false to disable the use of file annotations as feedback.
124+
- Default: true
125+
122126
#### `database`
123127

124128
- **Description**: The directory containing compilation database (like compile_commands.json) file.
@@ -140,10 +144,9 @@ to install a certain version of clang-tidy and clang-format.
140144

141145
```yml
142146
on:
143-
push:
144-
paths-ignore: "docs/**"
145147
pull_request:
146-
paths-ignore: "docs/**"
148+
types: [opened, reopened] # let PR-synchronize events be handled by push events
149+
push:
147150

148151
jobs:
149152
cpp-linter:

action.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ branding:
66
color: "green"
77
inputs:
88
thread-comments:
9-
description: Set this option to false to disable the use of thread comments as feedback. Defaults to true.
9+
description: Set this option to false to disable the use of thread comments as feedback. Defaults to false.
1010
required: false
1111
default: false
12+
file-annotations:
13+
description: Set this option to false to disable the use of file annotations as feedback. Defaults to true.
14+
required: false
15+
default: true
1216
style:
1317
description: >
1418
The style rules to use (defaults to 'llvm').
@@ -88,3 +92,4 @@ runs:
8892
- --thread-comments=${{ inputs.thread-comments }}
8993
- --ignore=${{ inputs.ignore }}
9094
- --database=${{ inputs.database }}
95+
- --file-annotations=${{ inputs.file-annotations }}

cpp_linter/run.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@
134134
help="Set this option to false to disable the use of thread comments as feedback."
135135
"Defaults to %(default)s.",
136136
)
137+
cli_arg_parser.add_argument(
138+
"-a",
139+
"--file-annotations",
140+
default="true",
141+
type=lambda input: input.lower() == "true",
142+
help="Set this option to false to disable the use of file annotations as feedback."
143+
"Defaults to %(default)s.",
144+
)
137145

138146

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

697705

698-
def make_annotations(style: str) -> bool:
706+
def make_annotations(style: str, file_annotations: bool) -> bool:
699707
"""Use github log commands to make annotations from clang-format and
700708
clang-tidy output.
701709
@@ -709,11 +717,13 @@ def make_annotations(style: str) -> bool:
709717
for note in GlobalParser.format_advice:
710718
if note.replaced_lines:
711719
ret_val = True
712-
log_commander.info(note.log_command(style))
720+
if file_annotations:
721+
log_commander.info(note.log_command(style))
713722
count += 1
714723
for note in GlobalParser.tidy_notes:
715724
ret_val = True
716-
log_commander.info(note.log_command())
725+
if file_annotations:
726+
log_commander.info(note.log_command())
717727
count += 1
718728
logger.info("Created %d annotations", count)
719729
return ret_val
@@ -818,7 +828,7 @@ def main():
818828
)
819829
if args.thread_comments and thread_comments_allowed:
820830
post_results(False) # False is hard-coded to disable diff comments.
821-
set_exit_code(int(make_annotations(args.style)))
831+
set_exit_code(int(make_annotations(args.style, args.file_annotations)))
822832
end_log_group()
823833

824834

0 commit comments

Comments
 (0)