-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat(bitbucket-server): CODEOWNERS support and stacktrace linking #86639
Open
jianyuan
wants to merge
4
commits into
getsentry:master
Choose a base branch
from
jianyuan:feat/codeowners-bitbucket-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3e3b7e8
feat(bitbucket-server): CODEOWNERS support and stacktrace linking
jianyuan f4fb5de
Update src/sentry/integrations/bitbucket_server/integration.py
jianyuan a026d18
Update src/sentry/integrations/bitbucket_server/integration.py
jianyuan 4df64f5
ref: BitbucketServerAPIPath
jianyuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
from collections.abc import Mapping | ||
from typing import Any | ||
from urllib.parse import urlparse | ||
from urllib.parse import parse_qs, quote, urlencode, urlparse | ||
|
||
from cryptography.hazmat.backends import default_backend | ||
from cryptography.hazmat.primitives.serialization import load_pem_private_key | ||
|
@@ -19,7 +19,6 @@ | |
FeatureDescription, | ||
IntegrationData, | ||
IntegrationDomain, | ||
IntegrationFeatureNotImplementedError, | ||
IntegrationFeatures, | ||
IntegrationMetadata, | ||
IntegrationProvider, | ||
|
@@ -62,6 +61,19 @@ | |
""", | ||
IntegrationFeatures.COMMITS, | ||
), | ||
FeatureDescription( | ||
""" | ||
Link your Sentry stack traces back to your Bitbucket Server source code with stack | ||
trace linking. | ||
""", | ||
IntegrationFeatures.STACKTRACE_LINK, | ||
), | ||
FeatureDescription( | ||
""" | ||
Import your Bitbucket Server [CODEOWNERS file](https://support.atlassian.com/bitbucket-cloud/docs/set-up-and-use-code-owners/) and use it alongside your ownership rules to assign Sentry issues. | ||
""", | ||
IntegrationFeatures.CODEOWNERS, | ||
), | ||
] | ||
|
||
setup_alert = { | ||
|
@@ -246,6 +258,8 @@ class BitbucketServerIntegration(RepositoryIntegration): | |
|
||
default_identity = None | ||
|
||
codeowners_locations = [".bitbucket/CODEOWNERS"] | ||
|
||
@property | ||
def integration_name(self) -> str: | ||
return "bitbucket_server" | ||
|
@@ -312,16 +326,40 @@ def get_unmigratable_repositories(self): | |
return list(filter(lambda repo: repo.name not in accessible_repos, repos)) | ||
|
||
def source_url_matches(self, url: str) -> bool: | ||
raise IntegrationFeatureNotImplementedError | ||
return url.startswith(self.model.metadata["base_url"]) | ||
|
||
def format_source_url(self, repo: Repository, filepath: str, branch: str | None) -> str: | ||
raise IntegrationFeatureNotImplementedError | ||
project = quote(repo.config["project"]) | ||
repo_name = quote(repo.config["repo"]) | ||
source_url = f"{self.model.metadata["base_url"]}/projects/{project}/repos/{repo_name}/browse/{filepath}" | ||
|
||
if branch: | ||
source_url += "?" + urlencode({"at": branch}) | ||
|
||
return source_url | ||
|
||
def extract_branch_from_source_url(self, repo: Repository, url: str) -> str: | ||
raise IntegrationFeatureNotImplementedError | ||
parsed_url = urlparse(url) | ||
qs = parse_qs(parsed_url.query) | ||
|
||
if "at" in qs and len(qs["at"]) == 1: | ||
branch = qs["at"][0] | ||
|
||
# branch name may be prefixed with refs/heads/, so we strip that | ||
refs_prefix = "refs/heads/" | ||
if branch.startswith(refs_prefix): | ||
branch = branch[len(refs_prefix) :] | ||
|
||
return branch | ||
|
||
return "" | ||
|
||
def extract_source_path_from_source_url(self, repo: Repository, url: str) -> str: | ||
raise IntegrationFeatureNotImplementedError | ||
if repo.url is None: | ||
return "" | ||
parsed_repo_url = urlparse(repo.url) | ||
parsed_url = urlparse(url) | ||
return parsed_url.path.replace(parsed_repo_url.path + "/", "") | ||
Comment on lines
+358
to
+362
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm also curious how this is different from bitbucket, it kind of looks the same? |
||
|
||
# Bitbucket Server only methods | ||
|
||
|
@@ -336,7 +374,13 @@ class BitbucketServerIntegrationProvider(IntegrationProvider): | |
metadata = metadata | ||
integration_cls = BitbucketServerIntegration | ||
needs_default_identity = True | ||
features = frozenset([IntegrationFeatures.COMMITS]) | ||
features = frozenset( | ||
[ | ||
IntegrationFeatures.COMMITS, | ||
IntegrationFeatures.STACKTRACE_LINK, | ||
IntegrationFeatures.CODEOWNERS, | ||
] | ||
) | ||
setup_dialog_config = {"width": 1030, "height": 1000} | ||
|
||
def get_pipeline_views(self) -> list[PipelineView]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from urllib.parse import quote, urlencode | ||
|
||
|
||
class BitbucketServerAPIPath: | ||
""" | ||
project is the short key of the project | ||
repo is the fully qualified slug | ||
""" | ||
|
||
repository = "/rest/api/1.0/projects/{project}/repos/{repo}" | ||
repositories = "/rest/api/1.0/repos" | ||
repository_hook = "/rest/api/1.0/projects/{project}/repos/{repo}/webhooks/{id}" | ||
repository_hooks = "/rest/api/1.0/projects/{project}/repos/{repo}/webhooks" | ||
repository_commits = "/rest/api/1.0/projects/{project}/repos/{repo}/commits" | ||
commit_changes = "/rest/api/1.0/projects/{project}/repos/{repo}/commits/{commit}/changes" | ||
|
||
@staticmethod | ||
def build_raw(project: str, repo: str, path: str, sha: str) -> str: | ||
project = quote(project) | ||
repo = quote(repo) | ||
|
||
params = {} | ||
if sha: | ||
params["at"] = sha | ||
|
||
return f"/projects/{project}/repos/{repo}/raw/{path}?{urlencode(params)}" | ||
|
||
@staticmethod | ||
def build_source(project: str, repo: str, path: str, sha: str) -> str: | ||
project = quote(project) | ||
repo = quote(repo) | ||
|
||
params = {} | ||
if sha: | ||
params["at"] = sha | ||
|
||
return f"/rest/api/1.0/projects/{project}/repos/{repo}/browse/{path}?{urlencode(params)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you explain what the "at" means here? i am curious how this is different from bitbucket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see,
at
refers to the branch i think