Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _auto_create_repository(
organization_id=organization.id,
provider=repo_provider,
integration_id=org_int.integration_id,
external_id=repo_info.get("identifier", ""),
external_id=repo_info["external_id"],
), None
except IntegrityError:
# Race condition — repo was created between our lookup and now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,21 +351,18 @@ def test_auto_create_repository_when_provider_given(self) -> None:
name=new_repo_name, organization_id=self.organization.id
).exists()

def fake_auto_create(organization, repo_name, provider):
repo, _ = Repository.objects.get_or_create(
name=repo_name,
organization_id=organization.id,
defaults={
"integration_id": self.integration.id,
"provider": "integrations:github",
},
)
return repo, None
mock_repos = [
{
"name": "new-repo",
"identifier": new_repo_name,
"external_id": "99999",
"default_branch": "main",
}
]

with mock.patch(
"sentry.integrations.api.endpoints.organization_code_mappings_bulk."
"OrganizationCodeMappingsBulkEndpoint._auto_create_repository",
side_effect=fake_auto_create,
"sentry.integrations.github.integration.GitHubIntegration.get_repositories",
return_value=mock_repos,
):
response = self.make_post(
{
Expand All @@ -379,6 +376,7 @@ def fake_auto_create(organization, repo_name, provider):
repo = Repository.objects.get(name=new_repo_name, organization_id=self.organization.id)
assert repo.provider == "integrations:github"
assert repo.integration_id == self.integration.id
assert repo.external_id == "99999"

def test_skip_post_save_does_not_leak_to_fetched_instances(self) -> None:
"""The endpoint sets _skip_post_save on in-memory instances to batch
Expand Down
Loading