Module: tools Branch: master Commit: 34b1a84e0ca9f3327d63e78a78382500f7e8f449 URL: https://gitlab.winehq.org/winehq/tools/-/commit/34b1a84e0ca9f3327d63e78a7838...
Author: Jeremy White jwhite@codeweavers.com Date: Thu Jul 28 09:36:09 2022 -0500
gitlab: Exclude the MR submitter from reviewers.
Also add a more full featured test mode.
---
gitlab/gitlab-to-mail/assign.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
diff --git a/gitlab/gitlab-to-mail/assign.py b/gitlab/gitlab-to-mail/assign.py index 4538a701..f5959d7a 100755 --- a/gitlab/gitlab-to-mail/assign.py +++ b/gitlab/gitlab-to-mail/assign.py @@ -10,6 +10,7 @@ import re from urllib.parse import urljoin import fnmatch import requests +import argparse
from util import fetch_all, Settings
@@ -23,6 +24,12 @@ def empty_record(): } return copy.deepcopy(m)
+def add_but_exclude_author(out_ids, out_names, in_ids, in_names, author): + for i in range(len(in_ids)): + if in_names[i] != author: + out_ids.append(in_ids[i]) + out_names.append(in_names[i]) + class Assign: settings = None users = {} @@ -96,7 +103,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_from_files(self, files): + def get_assignees_from_files(self, files, author): maintainer_ids = [] people_ids = [] maintainer_names = [] @@ -105,10 +112,8 @@ class Assign: for glob in m['globs']: for f in files: if fnmatch.fnmatch(f, glob): - maintainer_ids = maintainer_ids + m['maintainer_ids'] - maintainer_names = maintainer_names + m['maintainers'] - people_ids = people_ids + m['people_ids'] - people_names = people_names + m['people'] + add_but_exclude_author(maintainer_ids, maintainer_names, m['maintainer_ids'], m['maintainers'], author['name']) + add_but_exclude_author(people_ids, people_names, m['people_ids'], m['people'], author['name']) if len(maintainer_ids) > 0: return maintainer_ids, maintainer_names return people_ids, people_names @@ -129,7 +134,7 @@ class Assign: return ids, names
def get_assignees(self, files, author, version): - ids, names = self.get_assignees_from_files(files) + ids, names = self.get_assignees_from_files(files, author) commit_ids, commit_names = self.get_assignees_from_commits(version) return list(set(ids + commit_ids)), list(set(names + commit_names))
@@ -151,9 +156,26 @@ class Assign:
def main(argv): """ Debug code; pass in a config file and the names of files you want to test """ - settings = Settings(argv[1]) + parser = argparse.ArgumentParser(description="Debug code to test the assignment code") + parser.add_argument('settings', nargs=1) + parser.add_argument('--author', nargs=1, help='name of the person supposed to have submitted the MR') + parser.add_argument('--committer', action='append', help='repeat to specify multiple committers in our fake MR.') + parser.add_argument('files', nargs='*', help='name of Wine files supposedly in MR to pattern match') + args = parser.parse_args() + settings = Settings(args.settings) + print(args) a = Assign(settings) - ids, names = a.get_assignees_from_files(argv[2:]) + if args.author: + author = { 'name': args.author[0] } + else: + author = { 'name': None } + version = { 'commits' : [] } + if args.committer: + for commit in args.committer: + vcommit = { 'author_name' : commit } + version['commits'].append(vcommit) + print(version) + ids, names = a.get_assignees(args.files, author, version) for i in range(len(ids)): print("{}: {}".format(ids[i], names[i]))