Пример #1
0
 def execute(
     self, pr_merge: prm.PullRequestMerge, github_repo: str = ""
 ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
     """Merge pull requests."""
     if github_repo:
         output = self.github_service.merge_pull_request_from_repo(
             github_repo, pr_merge
         )
         if pr_merge.delete_branch:
             delete_branch_use_case = dbr.GhDeleteBranchUseCase(
                 self.config_manager, self.github_service
             )
             delete_branch_use_case.execute(pr_merge.head, github_repo)
     else:
         output = ""
         if pr_merge.delete_branch:
             for github_repo in self.config_manager.config.github_selected_repos:
                 output += self.github_service.merge_pull_request_from_repo(
                     github_repo, pr_merge
                 )
                 delete_branch_use_case = dbr.GhDeleteBranchUseCase(
                     self.config_manager, self.github_service
                 )
                 delete_branch_use_case.execute(pr_merge.head, github_repo)
         else:
             for github_repo in self.config_manager.config.github_selected_repos:
                 output += self.github_service.merge_pull_request_from_repo(
                     github_repo, pr_merge
                 )
     return res.ResponseSuccess(output)
Пример #2
0
 def execute(
     self, selected_repos: List[str]
 ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
     """Configuration of git repositories."""
     self.config_manager.config.github_selected_repos = selected_repos
     self.config_manager.save_config()
     return res.ResponseSuccess("gitp repositories successfully configured.")
Пример #3
0
def test_response_success_has_type_and_value(
        response_value: Dict[str, List[str]]) -> None:
    """It has success type and value."""
    response = res.ResponseSuccess(response_value)

    assert response.type == res.ResponseSuccess.SUCCESS
    assert response.value == response_value
Пример #4
0
def config_repos() -> Union[res.ResponseFailure, res.ResponseSuccess]:
    """Configure current working `gitp` repositories."""
    new_repos = p.InquirerPrompter.new_repos(
        CONFIG_MANAGER.config.github_selected_repos)
    if not new_repos:
        return res.ResponseSuccess()
    github_service = _get_github_service(CONFIG_MANAGER.config)
    repo_names = github_service.get_repo_names()
    selected_repos = p.InquirerPrompter.select_repos(repo_names)
    return cr.ConfigReposUseCase(CONFIG_MANAGER).execute(selected_repos)
 def execute(
     self, branch: str, github_repo: str = ""
 ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
     """Delete branches."""
     if github_repo:
         output = self.github_service.delete_branch_from_repo(github_repo, branch)
     else:
         output = ""
         for github_repo in self.config_manager.config.github_selected_repos:
             output += self.github_service.delete_branch_from_repo(
                 github_repo, branch
             )
     return res.ResponseSuccess(output)
Пример #6
0
 def execute(
     self, request: gcs.GhConnectionSettings
 ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
     """Initialize app configuration."""
     try:
         new_github_service = ghs.GithubService(request)
     except AttributeError:
         return res.ResponseFailure.build_parameters_error()
     except ConnectionError:
         return res.ResponseFailure.build_system_error()
     repo_names = new_github_service.get_repo_names()
     selected_repos = p.InquirerPrompter.select_repos(repo_names)
     cr.ConfigReposUseCase(self.config_manager).execute(selected_repos)
     return res.ResponseSuccess("gitp successfully configured.")
Пример #7
0
 def execute(
     self,
     issue: i.Issue,
     github_repo: str = ""
 ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
     """Create issues."""
     if github_repo:
         output = self.github_service.create_issue_from_repo(
             github_repo, issue)
     else:
         output = ""
         for github_repo in self.config_manager.config.github_selected_repos:
             output += self.github_service.create_issue_from_repo(
                 github_repo, issue)
     return res.ResponseSuccess(output)
Пример #8
0
def test_config_init_success(
    mock_prompt_inquirer_prompter: MockerFixture,
    mock_config_manager: MockerFixture,
    mock_config_init_use_case: MockerFixture,
    runner: CliRunner,
) -> None:
    """It executes config init use case."""
    config_manager = mock_config_manager.return_value
    mock_config_init_use_case(
        config_manager).execute.return_value = res.ResponseSuccess(
            "success message")
    result = runner.invoke(git_portfolio.__main__.configure, ["init"],
                           prog_name="gitp")

    mock_config_init_use_case(config_manager).execute.assert_called_once()
    assert result.output == "success message\n"
Пример #9
0
def test_config_init_connection_error(
    mock_prompt_inquirer_prompter: MockerFixture,
    mock_config_manager: MockerFixture,
    mock_config_init_use_case: MockerFixture,
    runner: CliRunner,
) -> None:
    """It executes with connection error first then succeeds."""
    config_manager = mock_config_manager.return_value
    mock_config_init_use_case(config_manager).execute.side_effect = [
        res.ResponseFailure.build_system_error("message"),
        res.ResponseSuccess("success message"),
    ]
    result = runner.invoke(git_portfolio.__main__.configure, ["init"],
                           prog_name="gitp")

    assert mock_config_init_use_case(config_manager).execute.call_count == 2
    assert result.output == "Error: message\nsuccess message\n"
Пример #10
0
    def execute(
            self, git_selected_repos: List[str], command: str, args: Tuple[str]
    ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
        """Batch `git` command.

        Args:
            git_selected_repos: list of configured repo names.
            command: supported: checkout.
            args (Tuple[str]): command arguments.

        Returns:
            str: output.
            str: error output.
        """
        if self.err_output:
            return res.ResponseFailure.build_system_error(self.err_output)
        output = ""
        cwd = pathlib.Path().absolute()
        for repo_name in git_selected_repos:
            folder_name = repo_name.split("/")[1]
            output += f"{folder_name}: "
            try:
                popen = subprocess.Popen(  # noqa: S603, S607
                    ["git", command, *args],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    cwd=os.path.join(cwd, folder_name),
                )
                stdout, error = popen.communicate()
                # case of commands that outputs nothing on success such as `git add .`
                if not stdout and not error:
                    output += "success.\n"
                else:
                    if stdout:
                        stdout_str = stdout.decode("utf-8")
                        output += f"{stdout_str}"
                    if error:
                        error_str = error.decode("utf-8")
                        output += f"{error_str}"
            except FileNotFoundError as fnf_error:
                output += f"{fnf_error}\n"
        return res.ResponseSuccess(output)
Пример #11
0
 def execute(
     self,
     pr: pr.PullRequest,
     github_repo: str = ""
 ) -> Union[res.ResponseFailure, res.ResponseSuccess]:
     """Create pull requests."""
     if github_repo:
         if pr.link_issues:
             self.github_service.link_issues(github_repo, pr)
         output = self.github_service.create_pull_request_from_repo(
             github_repo, pr)
     else:
         output = ""
         if pr.link_issues:
             for github_repo in self.config_manager.config.github_selected_repos:
                 self.github_service.link_issues(github_repo, pr)
                 output += self.github_service.create_pull_request_from_repo(
                     github_repo, pr)
         else:
             for github_repo in self.config_manager.config.github_selected_repos:
                 output += self.github_service.create_pull_request_from_repo(
                     github_repo, pr)
     return res.ResponseSuccess(output)
Пример #12
0
 def _() -> res.ResponseSuccess:
     return res.ResponseSuccess("success message")
Пример #13
0
def test_response_success_is_true(
        response_value: Dict[str, List[str]]) -> None:
    """It has bool value of True."""
    assert bool(res.ResponseSuccess(response_value)) is True