@@ -13,7 +13,11 @@ use std::{
1313use tokio:: sync:: { RwLock , mpsc} ;
1414use tokio_stream:: wrappers:: ReceiverStream ;
1515
16- use bellatrix:: { Bellatrix , orion_client:: BuildInfo , orion_client:: OrionBuildRequest } ;
16+ use bellatrix:: {
17+ Bellatrix ,
18+ orion_client:: OrionBuildRequest ,
19+ orion_client:: { BuildInfo , ProjectRelativePath , Status } ,
20+ } ;
1721use callisto:: {
1822 entity_ext:: generate_link, mega_cl, mega_refs, raw_blob, sea_orm_active_enums:: ConvTypeEnum ,
1923} ;
@@ -587,6 +591,29 @@ impl MonoRepo {
587591 let mono_stg = self . storage . mono_storage ( ) ;
588592 let mono_api_service: MonoApiService = self . into ( ) ;
589593
594+ let mut path = Some ( cl_path) ;
595+ let mut path_q = Vec :: new ( ) ;
596+ while let Some ( p) = path {
597+ path_q. push ( p) ;
598+ path = p. parent ( ) ;
599+ }
600+ if path_q. len ( ) > 2 {
601+ path_q. pop ( ) ;
602+ path_q. pop ( ) ;
603+
604+ let p = path_q[ path_q. len ( ) - 1 ] ;
605+ if p. parent ( ) . is_some ( )
606+ && let Some ( tree) = tree_ops:: search_tree_by_path ( & mono_api_service, p, None )
607+ . await
608+ . ok ( )
609+ . flatten ( )
610+ && let Some ( buck) = self . try_extract_buck ( tree, cl_path)
611+ {
612+ return Ok ( vec ! [ buck] ) ;
613+ } ;
614+ return Ok ( vec ! [ ] ) ;
615+ }
616+
590617 let mut search_trees: Vec < ( PathBuf , Tree ) > = vec ! [ ] ;
591618
592619 let diff_trees = self . diff_trees_from_cl ( ) . await ?;
@@ -608,23 +635,6 @@ impl MonoRepo {
608635 }
609636 }
610637
611- // no buck file found
612- if res. is_empty ( ) {
613- let mut path = Some ( cl_path) ;
614- while let Some ( p) = path {
615- if p. parent ( ) . is_some ( )
616- && let Some ( tree) = tree_ops:: search_tree_by_path ( & mono_api_service, p, None )
617- . await
618- . ok ( )
619- . flatten ( )
620- && let Some ( buck) = self . try_extract_buck ( tree, cl_path)
621- {
622- return Ok ( vec ! [ buck] ) ;
623- } ;
624-
625- path = p. parent ( ) ;
626- }
627- }
628638 Ok ( res)
629639 }
630640
@@ -910,7 +920,38 @@ impl MonoRepo {
910920 self . path
911921 ) ;
912922 } else {
923+ let old_files = self . get_commit_blobs ( & cl_info. from_hash ) . await ?;
924+ let new_files = self . get_commit_blobs ( & cl_info. to_hash ) . await ?;
925+ let cl_diff_files = self . cl_files_list ( old_files, new_files. clone ( ) ) . await ?;
926+
927+ let cl_base = PathBuf :: from ( & cl_info. path ) ;
928+ let changes = cl_diff_files
929+ . into_iter ( )
930+ . map ( |m| {
931+ let mut item: crate :: model:: change_list:: ClFilesRes = m. into ( ) ;
932+ item. path = cl_base. join ( item. path ) . to_string_lossy ( ) . to_string ( ) ;
933+ item
934+ } )
935+ . collect :: < Vec < _ > > ( ) ;
936+
913937 for buck_file in buck_files {
938+ let path_str = buck_file. path . to_str ( ) . expect ( "path is not valid UTF-8" ) ;
939+ let counter_changes: Vec < _ > = changes
940+ . iter ( )
941+ . filter ( |& s| PathBuf :: from ( & s. path ) . starts_with ( & buck_file. path ) )
942+ . map ( |s| {
943+ let path = ProjectRelativePath :: from_abs ( & s. path , path_str) . unwrap ( ) ;
944+ if s. action == "new" {
945+ Status :: Added ( path)
946+ } else if s. action == "deleted" {
947+ Status :: Removed ( path)
948+ } else if s. action == "modified" {
949+ Status :: Modified ( path)
950+ } else {
951+ unreachable ! ( )
952+ }
953+ } )
954+ . collect ( ) ;
914955 let req = OrionBuildRequest {
915956 repo : buck_file. path . to_str ( ) . unwrap ( ) . to_string ( ) ,
916957 cl_link : link. to_string ( ) ,
@@ -921,6 +962,7 @@ impl MonoRepo {
921962 buck_hash: buck_file. buck. to_string( ) ,
922963 buckconfig_hash: buck_file. buck_config. to_string( ) ,
923964 args: Some ( vec![ ] ) ,
965+ changes: counter_changes,
924966 } ] ,
925967 } ;
926968 let bellatrix = self . bellatrix . clone ( ) ;
@@ -935,6 +977,23 @@ impl MonoRepo {
935977 check_reg. run_checks ( cl_info. clone ( ) . into ( ) ) . await ?;
936978 Ok ( ( ) )
937979 }
980+
981+ pub async fn get_commit_blobs (
982+ & self ,
983+ commit_hash : & str ,
984+ ) -> Result < Vec < ( PathBuf , SHA1 ) > , MegaError > {
985+ let api_service: MonoApiService = self . into ( ) ;
986+ api_service. get_commit_blobs ( commit_hash) . await
987+ }
988+
989+ pub async fn cl_files_list (
990+ & self ,
991+ old_files : Vec < ( PathBuf , SHA1 ) > ,
992+ new_files : Vec < ( PathBuf , SHA1 ) > ,
993+ ) -> Result < Vec < crate :: model:: change_list:: ClDiffFile > , MegaError > {
994+ let api_service: MonoApiService = self . into ( ) ;
995+ api_service. cl_files_list ( old_files, new_files) . await
996+ }
938997}
939998
940999type DiffResult = Vec < ( PathBuf , Option < SHA1 > , Option < SHA1 > ) > ;
0 commit comments