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