Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit fa947b7

Browse files
committed
feat: Use logger instead of print
1 parent df94fa8 commit fa947b7

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

annotate_pr_with_ruff/github_utils.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from .ruff import RuffError
77
from .ruff import run_cli
88

9+
import logging
10+
11+
logger = logging.getLogger(__name__)
12+
913

1014
def get_diff(owner: str, repo: str, pr_number: int) -> str:
1115
return run_cli(
@@ -33,7 +37,13 @@ def get_last_commit(owner: str, repo: str, pr_number: int) -> str:
3337
).strip()
3438

3539

36-
def submit_review(owner: str, repo: str, pr_number: int, review_message:str, errors: Sequence[RuffError]):
40+
def submit_review(
41+
owner: str,
42+
repo: str,
43+
pr_number: int,
44+
review_message: str,
45+
errors: Sequence[RuffError],
46+
):
3747
url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}/reviews"
3848

3949
body = dict(
@@ -58,5 +68,5 @@ def submit_review(owner: str, repo: str, pr_number: int, review_message:str, err
5868
headers=headers,
5969
json=body,
6070
)
61-
print(f">>> post({url}, headers={headers}, body={body})")
62-
print(response.status_code, response.json())
71+
logger.debug(f">>> post({url}, headers={headers}, body={body})")
72+
logger.debug(response.status_code, response.json())

annotate_pr_with_ruff/ruff.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from pathlib import Path
66
from typing import Tuple
77

8+
import logging
9+
10+
logger = logging.getLogger(__name__)
11+
812

913
@dataclass
1014
class RuffError:
@@ -29,13 +33,17 @@ def run_cli(*command_args) -> str:
2933
process = subprocess.Popen(command_args, stdout=subprocess.PIPE)
3034
stdout, _ = process.communicate()
3135
output = stdout.decode()
32-
print(f""">>> {' '.join(command_args)}""")
33-
print(output)
36+
logger.debug(f""">>> {' '.join(command_args)}""")
37+
logger.debug(output)
3438
return output
3539

3640

3741
def ruff(*files: Tuple[str, ...]):
3842
if not files:
3943
files = tuple(str(x) for x in Path(".").iterdir() if x.is_dir())
4044
output = run_cli("ruff", *files)
41-
return [RuffError.from_message_error(error) for error in output.splitlines() if error.startswith(files)]
45+
return [
46+
RuffError.from_message_error(error)
47+
for error in output.splitlines()
48+
if error.startswith(files)
49+
]

0 commit comments

Comments
 (0)