Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/sentry/integrations/utils/github_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,16 @@ def get_missing_github_app_permissions(
def get_github_permissions_update_url(
installation_id: str, account_type: str | None, account_login: str
) -> str | None:
# GitHub Enterprise installations are keyed as "{host}:{installation id}".
host, _, installation_id = installation_id.rpartition(":")
base_url = f"https://{host or 'github.com'}"
if not installation_id:
return None
if account_type == "Organization":
if not account_login:
return None
return (
f"https://github.com/organizations/{account_login}"
f"{base_url}/organizations/{account_login}"
f"/settings/installations/{installation_id}/permissions/update"
)
return f"https://github.com/settings/installations/{installation_id}/permissions/update"
return f"{base_url}/settings/installations/{installation_id}/permissions/update"
7 changes: 7 additions & 0 deletions tests/sentry/integrations/utils/test_github_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ def test_a_mistyped_required_level_stops_enforcing_rather_than_raising(
"example-user",
"https://github.com/settings/installations/123/permissions/update",
),
(
"example.ghe.com:123",
"Organization",
"example-org",
"https://example.ghe.com/organizations/example-org"
"/settings/installations/123/permissions/update",
),
("123", "Organization", "", None),
("", "User", "example-user", None),
],
Expand Down
Loading