@@ -16,20 +16,6 @@ pub trait RunEnvironmentDetector {
1616 fn detect ( ) -> bool ;
1717}
1818
19- fn get_commit_hash ( repository_root_path : & str ) -> Result < String > {
20- let repo = Repository :: open ( repository_root_path) . context ( format ! (
21- "Failed to open repository at path: {repository_root_path}"
22- ) ) ?;
23-
24- let commit_hash = repo
25- . head ( )
26- . and_then ( |head| head. peel_to_commit ( ) )
27- . context ( "Failed to get HEAD commit" ) ?
28- . id ( )
29- . to_string ( ) ;
30- Ok ( commit_hash)
31- }
32-
3319/// `RunEnvironmentProvider` is a trait that defines the necessary methods
3420/// for a continuous integration provider.
3521pub trait RunEnvironmentProvider {
@@ -73,7 +59,7 @@ pub trait RunEnvironmentProvider {
7359 ) -> Result < UploadMetadata > {
7460 let run_environment_metadata = self . get_run_environment_metadata ( ) ?;
7561
76- let commit_hash = get_commit_hash ( & run_environment_metadata. repository_root_path ) ?;
62+ let commit_hash = self . get_commit_hash ( & run_environment_metadata. repository_root_path ) ?;
7763
7864 Ok ( UploadMetadata {
7965 version : Some ( LATEST_UPLOAD_METADATA_VERSION ) ,
@@ -94,6 +80,25 @@ pub trait RunEnvironmentProvider {
9480 run_part : self . get_run_provider_run_part ( ) ,
9581 } )
9682 }
83+
84+ /// Returns the HEAD commit hash of the repository at the given path.
85+ fn get_commit_hash ( & self , repository_root_path : & str ) -> Result < String > {
86+ get_commit_hash_default_impl ( repository_root_path)
87+ }
88+ }
89+
90+ fn get_commit_hash_default_impl ( repository_root_path : & str ) -> Result < String > {
91+ let repo = Repository :: open ( repository_root_path) . context ( format ! (
92+ "Failed to open repository at path: {repository_root_path}"
93+ ) ) ?;
94+
95+ let commit_hash = repo
96+ . head ( )
97+ . and_then ( |head| head. peel_to_commit ( ) )
98+ . context ( "Failed to get HEAD commit" ) ?
99+ . id ( )
100+ . to_string ( ) ;
101+ Ok ( commit_hash)
97102}
98103
99104#[ cfg( test) ]
@@ -102,7 +107,7 @@ mod tests {
102107
103108 #[ test]
104109 fn test_get_commit_hash ( ) {
105- let commit_hash = get_commit_hash ( env ! ( "CARGO_MANIFEST_DIR" ) ) . unwrap ( ) ;
110+ let commit_hash = get_commit_hash_default_impl ( env ! ( "CARGO_MANIFEST_DIR" ) ) . unwrap ( ) ;
106111 // ensure that the commit hash is correct, thus it has 40 characters
107112 assert_eq ! ( commit_hash. len( ) , 40 ) ;
108113 }
0 commit comments