Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/git_portfolio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ def config_init() -> None:
@configure.command("repos")
def config_repos() -> None:
"""Config repos command."""
config = ghm.GithubManager(CONFIG_MANAGER.config).config_repos()
if config:
_save_config(config)
else:
if CONFIG_MANAGER.config_is_empty():
click.secho("Error: no config found, please run `gitp config init`.", fg="red")
else:
config = ghm.GithubManager(CONFIG_MANAGER.config).config_repos()
if config:
_save_config(config)


@create.command("issues")
Expand Down
5 changes: 3 additions & 2 deletions src/git_portfolio/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ def __init__(self, config_filename: str = "config.yaml") -> None:
config_file.truncate(0)
self.config = Config("", "", [])

def _config_is_empty(self) -> bool:
def config_is_empty(self) -> bool:
"""Check if config is empty."""
if self.config.github_selected_repos and self.config.github_access_token:
return False
return True

def save_config(self) -> None:
"""Write config to YAML file."""
if not self._config_is_empty():
if not self.config_is_empty():
pathlib.Path(self.config_folder).mkdir(parents=True, exist_ok=True)
config_dict = vars(self.config)
with open(self.config_path, "w") as config_file:
Expand Down
23 changes: 19 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def test_config_init(
mock_github_manager.assert_called_once()


@patch("git_portfolio.__main__.CONFIG_MANAGER")
@patch("git_portfolio.__main__.CONFIG_MANAGER", autospec=True)
@patch("git_portfolio.github_manager.GithubManager", autospec=True)
def test_config_repos(
def test_config_repos_success(
mock_github_manager: Mock, mock_configmanager: Mock, runner: CliRunner
) -> None:
"""It call config_repos from pm.GithubManager."""
mock_configmanager.config_is_empty.return_value = False
result = runner.invoke(
git_portfolio.__main__.configure, ["repos"], prog_name="gitp"
)
Expand All @@ -74,6 +75,22 @@ def test_config_repos(
assert result.output == "gitp successfully configured.\n"


@patch("git_portfolio.__main__.CONFIG_MANAGER", autospec=True)
@patch("git_portfolio.github_manager.GithubManager", autospec=True)
def test_config_repos_do_not_change(
mock_github_manager: Mock, mock_configmanager: Mock, runner: CliRunner
) -> None:
"""It does not change config file."""
mock_configmanager.config_is_empty.return_value = False
mock_github_manager.return_value.config_repos.return_value = None
result = runner.invoke(
git_portfolio.__main__.configure, ["repos"], prog_name="gitp"
)
mock_github_manager.assert_called_once()
mock_github_manager.return_value.config_repos.assert_called_once()
assert "gitp successfully configured.\n" not in result.output


@patch("git_portfolio.__main__.CONFIG_MANAGER")
@patch("git_portfolio.github_manager.GithubManager", autospec=True)
def test_config_repos_no_config(
Expand All @@ -84,8 +101,6 @@ def test_config_repos_no_config(
result = runner.invoke(
git_portfolio.__main__.configure, ["repos"], prog_name="gitp"
)
mock_github_manager.assert_called_once()
mock_github_manager.return_value.config_repos.assert_called_once()
assert "Error" in result.output


Expand Down