Skip to content

Commit bb091ab

Browse files
committed
feat: implement basic librarian configure command
1 parent fdea288 commit bb091ab

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

.generator/cli.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
BUILD_REQUEST_FILE = "build-request.json"
4747
GENERATE_REQUEST_FILE = "generate-request.json"
48+
CONFIGURE_REQUEST_FILE = "configure-response.json"
4849
RELEASE_INIT_REQUEST_FILE = "release-init-request.json"
4950
STATE_YAML_FILE = "state.yaml"
5051

@@ -144,7 +145,28 @@ def handle_configure(
144145
Raises:
145146
ValueError: If configuring a new library fails.
146147
"""
147-
# TODO(https://github.com/googleapis/librarian/issues/466): Implement configure command and update docstring.
148+
try:
149+
# configure-request.json contains the library definitions.
150+
request_data = _read_json_file(f"{librarian}/{CONFIGURE_REQUEST_FILE}")
151+
for library_config in request_data.get("libraries", []):
152+
is_new_library_or_api = False
153+
if "apis" in library_config:
154+
for api in library_config["apis"]:
155+
if api.get("status") == "new":
156+
is_new_library_or_api = True
157+
# Delete the status field since we don't need to include it in `configure-response.json`.
158+
del api["status"]
159+
160+
if is_new_library_or_api:
161+
library_id = _get_library_id(library_config)
162+
# TODO: Add missing information for the configured library.
163+
request_data[library_id] = library_config
164+
165+
# Write the new library configuration to configure-response.json.
166+
_write_json_file(f"{librarian}/configure-response.json", request_data[library_id])
167+
168+
except Exception as e:
169+
raise ValueError("Configuring a new library failed.") from e
148170
logger.info("'configure' command executed.")
149171

150172

0 commit comments

Comments
 (0)