Skip to content

Commit 6484561

Browse files
committed
Allow exiting with 0 regardless of flake8 status.
1 parent f1e0c43 commit 6484561

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

flake8_github_action/__init__.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def action(
9999

100100
# check_run_id = check.create_check_run()
101101
check_run_id = check.find_run_for_action()
102+
check.update_check_run(
103+
check_run_id,
104+
status="in_progress",
105+
output={"title": "Flake8 checks", "summary": "Output from Flake8"},
106+
)
102107

103108
flake8_app = Application()
104109
flake8_app.run(args)
@@ -110,32 +115,34 @@ def action(
110115
for filename, raw_annotations in json_annotations:
111116
annotations.extend(Annotation.from_flake8json(filename, ann) for ann in raw_annotations)
112117

113-
# Github limits updates to 50 annotations at a time
114-
annotation_chunks = list(chunks(annotations, 50))
115-
116-
if flake8_app.result_count:
117-
conclusion = "failure"
118-
ret = 1
119-
else:
120-
conclusion = "success"
121-
ret = 0
122-
123-
for chunk in annotation_chunks[:-1]:
124-
check.update_check_run(
125-
check_run_id,
126-
conclusion=conclusion,
127-
output={
128-
"title": "Flake8 checks",
129-
"summary": "Output from Flake8",
130-
"annotations": [a.to_dict() for a in chunk],
131-
},
132-
)
133-
134-
output = {
135-
"title": "Flake8 checks",
136-
"summary": "Output from Flake8",
137-
"annotations": [a.to_dict() for a in annotation_chunks[-1]],
138-
}
139-
140-
# TODO: reflect flake8 output
141-
return check.complete_check_run(check_run_id, conclusion="success", output=output), ret
118+
if annotations:
119+
# Github limits updates to 50 annotations at a time
120+
annotation_chunks = list(chunks(annotations, 50))
121+
122+
if flake8_app.result_count:
123+
conclusion = "failure"
124+
ret = 1
125+
else:
126+
conclusion = "success"
127+
ret = 0
128+
129+
for chunk in annotation_chunks[:-1]:
130+
check.update_check_run(
131+
check_run_id,
132+
conclusion=conclusion,
133+
output={
134+
"title": "Flake8 checks",
135+
"summary": "Output from Flake8",
136+
"annotations": [a.to_dict() for a in chunk],
137+
},
138+
)
139+
140+
output = {
141+
"title": "Flake8 checks",
142+
"summary": "Output from Flake8",
143+
"annotations": [a.to_dict() for a in annotation_chunks[-1]],
144+
}
145+
146+
return check.complete_check_run(check_run_id, conclusion=conclusion, output=output), ret
147+
148+
return check.complete_check_run(check_run_id, conclusion="success"), 0

flake8_github_action/__main__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@
6060
default=None,
6161
help="The repository name (in the format <username>/<repository>) or the complete GitHub URL.",
6262
)
63+
@click.option(
64+
"--annotate-only",
65+
is_flag=True,
66+
default=False,
67+
help="Only add the annotations (exit 0 regardless of flake8 output).",
68+
)
6369
@click.command(context_settings={"ignore_unknown_options": True, "allow_extra_args": True, **CONTEXT_SETTINGS})
6470
@click.pass_context
65-
def main(ctx: click.Context, token: str, repo: Union[str, URL, None] = None):
71+
def main(ctx: click.Context, token: str, repo: Union[str, URL, None] = None, annotate_only: bool = False,):
6672
"""
6773
Run flake8 and add the errors as annotations on GitHub.
6874
"""
@@ -74,7 +80,11 @@ def main(ctx: click.Context, token: str, repo: Union[str, URL, None] = None):
7480

7581
# if response.status_code == 200:
7682
# sys.exit(0)
77-
sys.exit(ret)
83+
84+
if annotate_only:
85+
sys.exit(0)
86+
else:
87+
sys.exit(ret)
7888

7989

8090
if __name__ == "__main__":

0 commit comments

Comments
 (0)