diff --git a/README.md b/README.md index 8414c29..3510ec3 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,14 @@ From this point you are ready for the next change. When a pull requests exists a proposal is made to update the existing pull request. +### Overwrite target branch + +When you want to overwrite the target branch you need to supply the `--branch ` option: + +```bash +pull-request-codecommit --branch my-target-branch +``` + ## Testing locally ```bash diff --git a/pull_request_codecommit/__init__.py b/pull_request_codecommit/__init__.py index b8c0326..940ca96 100644 --- a/pull_request_codecommit/__init__.py +++ b/pull_request_codecommit/__init__.py @@ -8,12 +8,15 @@ @click.command() @click.option("-r", "--repository-path", default=None) +@click.option("-b", "--branch", default=None) @click.option("--auto-merge/--no-auto-merge", default=False) -def main(repository_path: Optional[str], auto_merge: bool) -> None: +def main( + repository_path: Optional[str], branch: Optional[str], auto_merge: bool +) -> None: """ pull-request-codecommit """ - repo = __load_repository(repository_path) + repo = __load_repository(repository_path=repository_path, target_branch=branch) __display_repository_information(repo) pr = __create_pull_request(repo) @@ -22,8 +25,10 @@ def main(repository_path: Optional[str], auto_merge: bool) -> None: click.echo(f"Auto merging resulted in: {status}") -def __load_repository(repository_path: Optional[str]) -> Repository: - repo = Repository(repository_path) +def __load_repository( + repository_path: Optional[str], target_branch: Optional[str] +) -> Repository: + repo = Repository(path=repository_path, target_branch=target_branch) if not repo.remote.supported: raise click.ClickException("The repository is not compatible with this tool!") diff --git a/pull_request_codecommit/aws/client.py b/pull_request_codecommit/aws/client.py index ad6a415..7f62a7d 100644 --- a/pull_request_codecommit/aws/client.py +++ b/pull_request_codecommit/aws/client.py @@ -19,7 +19,7 @@ def __init__(self, profile: Optional[str], region: Optional[str]) -> None: @property def base_command(self) -> List[str]: - base_command = ["aws"] + base_command = ["aws", "--output", "json"] if self.__profile: base_command.extend(["--profile", self.__profile]) diff --git a/pull_request_codecommit/repository.py b/pull_request_codecommit/repository.py index 8f310f6..02a8bd3 100644 --- a/pull_request_codecommit/repository.py +++ b/pull_request_codecommit/repository.py @@ -10,17 +10,22 @@ class Repository: Understands CodeCommit repositories """ - def __init__(self, path: Optional[str] = None) -> None: - self.__remote: Optional[Remote] = None - self.__branch: str = "" - + def __init__( + self, path: Optional[str] = None, target_branch: Optional[str] = None + ) -> None: if not path: path = os.getcwd() self.__git = GitClient(path) + self.__remote: Optional[Remote] = None + self.__branch: str = "" + self.__target_branch: str = ( + target_branch if target_branch else self.__config("destination_branch") + ) - def __config(self, method: str) -> Optional[str]: - return getattr(Config, method)(self.remote.profile) + def __config(self, method: str) -> str: + item = getattr(Config, method)(self.remote.profile) + return item if item else "" @property def remote(self) -> Remote: @@ -38,8 +43,7 @@ def branch(self) -> str: @property def destination(self) -> str: - destination = self.__config("destination_branch") - return destination if destination else "" + return self.__target_branch def commits(self) -> Commits: return self.__git.get_commit_messages(destination_branch=self.destination) diff --git a/tests/test_command.py b/tests/test_command.py index 18ee7b3..632f354 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -93,7 +93,14 @@ def generate_invoke_parameters( @pytest.mark.parametrize( "remote, region, profile, config, commits, parameters", - generate_invoke_parameters([[], ["--auto-merge"]]), + generate_invoke_parameters( + [ + [], + ["--auto-merge"], + ["-b", "my-target-branch"], + ["--branch", "my-target-branch"], + ] + ), ) @patch("pull_request_codecommit.aws.client.subprocess.run") @patch("pull_request_codecommit.repository.GitClient")