From c0194d412ed2256f5036af4e7b652bbe774bf3b5 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Thu, 11 Jan 2024 14:31:40 +0000 Subject: [PATCH] Raise IssueParsingError if ref already exists in charms.json --- cli/cli/add_charm_branch.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/cli/add_charm_branch.py b/cli/cli/add_charm_branch.py index 1f5a5b5..abad97b 100644 --- a/cli/cli/add_charm_branch.py +++ b/cli/cli/add_charm_branch.py @@ -83,14 +83,19 @@ def main(): path = pathlib.Path(charm_branch.relative_path_to_charmcraft_yaml) if not path.resolve().is_relative_to(pathlib.Path(".").resolve()): raise IssueParsingError("Invalid path. @carlcsaposs-canonical") + with open("charms.json", "r") as file: + charms = json.load(file) + charm_ = dataclasses.asdict(charm_branch) + if charm_ in charms: + raise IssueParsingError( + "Git ref already exists in charms.json. @carlcsaposs-canonical" + ) except IssueParsingError as exception: output = f"success={json.dumps(False)}\nerror={exception.message}" else: - with open("charms.json", "r") as file: - data = json.load(file) - data.append(dataclasses.asdict(charm_branch)) + charms.append(charm_) with open("charms.json", "w") as file: - json.dump(data, file, indent=2) + json.dump(charms, file, indent=2) output = f"success={json.dumps(True)}\ntitle=Add {charm_branch.github_repository}@{charm_branch.ref} at path {charm_branch.relative_path_to_charmcraft_yaml}" print(output) with open(os.environ["GITHUB_OUTPUT"], "a") as file: