2828
2929# stdlib
3030import json
31- from typing import List , Tuple , Union
32-
33- # 3rd party
34- import click
35- import dulwich .errors
36- from apeye import URL
37- from domdf_python_tools .iterative import chunks
38- from domdf_python_tools .secrets import Secret
39- from dulwich .repo import Repo
40- from requests import Response
31+ from typing import List
4132
4233# this package
4334from flake8_github_action .annotation import Annotation
5445
5546
5647def action (
57- token : Union [str , Secret ],
58- repo : Union [str , URL , None ] = None ,
5948 * args ,
60- ) -> Tuple [ Response , int ] :
49+ ) -> int :
6150 r"""
6251 Action!
6352
64- :param token: The token to authenticate with the GitHub API.
65- :param repo: The repository name (in the format <username>/<repository>) or the complete GitHub URL.
6653 :param \*args: flake8 command line arguments.
6754 """
6855
69- if not isinstance (token , Secret ):
70- token = Secret (token )
71-
72- dulwich_repo = Repo ('.' )
73-
74- if repo is None :
75- try :
76- config = dulwich_repo .get_config ()
77- repo = URL (config .get (("remote" , "origin" ), "url" ).decode ("UTF-8" ))
78- except dulwich .errors .NotGitRepository as e :
79- raise click .UsageError (str (e ))
80-
81- elif not isinstance (repo , URL ):
82- repo = URL (repo )
83-
84- if repo .suffix == ".git" :
85- repo = repo .with_suffix ('' )
86-
87- repo_name = repo .name
88-
89- # first case is for full url, second for github/hello_world
90- github_username = repo .parent .name or repo .domain .domain
91-
92- check = Checks (
93- owner = github_username ,
94- repository_name = repo_name ,
95- check_name = "Flake8" ,
96- head_sha = dulwich_repo .head ().decode ("UTF-8" ),
97- token = token .value ,
98- )
99-
100- # check_run_id = check.create_check_run()
101- 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- )
107-
10856 flake8_app = Application ()
10957 flake8_app .run (args )
11058 flake8_app .exit ()
@@ -115,34 +63,16 @@ def action(
11563 for filename , raw_annotations in json_annotations :
11664 annotations .extend (Annotation .from_flake8json (filename , ann ) for ann in raw_annotations )
11765
66+ if flake8_app .result_count :
67+ ret = 1
68+ else :
69+ ret = 0
70+
11871 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
72+ for annotation in annotations :
73+ print (annotation .to_str ())
74+
75+ return ret
76+
77+
78+
0 commit comments