Skip to content

fix(scm): Pick the code-mapping integration by its matching repository - #128328

Open
vaind wants to merge 3 commits into
masterfrom
ivan/repo-path-parsing-pick-integration-by-repo
Open

vaind wants to merge 3 commits into
masterfrom
ivan/repo-path-parsing-pick-integration-by-repo

Conversation

@vaind

@vaind vaind commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #128174 (comment).

When you set up a code mapping by pasting a file link, Sentry asks each connected integration whether the link belongs to it, takes the first one that says yes, and then looks for the repository in that integration only.

Some integrations rightly say yes to the same links. Bitbucket Cloud can't tell its workspaces apart from the link: for personal accounts the integration doesn't store the workspace name, so every Bitbucket Cloud integration says yes to every bitbucket.org link. A GitLab integration for a group also says yes to links into its subgroups. With two such integrations connected, the first one checked always wins, and a link to the other one's repository fails with "Could not find repo".

Now Sentry looks for the repository across every integration that says yes, and uses the integration that owns it. Any provider whose integrations can overlap gets the same fix, without each one needing to narrow its own check.

The endpoint never skipped integrations that are disabled, or disabled for the organization, and searching all of them would reach a disabled one's repository whenever no active one has it. Saving the code mapping doesn't check status either, so its stack trace links would never work. Only active integrations are considered now.

The repository match had the same bug the integration checks just had fixed: it compared raw text, so repository acme/api also claimed links to acme/api-v2. It now uses url_is_under, which requires a / after the repository path.

The overlap and repository-match tests fail on master, and the disabled-integration tests fail without the status filter.

With two Bitbucket Cloud workspaces connected, both integrations claim every bitbucket.org link,
so whichever was checked first won and the link to the other workspace's repo failed with
"Could not find repo". Search repos across every integration that claims the link and take the
integration that owns the match instead.

The repo match also used a raw prefix, so repo acme/api claimed links to acme/api-v2. It now
uses url_is_under like the integration checks.
@vaind
vaind requested a review from a team as a code owner October 21, 2026 09:01
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 21, 2026
vaind added a commit that referenced this pull request Oct 21, 2026
…128174)

Stacked on #128168, which adds
the shared `url_is_under` helper.

When you set up a code mapping by pasting a file link, Sentry asks each
integration whether the link belongs to it. Bitbucket Cloud said yes if
the link started with the text `https://bitbucket.org`, so it also
accepted hosts like `bitbucket.org.other.net`. Its other condition,
`https://` + `domain_name`, never added anything:

- **Teams:** `domain_name` is `bitbucket.org/<workspace>`, which the
first condition already covers.
- **Personal accounts:** `domain_name` is a bare username, which never
matches a real link.

The check is now `url_is_under(url, "https://bitbucket.org")`. Every
real bitbucket.org link still matches, and lookalike hosts don't. The
new test case fails on the base branch.

This check still can't limit each integration to its own workspace,
because for personal accounts `domain_name` doesn't hold the workspace.
#128328 handles that where the
check is called: when several integrations claim a link, the one that
owns the matching repository wins.

---------

Co-authored-by: Claude <noreply@anthropic.com>
The endpoint never checked whether an integration, or its install on the organization, is
active. Searching every matching integration made that reachable in a new way: when an active
integration lacks the repo, a disabled one that has it now wins. Saving the mapping does not
check status either, so the user would get a code mapping whose stack trace links never work.

Also covers a GitLab group and its subgroup claiming the same link, alongside the Bitbucket case.
@sentry

sentry Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Sentry Snapshot Testing

Name Added Removed Changed Renamed Unchanged Skipped Status
sentry-frontend
sentry-frontend
0 0 0 0 760 0 ✅ Unchanged

⚙️ sentry-frontend Snapshot Settings

This branch was successfully deployed

1 active deployment
Preview — 9a271864 Deployed Oct 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant