@@ -445,3 +445,68 @@ def test_get_commit_context_all_frames(self, _, __):
445
445
),
446
446
)
447
447
]
448
+
449
+ @responses .activate
450
+ def test_source_url_matches (self ):
451
+ self .assert_setup_flow ()
452
+ integration = Integration .objects .get (provider = self .provider .key )
453
+ installation = get_installation_of_type (
454
+ GitHubEnterpriseIntegration , integration , self .organization .id
455
+ )
456
+
457
+ test_cases = [
458
+ ("https://github.example.org/Test-Organization/foo" , True ),
459
+ ("https://github.example.org/Test-Organization/bar" , True ),
460
+ ("https://github.example.org/Other-Organization/bar" , False ),
461
+ ("https://github.com/Test-Organization/foo" , False ),
462
+ ]
463
+
464
+ for url , expected in test_cases :
465
+ assert installation .source_url_matches (url ) == expected
466
+
467
+ @responses .activate
468
+ def test_extract_branch_from_source_url (self ):
469
+ self .assert_setup_flow ()
470
+ integration = Integration .objects .get (provider = self .provider .key )
471
+ with assume_test_silo_mode (SiloMode .REGION ):
472
+ repo = Repository .objects .create (
473
+ organization_id = self .organization .id ,
474
+ name = "Test-Organization/foo" ,
475
+ url = "https://github.example.org/Test-Organization/foo" ,
476
+ provider = "integrations:github_enterprise" ,
477
+ external_id = 123 ,
478
+ config = {"name" : "Test-Organization/foo" },
479
+ integration_id = integration .id ,
480
+ )
481
+ installation = get_installation_of_type (
482
+ GitHubEnterpriseIntegration , integration , self .organization .id
483
+ )
484
+
485
+ source_url = "https://github.example.org/Test-Organization/foo/blob/master/src/sentry/integrations/github/integration.py"
486
+
487
+ assert installation .extract_branch_from_source_url (repo , source_url ) == "master"
488
+
489
+ @responses .activate
490
+ def test_extract_source_path_from_source_url (self ):
491
+ self .assert_setup_flow ()
492
+ integration = Integration .objects .get (provider = self .provider .key )
493
+ with assume_test_silo_mode (SiloMode .REGION ):
494
+ repo = Repository .objects .create (
495
+ organization_id = self .organization .id ,
496
+ name = "Test-Organization/foo" ,
497
+ url = "https://github.example.org/Test-Organization/foo" ,
498
+ provider = "integrations:github_enterprise" ,
499
+ external_id = 123 ,
500
+ config = {"name" : "Test-Organization/foo" },
501
+ integration_id = integration .id ,
502
+ )
503
+ installation = get_installation_of_type (
504
+ GitHubEnterpriseIntegration , integration , self .organization .id
505
+ )
506
+
507
+ source_url = "https://github.example.org/Test-Organization/foo/blob/master/src/sentry/integrations/github/integration.py"
508
+
509
+ assert (
510
+ installation .extract_source_path_from_source_url (repo , source_url )
511
+ == "src/sentry/integrations/github/integration.py"
512
+ )
0 commit comments