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

feat: add migration script to change assignees into reviewers

(and authors into assignees)
parent e0e9b05c4a7d
import logging
import os
from argparse import ArgumentParser
from gitlab import Gitlab
from gitlab.exceptions import GitlabHttpError
from assignbot.__main__ import all_reviews
def assignee_to_reviewer(cnx):
"""Gitlab added a "reviewer" role on merge requests. This function changes
the author to the assignee and the previous assignee to the reviewer.
"""
merges_requests = all_reviews(cnx, assignee_id="Any")
for merge_request in merges_requests:
if merge_request.reviewers:
continue
assignee = merge_request.assignee
author = merge_request.author
logging.info(
f'Assigning {author["name"]} and request review from {assignee["name"]} on {merge_request.web_url}'
)
try:
cnx.http_put(
f"/projects/{merge_request.project_id}/merge_requests/{merge_request.iid}",
query_data={
"assignee_id": author["id"],
"reviewer_ids": [assignee["id"]],
},
)
except GitlabHttpError:
logging.error(
f"no permission to assign a reviewer to {merge_request.title}"
f" ({merge_request.web_url})"
)
if __name__ == "__main__":
logging.getLogger().setLevel(logging.INFO)
parser = ArgumentParser()
parser.add_argument("--gitlab-url", type=str, default=os.getenv("GITLAB_URL"))
parser.add_argument("--gitlab-token", type=str, default=os.getenv("GITLAB_TOKEN"))
args = parser.parse_args()
cnx = Gitlab(args.gitlab_url, args.gitlab_token)
assignee_to_reviewer(cnx)
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