[sysadmin-bin] Set default and stable branches as protected



commit 7e7b9d89045dd5a4d9732d4b9c3a40ffe2d7fecd
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Fri Sep 27 15:07:29 2019 +0200

    Set default and stable branches as protected

 gitlab/gitlab-operations.py | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/gitlab/gitlab-operations.py b/gitlab/gitlab-operations.py
index dd24e3a..fc0ae09 100755
--- a/gitlab/gitlab-operations.py
+++ b/gitlab/gitlab-operations.py
@@ -94,12 +94,21 @@ for project in projects:
     uids = []
 
     doap_url = 'https://gitlab.gnome.org/GNOME/%s/raw/%s/%s.doap'
-    branch_name = project.attributes.get('default_branch')
-    if not branch_name:
-        branch_name = 'master'
+    default_branch = project.attributes.get('default_branch')
+    if not default_branch:
+        default_branch = 'master'
+
+    branches = [branch.name for branch in project.branches_list()]
+    stable_branches_regex = re.compile(r'gnome-\d-\d\d')
+    stable_branches = set(filter(stable_branches_regex.match, branches))
+    protected_branches = {branch.name for branch in project.protectedbranches.list()}
+
+    for branch_name in (stable_branches - protected_branches):
+        branch = project.branches.get(branch_name, lazy=True)
+        branch.protect(developers_can_push=True, developers_can_merge=True)
 
     try:
-        nodes = semi_rdf.read_rdf(doap_url % (project_name, branch_name, project_name))
+        nodes = semi_rdf.read_rdf(doap_url % (project_name, default_branch, project_name))
     except SAXParseException:
         nodes = ''
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]