Module: tools Branch: master Commit: dd1f0c3aa2f23a65a594cf65a057b81d8c9158c0 URL: https://gitlab.winehq.org/winehq/tools/-/commit/dd1f0c3aa2f23a65a594cf65a057...
Author: Jeremy White jwhite@codeweavers.com Date: Thu Jul 14 14:21:25 2022 -0500
Improve diagnostic messages.
This includes printing who each MR is assigned to, so we can more readily check the work of this script.
---
gitlab/gitlab-to-mail/assign.py | 49 +++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/gitlab/gitlab-to-mail/assign.py b/gitlab/gitlab-to-mail/assign.py index 5a8b914d..9b6acb69 100755 --- a/gitlab/gitlab-to-mail/assign.py +++ b/gitlab/gitlab-to-mail/assign.py @@ -20,6 +20,8 @@ def empty_record(): 'globs': [], 'maintainers': [], 'people': [], + 'maintainer_ids': [], + 'people_ids': [], } return copy.deepcopy(m)
@@ -27,7 +29,7 @@ def fetch_users(): url = urljoin(settings.GITLAB_URL, f"api/v4/projects/{settings.GITLAB_PROJECT_ID}/users") return fetch_all(url, settings)
-def append_user(user_map, line, out, verbose=False): +def append_user(user_map, line, id_array, name_array, verbose=False): match = re.match("(.+)<", line) if match: name = match.group(1).strip() @@ -36,7 +38,8 @@ def append_user(user_map, line, out, verbose=False): return
if name in user_map: - out.append(user_map[name]) + id_array.append(user_map[name]) + name_array.append(name) elif verbose: print("Cannot find GitLab account for [{}]".format(name), file=sys.stderr)
@@ -69,9 +72,9 @@ def get_maintainers_map(verbose=False): glob += '*' m['globs'].append(glob) elif line.find("M:\t") == 0: - append_user(user_map, line[3:], m['maintainers'], verbose) + append_user(user_map, line[3:], m['maintainer_ids'], m['maintainers'], verbose) elif line.find("P:\t") == 0: - append_user(user_map, line[3:], m['people'], verbose) + append_user(user_map, line[3:], m['people_ids'], m['people'], verbose) elif line.find("W:\t") == 0: pass elif len(m['globs']) == 0: @@ -89,17 +92,21 @@ def post_reviewers(mr_iid, reviewers): r.raise_for_status()
def get_assignees(maintainers_map, files): - maintainers = [] - people = [] + maintainer_ids = [] + people_ids = [] + maintainer_names = [] + people_names = [] for m in maintainers_map: for glob in m['globs']: for f in files: if fnmatch.fnmatch(f, glob): - maintainers = maintainers + m['maintainers'] - people = people + m['people'] - if len(maintainers) > 0: - return maintainers - return people + 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'] + if len(maintainer_ids) > 0: + return maintainer_ids, maintainer_names + return people_ids, people_names
def assign_reviewers(mr_iid, version, maintainers_map, update_db): paths = [] @@ -108,23 +115,23 @@ def assign_reviewers(mr_iid, version, maintainers_map, update_db): for d in version['diffs']: if 'new_path' in d: paths.append(d['new_path']) - a = get_assignees(maintainers_map, paths) - if len(a) > 0: + ids, names = get_assignees(maintainers_map, paths) + if len(ids) > 0: if update_db: # set() prunes dupes, list() makes it json transmittable again - post_reviewers(mr_iid, list(set(a))) + post_reviewers(mr_iid, list(set(ids))) + print(f"Asking {names} to review MR {mr_iid}") else: - print("Debug: would set reviewers for {} to ids {}".format(mr_iid, a)) + print("Debug: would set reviewers for {} to {}".format(mr_iid, set(names))) + else: + print(f"No suitable reviewers found for MR {mr_iid}")
def main(argv): """ Debug code; pass in a config file and the names of files you want to test """ maintainers_map = get_maintainers_map(True) - a = get_assignees(maintainers_map, argv[2:]) - users = fetch_users() - for id in a: - for u in users: - if id == u['id']: - print("{}: {}".format(id, u['name'])) + ids, names = get_assignees(maintainers_map, argv[2:]) + for i in range(len(ids)): + print("{}: {}".format(ids[i], names[i]))
if __name__ == "__main__": main(sys.argv)