Skip to content

Commit 06157f0

Browse files
authored
fix: update GitHub provider to support Enterprise Server (#979)
Closes #974.
1 parent 14588ff commit 06157f0

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

components/renku_data_services/connected_services/dummy_async_oauth2_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def get(self, url: str, *args: list, **kwargs: dict) -> Response:
2626
if parsed.path == "/api/v4/projects/username%2Fmy_repo":
2727
return self._get_repository_response()
2828

29-
if parsed.path == "/user/installations":
29+
if parsed.path == "/api/v3/user/installations":
3030
return self._get_installations_response()
3131

3232
return Response(500, json=dict())

components/renku_data_services/connected_services/provider_adapters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def api_validate_account_response(self, response: Response) -> models.ConnectedA
7878

7979

8080
class GitHubAdapter(ProviderAdapter):
81-
"""Adapter for GitLab OAuth2 clients."""
81+
"""Adapter for GitHub OAuth2 clients."""
8282

8383
@property
8484
def authorization_url(self) -> str:
@@ -94,6 +94,9 @@ def token_endpoint_url(self) -> str:
9494
def api_url(self) -> str:
9595
"""The URL used for API calls on the Resource Server."""
9696
url = urlparse(self.client_url)
97+
# See: https://docs.github.com/en/apps/sharing-github-apps/making-your-github-app-available-for-github-enterprise-server#the-app-code-must-use-the-correct-urls
98+
if url.netloc != "github.com":
99+
return urljoin(self.client_url, "api/v3/")
97100
url = url._replace(netloc=f"api.{url.netloc}")
98101
return urlunparse(url)
99102

components/renku_data_services/repositories/provider_adapters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ def api_validate_repository_response(
7373

7474

7575
class GitHubAdapter(GitProviderAdapter):
76-
"""Adapter for GitLab OAuth2 clients."""
76+
"""Adapter for GitHub OAuth2 clients."""
7777

7878
@property
7979
def api_url(self) -> str:
8080
"""The URL used for API calls on the Resource Server."""
8181
url = urlparse(self.client_url)
82+
# See: https://docs.github.com/en/apps/sharing-github-apps/making-your-github-app-available-for-github-enterprise-server#the-app-code-must-use-the-correct-urls
83+
if url.netloc != "github.com":
84+
return urljoin(self.client_url, "api/v3/")
8285
url = url._replace(netloc=f"api.{url.netloc}")
8386
return urlunparse(url)
8487

0 commit comments

Comments
 (0)