Commit f7344708 authored by Simon Chabot's avatar Simon Chabot
Browse files

feat: use a proper logger instead of using print

parent f982fcd9b39e
Pipeline #20621 passed with stage
in 46 seconds
...@@ -23,6 +23,7 @@ import os ...@@ -23,6 +23,7 @@ import os
from argparse import ArgumentParser from argparse import ArgumentParser
from random import choice, shuffle from random import choice, shuffle
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging
import yaml import yaml
import pandas as pd import pandas as pd
...@@ -36,6 +37,7 @@ REVIEW_ACCESS_LEVEL = 30 # developper ...@@ -36,6 +37,7 @@ REVIEW_ACCESS_LEVEL = 30 # developper
CLIENT_PROJECT_TAG = "client-project" CLIENT_PROJECT_TAG = "client-project"
STATE_FILENAME = "auto_assigned_reviewers.csv" STATE_FILENAME = "auto_assigned_reviewers.csv"
logging.basicConfig(level=os.getenv("AB_LOG_THRESHOLD", "INFO").upper())
class ReviewAssigner: class ReviewAssigner:
...@@ -125,9 +127,10 @@ class ReviewAssigner: ...@@ -125,9 +127,10 @@ class ReviewAssigner:
query_data={"assignee_id": user.id}, query_data={"assignee_id": user.id},
) )
except GitlabHttpError: except GitlabHttpError:
print( logging.error(
f"ERROR: no permission to assign a reviewer to {merge_request.title}" "ERROR: no permission to assign a reviewer to %s (%s)",
f" ({merge_request.web_url})" merge_request.title,
merge_request.web_url,
) )
return return
...@@ -136,7 +139,11 @@ class ReviewAssigner: ...@@ -136,7 +139,11 @@ class ReviewAssigner:
datetime.now(), datetime.now(),
merge_request.web_url, merge_request.web_url,
) )
print(f"{user.name} has been assigned to {merge_request.title}") logging.info(
"%s has been assigned to %s",
user.name,
merge_request.title,
)
def all_reviews_to_do(self): def all_reviews_to_do(self):
merge_requests = self.cnx.mergerequests.list( merge_requests = self.cnx.mergerequests.list(
...@@ -172,8 +179,9 @@ class ReviewAssigner: ...@@ -172,8 +179,9 @@ class ReviewAssigner:
if CLIENT_PROJECT_TAG in project.tag_list: if CLIENT_PROJECT_TAG in project.tag_list:
# it's a client project. Let's assume that someone will take # it's a client project. Let's assume that someone will take
# care of this MR. # care of this MR.
print( logging.info(
f"INFO: {merge_request.web_url} would need review, but it's a client project" "%s would need review, but it's a client project",
merge_request.web_url,
) )
continue continue
yield merge_request yield merge_request
...@@ -183,7 +191,11 @@ class ReviewAssigner: ...@@ -183,7 +191,11 @@ class ReviewAssigner:
try: try:
reviewer = self.a_possible_reviewer(mr) reviewer = self.a_possible_reviewer(mr)
except IndexError: except IndexError:
print(f"WARNING: no reviewer available for {mr.title}.") logging.warning(
"no reviewer available for %s (%s).",
mr.title,
mr.web_url,
)
continue continue
self.assign_reviewer(mr, reviewer) self.assign_reviewer(mr, reviewer)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment