@@ -81,7 +81,23 @@ def _determine_bazel_rule(api_path: str) -> str:
8181 return bazel_rule
8282 except Exception as e :
8383 raise ValueError (f"Bazelisk query `{ query } ` failed" ) from e
84+
85+ def _get_library_id (request_data : Dict ) -> str :
86+ """Retrieve the library id from the given request dictionary
87+
88+ Args:
89+ request_data(Dict): The contents `generate-request.json`.
90+
91+ Raises:
92+ ValueError: If the key `id` does not exist in `request_data`.
8493
94+ Returns:
95+ str: The id of the library in `generate-request.json`
96+ """
97+ library_id = request_data .get ("id" )
98+ if not library_id :
99+ raise ValueError ("Request file is missing required 'id' field." )
100+ return library_id
85101
86102def handle_generate ():
87103 """The main coordinator for the code generation process.
@@ -97,9 +113,7 @@ def handle_generate():
97113 # Read a generate-request.json file
98114 try :
99115 request_data = _read_json_file (f"{ LIBRARIAN_DIR } /{ GENERATE_REQUEST_FILE } " )
100- library_id = request_data .get ("id" )
101- if not library_id :
102- raise ValueError ("Request file is missing required 'id' field." )
116+ library_id = _get_library_id (request_data )
103117
104118 for api in request_data .get ("apis" , []):
105119 api_path = api .get ("path" )
@@ -124,7 +138,7 @@ def _run_nox_sessions(sessions: List[str]):
124138 current_session = None
125139 try :
126140 request_data = _read_json_file (f"{ LIBRARIAN_DIR } /{ GENERATE_REQUEST_FILE } " )
127- library_id = request_data . get ( "id" )
141+ library_id = _get_library_id ( request_data )
128142 for nox_session in sessions :
129143 current_session = nox_session
130144 command = [
0 commit comments