Commit bd6e0128 authored by Frank Bessou's avatar Frank Bessou 💭
Browse files

refactor: extract all_reviews function

It will be used by migrations.
parent 81b0ec1b37cf
...@@ -47,6 +47,47 @@ Do you think it should still be merged? ...@@ -47,6 +47,47 @@ Do you think it should still be merged?
Thank you for your time. Thank you for your time.
""" """
def all_reviews(cnx, assignee_id="None"):
merge_requests = cnx.mergerequests.list(
labels=TO_REVIEW_LABEL,
state="opened",
wip="no",
scope="all",
assignee_id=assignee_id,
all=True,
)
merge_requests.extend(
cnx.mergerequests.list(
labels="None",
state="opened",
wip="no",
scope="all",
assignee_id=assignee_id,
all=True,
)
)
shuffle(merge_requests)
for merge_request in merge_requests:
if merge_request.work_in_progress:
# double check that the MR is not WIP.
# it seems that filtering in the search parameters is not enough
# XXX is it a Gitlab bug ?
continue
project = cnx.projects.get(merge_request.project_id)
if DO_NOT_REVIEW_TAG in project.tag_list:
# has the 'no-assignbot' tag. Let's assume that someone will take
# care of this MR.
print(
f"INFO: {merge_request.web_url} would need review, but it "
f"has the '{DO_NOT_REVIEW_TAG}' tag"
)
continue
yield merge_request
class ReviewAssigner: class ReviewAssigner:
def __init__(self, gitlab_url, gitlab_token, users_preferences_filepath): def __init__(self, gitlab_url, gitlab_token, users_preferences_filepath):
...@@ -148,53 +189,13 @@ class ReviewAssigner: ...@@ -148,53 +189,13 @@ class ReviewAssigner:
) )
print(f"{user.name} has been assigned to {merge_request.title}") print(f"{user.name} has been assigned to {merge_request.title}")
def _all_reviews(self, assignee_id="None"):
merge_requests = self.cnx.mergerequests.list(
labels=TO_REVIEW_LABEL,
state="opened",
wip="no",
scope="all",
assignee_id=assignee_id,
all=True,
)
merge_requests.extend(
self.cnx.mergerequests.list(
labels="None",
state="opened",
wip="no",
scope="all",
assignee_id=assignee_id,
all=True,
)
)
shuffle(merge_requests)
for merge_request in merge_requests:
if merge_request.work_in_progress:
# double check that the MR is not WIP.
# it seems that filtering in the search parameters is not enough
# XXX is it a Gitlab bug ?
continue
project = self.cnx.projects.get(merge_request.project_id)
if DO_NOT_REVIEW_TAG in project.tag_list:
# has the 'no-assignbot' tag. Let's assume that someone will take
# care of this MR.
print(
f"INFO: {merge_request.web_url} would need review, but it "
f"has the '{DO_NOT_REVIEW_TAG}' tag"
)
continue
yield merge_request
def all_reviews_to_do(self): def all_reviews_to_do(self):
return self._all_reviews(assignee_id="None") return all_reviews(self.cnx, assignee_id="None")
def all_pending_reviews_older_than(self, older_than): def all_pending_reviews_older_than(self, older_than):
now = datetime.now(timezone.utc) now = datetime.now(timezone.utc)
for mr in self._all_reviews(assignee_id="Any"): for mr in all_reviews(self.cnx, assignee_id="Any"):
mr_last_update = datetime.fromisoformat( mr_last_update = datetime.fromisoformat(
mr.updated_at.replace("Z", "+00:00") mr.updated_at.replace("Z", "+00:00")
) )
......
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