@@ -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,16 +80,19 @@ pub trait RunEnvironmentProvider {
9480 run_part : self . get_run_provider_run_part ( ) ,
9581 } )
9682 }
97- }
9883
99- #[ cfg( test) ]
100- mod tests {
101- use super :: * ;
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+ let repo = Repository :: open ( repository_root_path) . context ( format ! (
87+ "Failed to open repository at path: {repository_root_path}"
88+ ) ) ?;
10289
103- #[ test]
104- fn test_get_commit_hash ( ) {
105- let commit_hash = get_commit_hash ( env ! ( "CARGO_MANIFEST_DIR" ) ) . unwrap ( ) ;
106- // ensure that the commit hash is correct, thus it has 40 characters
107- assert_eq ! ( commit_hash. len( ) , 40 ) ;
90+ let commit_hash = repo
91+ . head ( )
92+ . and_then ( |head| head. peel_to_commit ( ) )
93+ . context ( "Failed to get HEAD commit" ) ?
94+ . id ( )
95+ . to_string ( ) ;
96+ Ok ( commit_hash)
10897 }
10998}
0 commit comments