Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 59d0a85

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #80 from staticdev/config-repos-bug
Bug config repos
2 parents ea69b26 + 9167333 commit 59d0a85

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/git_portfolio/__main__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ def config_init() -> None:
9090
@configure.command("repos")
9191
def config_repos() -> None:
9292
"""Config repos command."""
93-
config = ghm.GithubManager(CONFIG_MANAGER.config).config_repos()
94-
if config:
95-
_save_config(config)
96-
else:
93+
if CONFIG_MANAGER.config_is_empty():
9794
click.secho("Error: no config found, please run `gitp config init`.", fg="red")
95+
else:
96+
config = ghm.GithubManager(CONFIG_MANAGER.config).config_repos()
97+
if config:
98+
_save_config(config)
9899

99100

100101
@create.command("issues")

src/git_portfolio/config_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ def __init__(self, config_filename: str = "config.yaml") -> None:
4444
config_file.truncate(0)
4545
self.config = Config("", "", [])
4646

47-
def _config_is_empty(self) -> bool:
47+
def config_is_empty(self) -> bool:
48+
"""Check if config is empty."""
4849
if self.config.github_selected_repos and self.config.github_access_token:
4950
return False
5051
return True
5152

5253
def save_config(self) -> None:
5354
"""Write config to YAML file."""
54-
if not self._config_is_empty():
55+
if not self.config_is_empty():
5556
pathlib.Path(self.config_folder).mkdir(parents=True, exist_ok=True)
5657
config_dict = vars(self.config)
5758
with open(self.config_path, "w") as config_file:

tests/test_main.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ def test_config_init(
6060
mock_github_manager.assert_called_once()
6161

6262

63-
@patch("git_portfolio.__main__.CONFIG_MANAGER")
63+
@patch("git_portfolio.__main__.CONFIG_MANAGER", autospec=True)
6464
@patch("git_portfolio.github_manager.GithubManager", autospec=True)
65-
def test_config_repos(
65+
def test_config_repos_success(
6666
mock_github_manager: Mock, mock_configmanager: Mock, runner: CliRunner
6767
) -> None:
6868
"""It call config_repos from pm.GithubManager."""
69+
mock_configmanager.config_is_empty.return_value = False
6970
result = runner.invoke(
7071
git_portfolio.__main__.configure, ["repos"], prog_name="gitp"
7172
)
@@ -74,6 +75,22 @@ def test_config_repos(
7475
assert result.output == "gitp successfully configured.\n"
7576

7677

78+
@patch("git_portfolio.__main__.CONFIG_MANAGER", autospec=True)
79+
@patch("git_portfolio.github_manager.GithubManager", autospec=True)
80+
def test_config_repos_do_not_change(
81+
mock_github_manager: Mock, mock_configmanager: Mock, runner: CliRunner
82+
) -> None:
83+
"""It does not change config file."""
84+
mock_configmanager.config_is_empty.return_value = False
85+
mock_github_manager.return_value.config_repos.return_value = None
86+
result = runner.invoke(
87+
git_portfolio.__main__.configure, ["repos"], prog_name="gitp"
88+
)
89+
mock_github_manager.assert_called_once()
90+
mock_github_manager.return_value.config_repos.assert_called_once()
91+
assert "gitp successfully configured.\n" not in result.output
92+
93+
7794
@patch("git_portfolio.__main__.CONFIG_MANAGER")
7895
@patch("git_portfolio.github_manager.GithubManager", autospec=True)
7996
def test_config_repos_no_config(
@@ -84,8 +101,6 @@ def test_config_repos_no_config(
84101
result = runner.invoke(
85102
git_portfolio.__main__.configure, ["repos"], prog_name="gitp"
86103
)
87-
mock_github_manager.assert_called_once()
88-
mock_github_manager.return_value.config_repos.assert_called_once()
89104
assert "Error" in result.output
90105

91106

0 commit comments

Comments
 (0)