@@ -17,7 +17,7 @@ def make_headers(self) -> dict:
1717 }
1818
1919 def get_paginated_branches_url (self , page : int = 0 ):
20- return f'{ GH_BASE_URL } /repos/{ self .github_repo } /branches?per_page=30&page={ page } '
20+ return f'{ GH_BASE_URL } /repos/{ self .github_repo } /branches?protected=false& per_page=30&page={ page } '
2121
2222 def get_deletable_branches (self , last_commit_age_days : int , ignore_branches : list ) -> list :
2323 # Default branch might not be protected
@@ -36,7 +36,7 @@ def get_deletable_branches(self, last_commit_age_days: int, ignore_branches: lis
3636 current_page = 0
3737
3838 while len (branches ) > 0 :
39- for branch in response . json () :
39+ for branch in branches :
4040 branch_name = branch .get ('name' )
4141
4242 commit_hash = branch .get ('commit' , {}).get ('sha' )
@@ -49,6 +49,8 @@ def get_deletable_branches(self, last_commit_age_days: int, ignore_branches: lis
4949 print (f'Ignoring `{ branch_name } ` because it is the default branch' )
5050 continue
5151
52+ # We're already retrieving non-protected branches from the API, but it pays being careful when dealing
53+ # with third party apis
5254 if branch .get ('protected' ) is True :
5355 print (f'Ignoring `{ branch_name } ` because it is protected' )
5456 continue
@@ -78,7 +80,7 @@ def get_deletable_branches(self, last_commit_age_days: int, ignore_branches: lis
7880 # Re-request next page
7981 current_page += 1
8082 response = requests .get (url = self .get_paginated_branches_url (page = current_page ), headers = headers )
81- branches = response .json ()
83+ branches : list = response .json ()
8284
8385 return deletable_branches
8486
0 commit comments