11from github import Github
2+ from github import GithubException
3+ import sys
24from stdiomask import getpass
35from config import branches
46from config import branch_rules
@@ -10,51 +12,71 @@ def add_all(pat):
1012 print ("" )
1113 for repo in git .get_organization (org_name ).get_repos ():
1214 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 ()
15+ try :
16+ repo .get_branch (branch_name )
17+ except GithubException :
18+ print ("Error:" ,repo .name ,"," ,branch_name ,"-->" ,sys .exc_info ()[1 ])
1919 else :
20- branch .remove_required_signatures ()
21- print ("Edited the branch protection rules for: " + repo .name + "," + branch_name )
20+ branch = repo .get_branch (branch_name )
21+ if (add_codeowners_file ):
22+ codeowners .add (org_name ,pat ,repo .name ,branch_name )
23+ branch .edit_protection (** branch_rules )
24+ if (signed_commit ):
25+ branch .add_required_signatures ()
26+ else :
27+ branch .remove_required_signatures ()
28+ print ("Edited the branch protection rules for: " + repo .name + "," + branch_name )
2229
2330def add_one (pat ):
2431 repo_name = input ("\n Repository: " )
2532 repo = git .get_repo (org_name + "/" + repo_name )
2633 for branch_name in branches :
27- branch = repo .get_branch (branch_name )
28- if (add_codeowners_file ):
29- codeowners .add (org_name ,pat ,repo_name ,branch_name )
30- branch .edit_protection (** branch_rules )
31- if (signed_commit ):
32- branch .add_required_signatures ()
34+ try :
35+ repo .get_branch (branch_name )
36+ except GithubException :
37+ print ("Error:" ,repo .name ,"," ,branch_name ,"-->" ,sys .exc_info ()[1 ])
3338 else :
34- branch .remove_required_signatures ()
35- print ("Edited the branch protection rules for: " + repo .name + "," + branch_name )
39+ branch = repo .get_branch (branch_name )
40+ if (add_codeowners_file ):
41+ codeowners .add (org_name ,pat ,repo_name ,branch_name )
42+ branch .edit_protection (** branch_rules )
43+ if (signed_commit ):
44+ branch .add_required_signatures ()
45+ else :
46+ branch .remove_required_signatures ()
47+ print ("Edited the branch protection rules for: " + repo .name + "," + branch_name )
3648
3749def remove_one ():
3850 repo_name = input ("\n Repository: " )
3951 repo = git .get_repo (org_name + "/" + repo_name )
4052 for branch_name in branches :
41- branch = repo . get_branch ( branch_name )
42- if ( branch . protected ):
43- branch . remove_protection ()
44- print ("Removed branch protection rules for: " + repo .name + "," + branch_name )
53+ try :
54+ repo . get_branch ( branch_name )
55+ except GithubException :
56+ print ("Error:" , repo .name , "," , branch_name , "-->" , sys . exc_info ()[ 1 ] )
4557 else :
46- print ("No branch protection rules for: " + repo .name + "," + branch .name )
58+ branch = repo .get_branch (branch_name )
59+ if (branch .protected ):
60+ branch .remove_protection ()
61+ print ("Removed branch protection rules for: " + repo .name + "," + branch_name )
62+ else :
63+ print ("No branch protection rules for: " + repo .name + "," + branch .name )
4764
4865def remove_all ():
4966 print ("" )
5067 for repo in git .get_organization (org_name ).get_repos ():
5168 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 )
69+ try :
70+ repo . get_branch ( branch_name )
71+ except GithubException :
72+ print ("Error:" , repo .name , "," , branch_name , "-->" , sys . exc_info ()[ 1 ] )
5673 else :
57- print ("No branch protection rules for: " + repo .name + "," + branch .name )
74+ branch = repo .get_branch (branch_name )
75+ if (branch .protected ):
76+ branch .remove_protection ()
77+ print ("Removed branch protection rules for: " + repo .name + "," + branch_name )
78+ else :
79+ print ("No branch protection rules for: " + repo .name + "," + branch .name )
5880
5981print (" ___ _ _ ______ _ ______ _ " )
6082print (" / _ \ | | | | | ___ \ | | | ___ \ | | " )
0 commit comments