Skip to content

Commit d39fc66

Browse files
author
Grenston George
authored
Merge pull request #8 from CanarysAutomations/grenston-branch
multi branch support added
2 parents dafc863 + 55228c6 commit d39fc66

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

automate-branch-rules.py

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from github import Github
22
from stdiomask import getpass
3-
from config import branch_name
3+
from config import branches
44
from config import branch_rules
55
from config import signed_commit
66
from config import add_codeowners_file
@@ -9,48 +9,52 @@
99
def add_all(pat):
1010
print("")
1111
for repo in git.get_organization(org_name).get_repos():
12+
for branch_name in branches:
13+
branch = repo.get_branch(branch_name)
14+
if(add_codeowners_file):
15+
codeowners.add(org_name,pat,repo.name,branch_name)
16+
branch.edit_protection(**branch_rules)
17+
if(signed_commit):
18+
branch.add_required_signatures()
19+
else:
20+
branch.remove_required_signatures()
21+
print("Edited the branch protection rules for: " + repo.name + "," + branch_name)
22+
23+
def add_one(pat):
24+
repo_name = input("\nRepository: ")
25+
repo = git.get_repo(org_name+"/"+repo_name)
26+
for branch_name in branches:
1227
branch = repo.get_branch(branch_name)
1328
if(add_codeowners_file):
14-
codeowners.add(org_name,pat,repo.name,branch_name)
29+
codeowners.add(org_name,pat,repo_name,branch_name)
1530
branch.edit_protection(**branch_rules)
1631
if(signed_commit):
1732
branch.add_required_signatures()
1833
else:
1934
branch.remove_required_signatures()
20-
print("Edited the branch protection rules for: " + repo.name)
21-
22-
def add_one(pat):
23-
repo_name = input("\nRepository: ")
24-
repo = git.get_repo(org_name+"/"+repo_name)
25-
branch = repo.get_branch(branch_name)
26-
if(add_codeowners_file):
27-
codeowners.add(org_name,pat,repo_name,branch_name)
28-
branch.edit_protection(**branch_rules)
29-
if(signed_commit):
30-
branch.add_required_signatures()
31-
else:
32-
branch.remove_required_signatures()
33-
print("Edited the branch protection rules for: " + repo.name)
35+
print("Edited the branch protection rules for: " + repo.name + "," + branch_name)
3436

3537
def remove_one():
3638
repo_name = input("\nRepository: ")
3739
repo = git.get_repo(org_name+"/"+repo_name)
38-
branch = repo.get_branch(branch_name)
39-
if (branch.protected):
40-
branch.remove_protection()
41-
print("Removed branch protection rules for: " + repo.name)
42-
else:
43-
print("No branch protection rules for: " + repo.name + "," + branch.name)
44-
45-
def remove_all():
46-
print("")
47-
for repo in git.get_organization(org_name).get_repos():
40+
for branch_name in branches:
4841
branch = repo.get_branch(branch_name)
4942
if (branch.protected):
5043
branch.remove_protection()
51-
print("Removed branch protection rules for: " + repo.name)
44+
print("Removed branch protection rules for: " + repo.name + "," + branch_name)
5245
else:
53-
print("No branch protection rules for: " + repo.name + "," + branch.name)
46+
print("No branch protection rules for: " + repo.name + "," + branch.name)
47+
48+
def remove_all():
49+
print("")
50+
for repo in git.get_organization(org_name).get_repos():
51+
for branch_name in branches:
52+
branch = repo.get_branch(branch_name)
53+
if (branch.protected):
54+
branch.remove_protection()
55+
print("Removed branch protection rules for: " + repo.name + "," + branch_name)
56+
else:
57+
print("No branch protection rules for: " + repo.name + "," + branch.name)
5458

5559
print(" ___ _ _ ______ _ ______ _ ")
5660
print(" / _ \ | | | | | ___ \ | | | ___ \ | | ")

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
branch_name = "master"
1+
branches = ("master","dev")
22
add_codeowners_file = False
33
signed_commit = False
44
branch_rules = { "required_approving_review_count":1,

0 commit comments

Comments
 (0)