Jeremy White : gitlab: Assign extra commit authors as reviewers.
Alexandre Julliard
julliard at winehq.org
Thu Jul 28 14:48:29 CDT 2022
Module: tools
Branch: master
Commit: 6452a67926c0f71aa36f730a9d1943da2a7d4b48
URL: https://gitlab.winehq.org/winehq/tools/-/commit/6452a67926c0f71aa36f730a9d1943da2a7d4b48
Author: Jeremy White <jwhite at codeweavers.com>
Date: Thu Jul 28 13:13:51 2022 -0500
gitlab: Assign extra commit authors as reviewers.
If a merge request contains commits by authors other than
the submitting author, and we can find the commit author
in GitLab, ask them to review the merge request as well.
---
gitlab/gitlab-to-mail/assign.py | 28 ++++++++++++++++++++++++----
gitlab/gitlab-to-mail/gitlabtomail.py | 2 +-
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/gitlab/gitlab-to-mail/assign.py b/gitlab/gitlab-to-mail/assign.py
index bd156b2e..4538a701 100755
--- a/gitlab/gitlab-to-mail/assign.py
+++ b/gitlab/gitlab-to-mail/assign.py
@@ -96,7 +96,7 @@ class Assign:
r = requests.put(url, headers={"PRIVATE-TOKEN": self.settings.GITLAB_TOKEN}, json={'reviewer_ids': reviewers})
r.raise_for_status()
- def get_assignees(self, files):
+ def get_assignees_from_files(self, files):
maintainer_ids = []
people_ids = []
maintainer_names = []
@@ -113,14 +113,34 @@ class Assign:
return maintainer_ids, maintainer_names
return people_ids, people_names
- def assign_reviewers(self, mr_iid, version, update_db):
+ def get_assignees_from_commits(self, version):
+ author_names = []
+ for c in version['commits']:
+ if c['author_name'] != c['committer_name']:
+ author_names.append(c['committer_name'])
+ ids = []
+ names = []
+ for name in set(author_names):
+ if name in self.user_map:
+ ids.append(self.user_map[name])
+ names.append(name)
+ else:
+ print(f"MR includes a commit by {name}, but unable to find a GitLab ID in order to assign as reviewer.")
+ return ids, names
+
+ def get_assignees(self, files, author, version):
+ ids, names = self.get_assignees_from_files(files)
+ commit_ids, commit_names = self.get_assignees_from_commits(version)
+ return list(set(ids + commit_ids)), list(set(names + commit_names))
+
+ def assign_reviewers(self, mr_iid, author, version, update_db):
paths = []
if 'diffs' not in version:
return
for d in version['diffs']:
if 'new_path' in d:
paths.append(d['new_path'])
- ids, names = self.get_assignees(paths)
+ ids, names = self.get_assignees(paths, author, version)
if len(ids) > 0:
unique_names = list(set(names))
print(f"Asking {unique_names} to review MR {mr_iid}")
@@ -133,7 +153,7 @@ def main(argv):
""" Debug code; pass in a config file and the names of files you want to test """
settings = Settings(argv[1])
a = Assign(settings)
- ids, names = a.get_assignees(argv[2:])
+ ids, names = a.get_assignees_from_files(argv[2:])
for i in range(len(ids)):
print("{}: {}".format(ids[i], names[i]))
diff --git a/gitlab/gitlab-to-mail/gitlabtomail.py b/gitlab/gitlab-to-mail/gitlabtomail.py
index 915392d1..525130e8 100755
--- a/gitlab/gitlab-to-mail/gitlabtomail.py
+++ b/gitlab/gitlab-to-mail/gitlabtomail.py
@@ -628,7 +628,7 @@ def process_mr(mr, update_db, assigner):
# Assign reviewers if there are none currently
if len(mr['reviewers']) == 0:
full_version = fetch_mr_version(iid, versions[0]['id'])
- assigner.assign_reviewers(iid, full_version, update_db)
+ assigner.assign_reviewers(iid, mr['author'], full_version, update_db)
fixup_date(cover, date)
create_headers_from_mr(cover, mr)
More information about the wine-cvs
mailing list