@@ -360,6 +360,68 @@ def _clean_up_files_after_post_processing(output: str, library_id: str):
360360 ): # pragma: NO COVER
361361 os .remove (gapic_version_file )
362362
363+ def _create_repo_metadata_from_service_config (
364+ service_config_name : str , api_path : str , source : str , library_id : str
365+ ) -> Dict :
366+ """Creates the .repo-metadata.json content from the service config.
367+
368+ Args:
369+ service_config_name (str): The name of the service config file.
370+ api_path (str): The path to the API.
371+ source (str): The path to the source directory.
372+ library_id (str): The ID of the library.
373+
374+ Returns:
375+ Dict: The content of the .repo-metadata.json file.
376+ """
377+ full_service_config_path = f"{ source } /{ api_path } /{ service_config_name } "
378+
379+ # TODO(ohmayr): Read the api service config to backfill .repo-metadata.json
380+ return {
381+ "api_shortname" : "" ,
382+ "name_pretty" : "" ,
383+ "product_documentation" : "" ,
384+ "api_description" : "" ,
385+ "client_documentation" : "" ,
386+ "issue_tracker" : "" ,
387+ "release_level" : "" ,
388+ "language" : "python" ,
389+ "library_type" : "GAPIC_AUTO" ,
390+ "repo" : "googleapis/google-cloud-python" ,
391+ "distribution_name" : "" ,
392+ "api_id" : "" ,
393+ }
394+
395+
396+ def _generate_repo_metadata_file (
397+ output : str , library_id : str , source : str , apis : List [Dict ]
398+ ):
399+ """Generates the .repo-metadata.json file from the primary API service config.
400+
401+ Args:
402+ output (str): The path to the output directory.
403+ library_id (str): The ID of the library.
404+ source (str): The path to the source directory.
405+ apis (List[Dict]): A list of APIs to generate.
406+ """
407+ path_to_library = f"packages/{ library_id } "
408+ output_repo_metadata = f"{ output } /{ path_to_library } /.repo-metadata.json"
409+
410+ os .makedirs (f"{ output } /{ path_to_library } " , exist_ok = True )
411+
412+ # TODO(ohmayr): Programatically determine the primary api to be used to
413+ # to determine the information for metadata. For now, let's use the first
414+ # api in the list.
415+ primary_api = apis [0 ]
416+
417+ metadata_content = _create_repo_metadata_from_service_config (
418+ primary_api .get ("service_config" ),
419+ primary_api .get ("path" ),
420+ source ,
421+ library_id ,
422+ )
423+ _write_json_file (output_repo_metadata , metadata_content )
424+
363425
364426def handle_generate (
365427 librarian : str = LIBRARIAN_DIR ,
@@ -398,6 +460,7 @@ def handle_generate(
398460 api_path = api .get ("path" )
399461 if api_path :
400462 _generate_api (api_path , library_id , source , output )
463+ _generate_repo_metadata_file (output , library_id , source , apis_to_generate )
401464 _copy_files_needed_for_post_processing (output , input , library_id )
402465 _run_post_processor (output , library_id )
403466 _clean_up_files_after_post_processing (output , library_id )
0 commit comments