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
from argparse import ArgumentParser
from random import choice, shuffle
from datetime import datetime, timedelta
import logging
import yaml
import pandas as pd
......@@ -36,6 +37,7 @@ REVIEW_ACCESS_LEVEL = 30 # developper
CLIENT_PROJECT_TAG = "client-project"
STATE_FILENAME = "auto_assigned_reviewers.csv"
logging.basicConfig(level=os.getenv("AB_LOG_THRESHOLD", "INFO").upper())
class ReviewAssigner:
......@@ -125,9 +127,10 @@ class ReviewAssigner:
query_data={"assignee_id": user.id},
)
except GitlabHttpError:
print(
f"ERROR: no permission to assign a reviewer to {merge_request.title}"
f" ({merge_request.web_url})"
logging.error(
"ERROR: no permission to assign a reviewer to %s (%s)",
merge_request.title,
merge_request.web_url,
)
return
......@@ -136,7 +139,11 @@ class ReviewAssigner:
datetime.now(),
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):
merge_requests = self.cnx.mergerequests.list(
......@@ -172,8 +179,9 @@ class ReviewAssigner:
if CLIENT_PROJECT_TAG in project.tag_list:
# it's a client project. Let's assume that someone will take
# care of this MR.
print(
f"INFO: {merge_request.web_url} would need review, but it's a client project"
logging.info(
"%s would need review, but it's a client project",
merge_request.web_url,
)
continue
yield merge_request
......@@ -183,7 +191,11 @@ class ReviewAssigner:
try:
reviewer = self.a_possible_reviewer(mr)
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
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