From 27b0ba10ba66605fc1a05384e1a9f4e1b4f01cf9 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Fri, 8 Sep 2023 10:59:30 +0200 Subject: [PATCH] Improve remote error msg --- oca_port/app.py | 2 +- oca_port/cli/main.py | 17 +++++++++-------- oca_port/exceptions.py | 4 +++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/oca_port/app.py b/oca_port/app.py index bb2445e..3a65b60 100644 --- a/oca_port/app.py +++ b/oca_port/app.py @@ -127,7 +127,7 @@ def _prepare_repos(self): if self.repo.is_dirty(untracked_files=True): raise ValueError("changes not committed detected in this repository.") if self.destination and self.destination.remote not in self.repo.remotes: - raise ForkValueError(self.repo_name, self.destination.remote) + raise ForkValueError(self.destination) # Transform branch strings to Branch objects try: self.from_branch = self._prepare_branch(self.source) diff --git a/oca_port/cli/main.py b/oca_port/cli/main.py index 54ad72d..887080e 100644 --- a/oca_port/cli/main.py +++ b/oca_port/cli/main.py @@ -162,14 +162,14 @@ def main( cli=True, ) except ForkValueError as exc: - error_msg = prepare_remote_error_msg(*exc.args) + error_msg = prepare_remote_error_msg(exc.entity) error_msg += ( "\n\nYou can change the GitHub organization with the " f"{bc.DIM}--user-org{bc.END} option." ) raise click.ClickException(error_msg) from exc except RemoteBranchValueError as exc: - error_msg = prepare_remote_error_msg(*exc.args) + error_msg = prepare_remote_error_msg(exc.entity) raise click.ClickException(error_msg) from exc except ValueError as exc: raise click.ClickException(exc) from exc @@ -180,17 +180,18 @@ def main( raise click.ClickException(exc) from exc -def prepare_remote_error_msg(repo_name, remote): +def prepare_remote_error_msg(entity): return ( - f"No remote {bc.FAIL}{remote}{bc.END} in the current repository.\n" + f"No remote for {bc.FAIL}{entity._kind} {entity._ref}{bc.END} " + "in the current repository.\n" "To add it:\n" "\t# This mode requires an SSH key in the GitHub account\n" - f"\t{bc.DIM}$ git remote add {remote} " - f"git@github.com:{remote}/{repo_name}.git{bc.END}\n" + f"\t{bc.DIM}$ git remote add {entity.org} " + f"git@github.com:{entity.org}/{entity.repo}.git{bc.END}\n" " Or:\n" "\t# This will require to enter user/password each time\n" - f"\t{bc.DIM}$ git remote add {remote} " - f"https://github.com/{remote}/{repo_name}.git{bc.END}" + f"\t{bc.DIM}$ git remote add {entity.org} " + f"https://github.com/{entity.org}/{entity.repo}.git{bc.END}" ) diff --git a/oca_port/exceptions.py b/oca_port/exceptions.py index f373094..ef689cc 100644 --- a/oca_port/exceptions.py +++ b/oca_port/exceptions.py @@ -3,7 +3,9 @@ class ForkValueError(ValueError): - pass + def __init__(self, entity): + super().__init__(entity._ref) + self.entity = entity class RemoteBranchValueError(ValueError):