Support non-default URLs in GithubIntegration (#1229)

The get_installation() method of GithubIntegration was hardcoded to
always use the default URL of api.github.com, making it impossible to
fetch the installation of an GitHub Enterprise installation.
This commit is contained in:
Steve Kowalik
2019-09-25 23:01:31 +10:00
committed by GitHub
parent 89c967bb77
commit e33858a3dc
2 changed files with 15 additions and 4 deletions
+1 -1
View File
@@ -790,7 +790,7 @@ class GithubIntegration(object):
}
response = requests.get(
"{}/repos/{}/{}/installation".format(DEFAULT_BASE_URL, owner, repo),
"{}/repos/{}/{}/installation".format(self.base_url, owner, repo),
headers=headers
)
response_dict = response.json()
+14 -3
View File
@@ -84,6 +84,7 @@ class GithubIntegration(unittest.TestCase):
def __init__(self):
self.args = tuple()
self.kwargs = dict()
self.calls = []
@property
def status_code(self):
@@ -120,6 +121,7 @@ class GithubIntegration(unittest.TestCase):
)
def __call__(self, *args, **kwargs):
self.calls.append((args, kwargs))
self.args = args
self.kwargs = kwargs
return self
@@ -167,9 +169,18 @@ class GithubIntegration(unittest.TestCase):
integr = GithubIntegration("11111", private_key)
inst = integr.get_installation("foo", "bar")
self.assertEqual(
inst.id.value,
111111
)
self.get_mock.calls[0][0],
('https://api.github.com/repos/foo/bar/installation',))
self.assertEqual(inst.id.value, 111111)
def test_get_installation_custom_base_url(self):
from github import GithubIntegration
integr = GithubIntegration("11111", private_key, base_url='https://corp.com/v3')
inst = integr.get_installation("foo", "bar")
self.assertEqual(
self.get_mock.calls[0][0],
('https://corp.com/v3/repos/foo/bar/installation',))
self.assertEqual(inst.id.value, 111111)
def tearDown(self):
GithubObject.setCheckAfterInitFlag(self.origin_check_after_init_flag)