2121 SCMIntegrationInteractionEvent ,
2222 SCMIntegrationInteractionType ,
2323)
24- from sentry .integrations .source_code_management .repo_audit import log_repo_change
2524from sentry .organizations .services .organization import organization_service
26- from sentry .plugins .providers .integration_repository import get_integration_repository_provider
25+ from sentry .plugins .providers .integration_repository import (
26+ RepoExistsError ,
27+ get_integration_repository_provider ,
28+ )
2729from sentry .shared_integrations .exceptions import ApiError
2830from sentry .silo .base import SiloMode
2931from sentry .tasks .base import instrumented_task , retry
@@ -169,8 +171,6 @@ def sync_repos_for_org(organization_integration_id: int) -> None:
169171 if dry_run :
170172 return
171173
172- repo_by_external_id = {r .external_id : r for r in active_repos + disabled_repos }
173-
174174 if new_ids :
175175 integration_repo_provider = get_integration_repository_provider (integration )
176176 repo_configs = [
@@ -179,27 +179,12 @@ def sync_repos_for_org(organization_integration_id: int) -> None:
179179 if str (repo ["id" ]) in new_ids
180180 ]
181181 if repo_configs :
182- created_repos , reactivated_repos , _ = integration_repo_provider .create_repositories (
183- configs = repo_configs , organization = rpc_org
184- )
185-
186- for repo in created_repos :
187- log_repo_change (
188- event_name = "REPO_ADDED" ,
189- organization_id = organization_id ,
190- repo = repo ,
191- source = "repository sync" ,
192- provider = integration .provider ,
193- )
194-
195- for repo in reactivated_repos :
196- log_repo_change (
197- event_name = "REPO_ENABLED" ,
198- organization_id = organization_id ,
199- repo = repo ,
200- source = "repository sync" ,
201- provider = integration .provider ,
182+ try :
183+ integration_repo_provider .create_repositories (
184+ configs = repo_configs , organization = rpc_org
202185 )
186+ except RepoExistsError :
187+ pass
203188
204189 if removed_ids :
205190 repository_service .disable_repositories_by_external_ids (
@@ -209,31 +194,13 @@ def sync_repos_for_org(organization_integration_id: int) -> None:
209194 external_ids = list (removed_ids ),
210195 )
211196
212- for eid in removed_ids :
213- removed_repo = repo_by_external_id .get (eid )
214- if removed_repo :
215- log_repo_change (
216- event_name = "REPO_DISABLED" ,
217- organization_id = organization_id ,
218- repo = removed_repo ,
219- source = "automatic SCM syncing" ,
220- provider = integration .provider ,
221- )
222-
223197 if restored_ids :
224198 for repo in disabled_repos :
225199 if repo .external_id in restored_ids :
226200 repo .status = ObjectStatus .ACTIVE
227201 repository_service .update_repository (
228202 organization_id = organization_id , update = repo
229203 )
230- log_repo_change (
231- event_name = "REPO_ENABLED" ,
232- organization_id = organization_id ,
233- repo = repo ,
234- source = "automatic SCM syncing" ,
235- provider = integration .provider ,
236- )
237204
238205
239206@instrumented_task (
0 commit comments