@@ -445,3 +445,71 @@ 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
+ ("http://github.example.org/Test-Organization/foo" , True ),
461
+ ("http://github.example.org/Test-Organization/bar" , True ),
462
+ ("https://github.example.org/Other-Organization/bar" , False ),
463
+ ("http://github.example.org/Other-Organization/bar" , False ),
464
+ ("https://github.com/Test-Organization/foo" , False ),
465
+ ]
466
+
467
+ for url , expected in test_cases :
468
+ assert installation .source_url_matches (url ) == expected
469
+
470
+ @responses .activate
471
+ def test_extract_branch_from_source_url (self ):
472
+ self .assert_setup_flow ()
473
+ integration = Integration .objects .get (provider = self .provider .key )
474
+ with assume_test_silo_mode (SiloMode .REGION ):
475
+ repo = Repository .objects .create (
476
+ organization_id = self .organization .id ,
477
+ name = "Test-Organization/foo" ,
478
+ url = "https://github.example.org/Test-Organization/foo" ,
479
+ provider = "integrations:github_enterprise" ,
480
+ external_id = 123 ,
481
+ config = {"name" : "Test-Organization/foo" },
482
+ integration_id = integration .id ,
483
+ )
484
+ installation = get_installation_of_type (
485
+ GitHubEnterpriseIntegration , integration , self .organization .id
486
+ )
487
+
488
+ source_url = "https://github.example.org/Test-Organization/foo/blob/master/src/sentry/integrations/github/integration.py"
489
+
490
+ assert installation .extract_branch_from_source_url (repo , source_url ) == "master"
491
+
492
+ @responses .activate
493
+ def test_extract_source_path_from_source_url (self ):
494
+ self .assert_setup_flow ()
495
+ integration = Integration .objects .get (provider = self .provider .key )
496
+ with assume_test_silo_mode (SiloMode .REGION ):
497
+ repo = Repository .objects .create (
498
+ organization_id = self .organization .id ,
499
+ name = "Test-Organization/foo" ,
500
+ url = "https://github.example.org/Test-Organization/foo" ,
501
+ provider = "integrations:github_enterprise" ,
502
+ external_id = 123 ,
503
+ config = {"name" : "Test-Organization/foo" },
504
+ integration_id = integration .id ,
505
+ )
506
+ installation = get_installation_of_type (
507
+ GitHubEnterpriseIntegration , integration , self .organization .id
508
+ )
509
+
510
+ source_url = "https://github.example.org/Test-Organization/foo/blob/master/src/sentry/integrations/github/integration.py"
511
+
512
+ assert (
513
+ installation .extract_source_path_from_source_url (repo , source_url )
514
+ == "src/sentry/integrations/github/integration.py"
515
+ )
0 commit comments