22
33from src import requests
44
5- GH_BASE_URL = "https://api.github.com"
6-
7-
85class Github :
9- def __init__ (self , github_repo : str , github_token : str ):
6+ def __init__ (self , github_repo : str , github_token : str , github_base_url : str ):
107 self .github_token = github_token
118 self .github_repo = github_repo
9+ self .github_base_url = github_base_url
1210
1311 def make_headers (self ) -> dict :
1412 return {
@@ -17,7 +15,7 @@ def make_headers(self) -> dict:
1715 }
1816
1917 def get_paginated_branches_url (self , page : int = 0 ) -> str :
20- return f'{ GH_BASE_URL } /repos/{ self .github_repo } /branches?protected=false&per_page=30&page={ page } '
18+ return f'{ self . github_base_url } /repos/{ self .github_repo } /branches?protected=false&per_page=30&page={ page } '
2119
2220 def get_deletable_branches (self , last_commit_age_days : int , ignore_branches : list ) -> list :
2321 # Default branch might not be protected
@@ -91,7 +89,7 @@ def get_deletable_branches(self, last_commit_age_days: int, ignore_branches: lis
9189 def delete_branches (self , branches : list ) -> None :
9290 for branch in branches :
9391 print (f'Deleting branch `{ branch } `...' )
94- url = f'{ GH_BASE_URL } /repos/{ self .github_repo } /git/refs/heads/{ branch } '
92+ url = f'{ self . github_base_url } /repos/{ self .github_repo } /git/refs/heads/{ branch } '
9593
9694 response = requests .request (method = 'DELETE' , url = url , headers = self .make_headers ())
9795 if response .status_code != 204 :
@@ -101,7 +99,7 @@ def delete_branches(self, branches: list) -> None:
10199 print (f'Branch `{ branch } ` DELETED!' )
102100
103101 def get_default_branch (self ) -> str :
104- url = f'{ GH_BASE_URL } /repos/{ self .github_repo } '
102+ url = f'{ self . github_base_url } /repos/{ self .github_repo } '
105103 headers = self .make_headers ()
106104
107105 response = requests .get (url = url , headers = headers )
@@ -115,7 +113,7 @@ def has_open_pulls(self, commit_hash: str) -> bool:
115113 """
116114 Returns true if commit is part of an open pull request or the branch is the base for a pull request
117115 """
118- url = f'{ GH_BASE_URL } /repos/{ self .github_repo } /commits/{ commit_hash } /pulls'
116+ url = f'{ self . github_base_url } /repos/{ self .github_repo } /commits/{ commit_hash } /pulls'
119117 headers = self .make_headers ()
120118 headers ['accept' ] = 'application/vnd.github.groot-preview+json'
121119
@@ -134,7 +132,7 @@ def is_pull_request_base(self, branch: str) -> bool:
134132 """
135133 Returns true if the given branch is base for another pull request.
136134 """
137- url = f'{ GH_BASE_URL } /repos/{ self .github_repo } /pulls?base={ branch } '
135+ url = f'{ self . github_base_url } /repos/{ self .github_repo } /pulls?base={ branch } '
138136 headers = self .make_headers ()
139137 headers ['accept' ] = 'application/vnd.github.groot-preview+json'
140138
0 commit comments