@@ -176,58 +176,63 @@ def create_repos_and_code_mappings(
176176 raise InstallationNotFoundError
177177
178178 organization_id = organization_integration .organization_id
179- for code_mapping in code_mappings :
180- repository = (
181- Repository .objects .filter (name = code_mapping .repo .name , organization_id = organization_id )
182- .order_by ("-date_added" )
183- .first ()
184- )
185-
186- if not repository :
187- if not dry_run :
188- repository = Repository .objects .create (
189- name = code_mapping .repo .name ,
190- organization_id = organization_id ,
191- integration_id = organization_integration .integration_id ,
179+ with metrics .timer (
180+ f"{ METRIC_PREFIX } .create_configurations.duration" , tags = {"platform" : platform }
181+ ):
182+ for code_mapping in code_mappings :
183+ repository = (
184+ Repository .objects .filter (
185+ name = code_mapping .repo .name , organization_id = organization_id
192186 )
193- metrics .incr (
194- key = f"{ METRIC_PREFIX } .repository.created" ,
195- tags = {"platform" : platform , "dry_run" : dry_run },
196- sample_rate = 1.0 ,
187+ .order_by ("-date_added" )
188+ .first ()
197189 )
198190
199- extra = {
200- "project_id" : project .id ,
201- "stack_root" : code_mapping .stacktrace_root ,
202- "repository_name" : code_mapping .repo .name ,
203- }
204- # The project and stack_root are unique together
205- existing_code_mappings = RepositoryProjectPathConfig .objects .filter (
206- project = project , stack_root = code_mapping .stacktrace_root
207- )
208- if existing_code_mappings .exists ():
209- logger .warning ("Investigate." , extra = extra )
210- continue
211-
212- if not dry_run :
213- if repository is None : # This is mostly to appease the type checker
191+ if not repository :
192+ if not dry_run :
193+ repository = Repository .objects .create (
194+ name = code_mapping .repo .name ,
195+ organization_id = organization_id ,
196+ integration_id = organization_integration .integration_id ,
197+ )
198+ metrics .incr (
199+ key = f"{ METRIC_PREFIX } .repository.created" ,
200+ tags = {"platform" : platform , "dry_run" : dry_run },
201+ sample_rate = 1.0 ,
202+ )
203+
204+ extra = {
205+ "project_id" : project .id ,
206+ "stack_root" : code_mapping .stacktrace_root ,
207+ "repository_name" : code_mapping .repo .name ,
208+ }
209+ # The project and stack_root are unique together
210+ existing_code_mappings = RepositoryProjectPathConfig .objects .filter (
211+ project = project , stack_root = code_mapping .stacktrace_root
212+ )
213+ if existing_code_mappings .exists ():
214214 logger .warning ("Investigate." , extra = extra )
215215 continue
216216
217- RepositoryProjectPathConfig .objects .create (
218- project = project ,
219- stack_root = code_mapping .stacktrace_root ,
220- repository = repository ,
221- organization_integration_id = organization_integration .id ,
222- integration_id = organization_integration .integration_id ,
223- organization_id = organization_integration .organization_id ,
224- source_root = code_mapping .source_path ,
225- default_branch = code_mapping .repo .branch ,
226- automatically_generated = True ,
227- )
217+ if not dry_run :
218+ if repository is None : # This is mostly to appease the type checker
219+ logger .warning ("Investigate." , extra = extra )
220+ continue
221+
222+ RepositoryProjectPathConfig .objects .create (
223+ project = project ,
224+ stack_root = code_mapping .stacktrace_root ,
225+ repository = repository ,
226+ organization_integration_id = organization_integration .id ,
227+ integration_id = organization_integration .integration_id ,
228+ organization_id = organization_integration .organization_id ,
229+ source_root = code_mapping .source_path ,
230+ default_branch = code_mapping .repo .branch ,
231+ automatically_generated = True ,
232+ )
228233
229- metrics .incr (
230- key = f"{ METRIC_PREFIX } .code_mapping.created" ,
231- tags = {"platform" : platform , "dry_run" : dry_run },
232- sample_rate = 1.0 ,
233- )
234+ metrics .incr (
235+ key = f"{ METRIC_PREFIX } .code_mapping.created" ,
236+ tags = {"platform" : platform , "dry_run" : dry_run },
237+ sample_rate = 1.0 ,
238+ )
0 commit comments