11use std:: env;
22
3- use lazy_static:: lazy_static;
4- use regex:: Regex ;
53use simplelog:: SharedLogger ;
64
75use crate :: prelude:: * ;
6+ use crate :: run:: helpers:: { parse_git_remote, GitRemote } ;
87use crate :: run:: {
98 ci_provider:: {
109 interfaces:: { CIProviderMetadata , RepositoryProvider , RunEvent } ,
@@ -27,16 +26,6 @@ pub struct BuildkiteProvider {
2726 repository_root_path : String ,
2827}
2928
30- lazy_static ! {
31- static ref GITHUB_URL_REGEX : Regex = Regex :: new(
32- r"(?x)
33- (?:https://github.com/|git@github.com:)
34- (?P<owner>[^/]+)/(?P<repository>[^/.]+)\.git
35- "
36- )
37- . expect( "Failed to compile GitHub URL regex" ) ;
38- }
39-
4029pub fn get_pr_number ( ) -> Result < Option < u64 > > {
4130 Ok ( get_env_variable ( "BUILDKITE_PULL_REQUEST" ) ?. parse ( ) . ok ( ) )
4231}
@@ -64,24 +53,6 @@ pub fn get_ref() -> Result<String> {
6453 }
6554}
6655
67- pub fn get_owner_and_repository ( ) -> Result < ( String , String ) > {
68- let repository_url = get_env_variable ( "BUILDKITE_REPO" ) ?;
69- let captures = GITHUB_URL_REGEX
70- . captures ( & repository_url)
71- . context ( "Failed to parse the GitHub repository URL" ) ?;
72-
73- let owner = captures
74- . name ( "owner" )
75- . context ( "Failed to parse the GitHub repository URL" ) ?
76- . as_str ( ) ;
77- let repository = captures
78- . name ( "repository" )
79- . context ( "Failed to parse the GitHub repository URL" ) ?
80- . as_str ( ) ;
81-
82- Ok ( ( owner. into ( ) , repository. into ( ) ) )
83- }
84-
8556impl TryFrom < & Config > for BuildkiteProvider {
8657 type Error = Error ;
8758 fn try_from ( config : & Config ) -> Result < Self > {
@@ -90,7 +61,18 @@ impl TryFrom<&Config> for BuildkiteProvider {
9061 }
9162
9263 let is_pr = get_pr_number ( ) ?. is_some ( ) ;
93- let ( owner, repository) = get_owner_and_repository ( ) ?;
64+ let repository_url = get_env_variable ( "BUILDKITE_REPO" ) ?;
65+ let GitRemote {
66+ owner,
67+ repository,
68+ domain,
69+ } = parse_git_remote ( & repository_url) ?;
70+
71+ if domain != "github.com" {
72+ bail ! (
73+ "Only GitHub repositories are supported by CodSpeed BuildKite integration for now."
74+ ) ;
75+ }
9476
9577 let repository_root_path = match find_repository_root ( & std:: env:: current_dir ( ) ?) {
9678 Some ( mut path) => {
@@ -181,29 +163,6 @@ mod tests {
181163 } ) ;
182164 }
183165
184- #[ test]
185- fn test_get_owner_and_repository ( ) {
186- with_var (
187- "BUILDKITE_REPO" ,
188- Some ( "https://github.com/my-org/adrien-python-test.git" ) ,
189- || {
190- let ( owner, repository) = get_owner_and_repository ( ) . unwrap ( ) ;
191- assert_eq ! ( owner, "my-org" ) ;
192- assert_eq ! ( repository, "adrien-python-test" ) ;
193- } ,
194- ) ;
195-
196- with_var (
197- "BUILDKITE_REPO" ,
198- Some ( "git@github.com:my-org/adrien-python-test.git" ) ,
199- || {
200- let ( owner, repository) = get_owner_and_repository ( ) . unwrap ( ) ;
201- assert_eq ! ( owner, "my-org" ) ;
202- assert_eq ! ( repository, "adrien-python-test" ) ;
203- } ,
204- ) ;
205- }
206-
207166 #[ test]
208167 fn test_try_from_push_main ( ) {
209168 with_vars (
0 commit comments