Skip to content

feat(github-enterprise): Stacktrace linking for GitHub Enterprise #86744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
11 changes: 7 additions & 4 deletions src/sentry/integrations/github_enterprise/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from sentry.integrations.base import (
FeatureDescription,
IntegrationData,
IntegrationFeatureNotImplementedError,
IntegrationFeatures,
IntegrationMetadata,
)
Expand Down Expand Up @@ -212,18 +211,22 @@ def get_repositories(self, query: str | None = None) -> list[dict[str, Any]]:
]

def source_url_matches(self, url: str) -> bool:
raise IntegrationFeatureNotImplementedError
return url.startswith(f"https://{self.model.metadata["domain_name"]}")

def format_source_url(self, repo: Repository, filepath: str, branch: str | None) -> str:
# Must format the url ourselves since `check_file` is a head request
# "https://github.example.org/octokit/octokit.rb/blob/master/README.md"
return f"{repo.url}/blob/{branch}/{filepath}"

def extract_branch_from_source_url(self, repo: Repository, url: str) -> str:
raise IntegrationFeatureNotImplementedError
url = url.replace(f"{repo.url}/blob/", "")
branch, _, _ = url.partition("/")
return branch

def extract_source_path_from_source_url(self, repo: Repository, url: str) -> str:
raise IntegrationFeatureNotImplementedError
url = url.replace(f"{repo.url}/blob/", "")
_, _, source_path = url.partition("/")
return source_path

def search_issues(self, query: str | None, **kwargs):
return self.get_client().search_issues(query)
Expand Down
65 changes: 65 additions & 0 deletions tests/sentry/integrations/github_enterprise/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,68 @@ def test_get_commit_context_all_frames(self, _, __):
),
)
]

@responses.activate
def test_source_url_matches(self):
self.assert_setup_flow()
integration = Integration.objects.get(provider=self.provider.key)
installation = get_installation_of_type(
GitHubEnterpriseIntegration, integration, self.organization.id
)

test_cases = [
("https://github.example.org/Test-Organization/foo", True),
("https://github.example.org/Test-Organization/bar", True),
("https://github.example.org/Other-Organization/bar", False),
("https://github.com/Test-Organization/foo", False),
]

for url, expected in test_cases:
assert installation.source_url_matches(url) == expected

@responses.activate
def test_extract_branch_from_source_url(self):
self.assert_setup_flow()
integration = Integration.objects.get(provider=self.provider.key)
with assume_test_silo_mode(SiloMode.REGION):
repo = Repository.objects.create(
organization_id=self.organization.id,
name="Test-Organization/foo",
url="https://github.example.org/Test-Organization/foo",
provider="integrations:github_enterprise",
external_id=123,
config={"name": "Test-Organization/foo"},
integration_id=integration.id,
)
installation = get_installation_of_type(
GitHubEnterpriseIntegration, integration, self.organization.id
)

source_url = "https://github.example.org/Test-Organization/foo/blob/master/src/sentry/integrations/github/integration.py"

assert installation.extract_branch_from_source_url(repo, source_url) == "master"

@responses.activate
def test_extract_source_path_from_source_url(self):
self.assert_setup_flow()
integration = Integration.objects.get(provider=self.provider.key)
with assume_test_silo_mode(SiloMode.REGION):
repo = Repository.objects.create(
organization_id=self.organization.id,
name="Test-Organization/foo",
url="https://github.example.org/Test-Organization/foo",
provider="integrations:github_enterprise",
external_id=123,
config={"name": "Test-Organization/foo"},
integration_id=integration.id,
)
installation = get_installation_of_type(
GitHubEnterpriseIntegration, integration, self.organization.id
)

source_url = "https://github.example.org/Test-Organization/foo/blob/master/src/sentry/integrations/github/integration.py"

assert (
installation.extract_source_path_from_source_url(repo, source_url)
== "src/sentry/integrations/github/integration.py"
)
Loading