From e02d8a49afb00c302a45dce33e68b0cf4f326c6f Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Oct 11 2022 10:38:06 +0000 Subject: Allow multiple branches in collaborator permissions According to the examples in collaborator permissions, it's possible to specify several rules separated by commas. However, the new branch utility only allowed one. --- diff --git a/fedscm_admin/utils.py b/fedscm_admin/utils.py index 8b37cae..f4c27d8 100644 --- a/fedscm_admin/utils.py +++ b/fedscm_admin/utils.py @@ -496,6 +496,20 @@ def prompt_for_new_repo(issue_json, issue_body_json, force=False, return +def match_collaborator_branch(branch_name, branch_patterns): + """Return true if branch_name matches the given pattern. + + Examples of patterns (from a src.fedoraproject.org settings page): + main,features/* + epel* + rawhide,f* + """ + for pattern in branch_patterns.split(','): + if fnmatch.fnmatch(branch_name, pattern.strip()): + return True + return False + + def prompt_for_new_branch(issue_json, issue_body_json, force=False, auto_approve=False): """ A helper function that prompts the user with information on a new branch @@ -577,14 +591,14 @@ def prompt_for_new_branch(issue_json, issue_body_json, force=False, auto_approve set(contributors['users']['commit']) | \ set(u['user'] for u in contributors['users']['collaborators'] - if fnmatch.fnmatch(branch_name, u['branches'])) + if match_collaborator_branch(branch_name, u['branches'])) # Get the list of FAS groups who can maintain the package access_groups = set(contributors['groups']['admin']) | \ set(contributors['groups']['commit']) | \ set(g['user'] for g in contributors['groups']['collaborators'] - if fnmatch.fnmatch(branch_name, g['branches'])) + if match_collaborator_branch(branch_name, g['branches'])) group_member = False for access_group in access_groups: # Check if the requestor is part of any of the FAS groups who can maintain the package diff --git a/tests/mock_values.py b/tests/mock_values.py index 480cb2a..c3c2bb0 100644 --- a/tests/mock_values.py +++ b/tests/mock_values.py @@ -271,7 +271,7 @@ def get_mock_pagure_project_contributors(exists=False): 'users': { 'admin': ['salimma'], 'collaborators': [{ - 'branches': 'epel8', + 'branches': 'epel8,f20', 'user': 'ngompa' }], 'commit': [],