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
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ disallow_untyped_decorators = False

[mypy-pytest]
ignore_missing_imports = True

[mypy-inquirer]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion src/git_portfolio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def delete_branches() -> None:
cli.add_command(delete)


def main() -> None:
def main(prog_name: str) -> None:
"""Git Portfolio."""
cli()

Expand Down
2 changes: 1 addition & 1 deletion src/git_portfolio/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def load_configs(self) -> Config:
return Config(**data)
return Config("", "", [])

def save_configs(self, configs: Config):
def save_configs(self, configs: Config) -> None:
"""Write config to YAML file."""
pathlib.Path(self.CONFIG_FOLDER).mkdir(parents=True, exist_ok=True)
configs_dict = vars(configs)
Expand Down
31 changes: 19 additions & 12 deletions src/git_portfolio/portfolio_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Command-line interface."""
import logging
import sys
from typing import Any
from typing import List
from typing import Optional
from typing import Set
from typing import Union

import github
Expand Down Expand Up @@ -30,7 +33,7 @@ def __init__(self) -> None:
self.config_ini()

def create_issues(
self, issue: Optional[prompt.Issue] = None, github_repo=""
self, issue: Optional[prompt.Issue] = None, github_repo: str = ""
) -> None:
"""Create issues."""
if not issue:
Expand All @@ -45,7 +48,9 @@ def create_issues(
for github_repo in self.configs.github_selected_repos:
self._create_issue_from_repo(github_repo, issue, labels)

def _create_issue_from_repo(self, github_repo, issue, labels):
def _create_issue_from_repo(
self, github_repo: str, issue: Any, labels: List[str]
) -> None:
"""Create issue from one repository."""
repo = self.github_connection.get_repo(github_repo)
try:
Expand All @@ -63,7 +68,7 @@ def _create_issue_from_repo(self, github_repo, issue, labels):
print(f"{github_repo}: {github_exception.data['message']}.")

def create_pull_requests(
self, pr: Optional[prompt.PullRequest] = None, github_repo=""
self, pr: Optional[prompt.PullRequest] = None, github_repo: str = ""
) -> None:
"""Create pull requests."""
if not pr:
Expand All @@ -75,7 +80,7 @@ def create_pull_requests(
for github_repo in self.configs.github_selected_repos:
self._create_pull_request_from_repo(github_repo, pr)

def _create_pull_request_from_repo(self, github_repo, pr):
def _create_pull_request_from_repo(self, github_repo: str, pr: Any) -> None:
"""Create pull request from one repository."""
repo = self.github_connection.get_repo(github_repo)
body = pr.body
Expand All @@ -96,12 +101,12 @@ def _create_pull_request_from_repo(self, github_repo, pr):
extra = ""
for error in github_exception.data["errors"]:
if "message" in error:
extra += f"{error['message']} "
extra += f"{error['message']} " # type: ignore
else:
extra += f"Invalid field {error['field']}. "
extra += f"Invalid field {error['field']}. " # type: ignore
print(f"{github_repo}: {github_exception.data['message']}. {extra}")

def _link_issues(self, body, labels, pr, repo):
def _link_issues(self, body: str, labels: Set[Any], pr: Any, repo: Any) -> Any:
"""Return body message linking issues."""
issues = repo.get_issues(state="open")
closes = ""
Expand All @@ -117,7 +122,7 @@ def _link_issues(self, body, labels, pr, repo):
return body

def merge_pull_requests(
self, pr_merge: Optional[prompt.PullRequestMerge] = None, github_repo=""
self, pr_merge: Optional[prompt.PullRequestMerge] = None, github_repo: str = ""
) -> None:
"""Merge pull requests."""
if not pr_merge:
Expand All @@ -136,7 +141,9 @@ def merge_pull_requests(
for github_repo in self.configs.github_selected_repos:
self._merge_pull_request_from_repo(github_repo, head, pr_merge, state)

def _merge_pull_request_from_repo(self, github_repo, head, pr_merge, state):
def _merge_pull_request_from_repo(
self, github_repo: str, head: str, pr_merge: Any, state: str
) -> None:
"""Merge pull request from one repository."""
repo = self.github_connection.get_repo(github_repo)
pulls = repo.get_pulls(state=state, base=pr_merge.base, head=head)
Expand Down Expand Up @@ -165,7 +172,7 @@ def _merge_pull_request_from_repo(self, github_repo, head, pr_merge, state):
)
)

def delete_branches(self, branch="", github_repo="") -> None:
def delete_branches(self, branch: str = "", github_repo: str = "") -> None:
"""Delete branches."""
if not branch:
branch = prompt.delete_branches(self.configs.github_selected_repos)
Expand All @@ -176,7 +183,7 @@ def delete_branches(self, branch="", github_repo="") -> None:
for github_repo in self.configs.github_selected_repos:
self._delete_branch_from_repo(github_repo, branch)

def _delete_branch_from_repo(self, github_repo, branch):
def _delete_branch_from_repo(self, github_repo: str, branch: str) -> None:
"""Delete a branch from one repository."""
repo = self.github_connection.get_repo(github_repo)
try:
Expand Down Expand Up @@ -216,7 +223,7 @@ def get_github_repos(
user: Union[
github.AuthenticatedUser.AuthenticatedUser, github.NamedUser.NamedUser
],
) -> github.PaginatedList.PaginatedList:
) -> github.PaginatedList.PaginatedList[Any]:
"""Get Github repos from user."""
return user.get_repos()

Expand Down
14 changes: 8 additions & 6 deletions src/git_portfolio/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _not_empty_validation(answers: Dict[str, Any], current: str) -> bool:
Issue = collections.namedtuple("Issue", ["title", "body", "labels"])


def create_issues(github_selected_repos):
def create_issues(github_selected_repos: List[str]) -> Issue:
"""Prompt questions to create issues."""
questions = [
inquirer.Text(
Expand All @@ -55,7 +55,7 @@ def create_issues(github_selected_repos):
return Issue(answers["title"], answers["body"], answers["labels"])


def delete_branches(github_selected_repos) -> str:
def delete_branches(github_selected_repos: List[str]) -> Any:
"""Prompt questions to delete branches."""
questions = [
inquirer.Text(
Expand Down Expand Up @@ -93,7 +93,7 @@ def delete_branches(github_selected_repos) -> str:
)


def create_pull_requests(github_selected_repos) -> PullRequest:
def create_pull_requests(github_selected_repos: List[str]) -> PullRequest:
"""Prompt questions to create pull requests."""
questions = [
inquirer.Text(
Expand Down Expand Up @@ -165,7 +165,9 @@ def create_pull_requests(github_selected_repos) -> PullRequest:
)


def merge_pull_requests(github_username, github_selected_repos):
def merge_pull_requests(
github_username: str, github_selected_repos: List[str]
) -> PullRequestMerge:
"""Prompt questions to merge pull requests."""
questions = [
inquirer.Text(
Expand Down Expand Up @@ -231,15 +233,15 @@ def connect_github(github_access_token: str) -> ConnectGithub:
return ConnectGithub(answers["github_access_token"], answers["github_hostname"])


def new_repos() -> bool:
def new_repos() -> Any:
"""Prompt question to know if you want to select new repositories."""
answer = inquirer.prompt(
[inquirer.Confirm("", message="Do you want to select new repositories?")]
)[""]
return answer


def select_repos(repo_names) -> List[str]:
def select_repos(repo_names: List[str]) -> Any:
"""Prompt questions to select new repositories."""
while True:
selected = inquirer.prompt(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def runner() -> CliRunner:

def test_main_without_argument(runner: CliRunner) -> None:
"""It exits with a status code of one."""
result = runner.invoke(__main__.main, prog_name="gitp")
result = runner.invoke(__main__.main, prog_name="gitp") # type: ignore
assert result.exit_code == 1