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

Add reopen PRS #555

Merged
merged 2 commits into from
Dec 11, 2021
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Features

* Configure multiple working repositories.
* Batch git_ commands with subcommands: ``add``, ``branch``, ``checkout``, ``commit``, ``diff``, ``fetch``, ``init``, ``merge``, ``mv``, ``pull``, ``push``, ``rebase``, ``reset``, ``rm``, ``show``, ``switch``, ``status`` and ``tag``.
* Batch API calls on GitHub_: create/close/reopen ``issues``, create/merge ``pull requests`` and delete ``branches`` by name.
* Batch API calls on GitHub_: create/close/reopen ``issues``, create/close/reopen/merge ``pull requests`` and delete ``branches`` by name.
* Batch Poetry_ commands such as: ``add``, ``version patch``, ``install`` or ``update``.


Expand Down
50 changes: 38 additions & 12 deletions src/git_portfolio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _echo_outputs(responses: list[res.Response]) -> None:
click.secho(f"{failure.value['message']}", fg="red")


def gitp_config_check(func: F) -> F:
def command_config_check(func: F) -> F:
"""Validate if there are selected repos and outputs success."""

@functools.wraps(func)
Expand Down Expand Up @@ -77,7 +77,7 @@ def _get_connection_settings(config: c.Config) -> cs.GhConnectionSettings:
return cs.GhConnectionSettings(config.github_access_token, config.github_hostname)


@gitp_config_check
@command_config_check
def _call_git_use_case(command: str, args: tuple[str]) -> list[res.Response]:
return git.GitUseCase().execute(
CONFIG_MANAGER.config.github_selected_repos, command, args
Expand Down Expand Up @@ -106,7 +106,7 @@ def checkout(args: tuple[str]) -> list[res.Response]:


@main.command()
@gitp_config_check
@command_config_check
def clone() -> list[res.Response]:
"""Batch `git clone` command on current folder. Does not accept aditional args."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand Down Expand Up @@ -269,7 +269,7 @@ def config_init() -> None:


@group_config.command("repos")
@gitp_config_check
@command_config_check
def config_repos() -> list[res.Response]:
"""Configure current working `gitp` repositories."""
new_repos = p.InquirerPrompter.new_repos(
Expand All @@ -293,7 +293,7 @@ def config_repos() -> list[res.Response]:


@group_issues.command("create")
@gitp_config_check
@command_config_check
def create_issues() -> list[res.Response]:
"""Batch creation of issues on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand All @@ -309,7 +309,7 @@ def create_issues() -> list[res.Response]:


@group_issues.command("close")
@gitp_config_check
@command_config_check
def close_issues() -> list[res.Response]:
"""Batch close issues on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand All @@ -335,7 +335,7 @@ def close_issues() -> list[res.Response]:


@group_issues.command("reopen")
@gitp_config_check
@command_config_check
def reopen_issues() -> list[res.Response]:
"""Batch reopen issues on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand All @@ -362,7 +362,7 @@ def reopen_issues() -> list[res.Response]:

@main.command("poetry", context_settings={"ignore_unknown_options": True})
@click.argument("args", nargs=-1)
@gitp_config_check
@command_config_check
def poetry_cmd(args: tuple[str]) -> list[res.Response]:
"""Batch `poetry` command."""
return poetry.PoetryUseCase().execute(
Expand All @@ -371,7 +371,7 @@ def poetry_cmd(args: tuple[str]) -> list[res.Response]:


@group_prs.command("create")
@gitp_config_check
@command_config_check
def create_prs() -> list[res.Response]:
"""Batch creation of pull requests on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand All @@ -397,7 +397,7 @@ def create_prs() -> list[res.Response]:


@group_prs.command("close")
@gitp_config_check
@command_config_check
def close_prs() -> list[res.Response]:
"""Batch close pull requests on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand All @@ -422,8 +422,34 @@ def close_prs() -> list[res.Response]:
)


@group_prs.command("reopen")
@command_config_check
def reopen_prs() -> list[res.Response]:
"""Batch reopen pull requests on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
try:
github_service = ghs.GithubService(settings)
except ghs.GithubServiceError as gse:
return [res.ResponseFailure(res.ResponseTypes.RESOURCE_ERROR, gse)]

list_object = "pull request"
title_query = p.InquirerPrompter.query_by_title(
CONFIG_MANAGER.config.github_selected_repos, list_object
)
list_request = il.build_list_request(
filters={
"obj__eq": list_object,
"state__eq": "closed",
"title__contains": title_query,
}
)
return ghri.GhReopenIssueUseCase(CONFIG_MANAGER, github_service).execute(
list_request
)


@group_prs.command("merge")
@gitp_config_check
@command_config_check
def merge_prs() -> list[res.Response]:
"""Batch merge of pull requests on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand All @@ -440,7 +466,7 @@ def merge_prs() -> list[res.Response]:


@group_branches.command("delete")
@gitp_config_check
@command_config_check
def delete_branches() -> list[res.Response]:
"""Batch deletion of branches on GitHub."""
settings = _get_connection_settings(CONFIG_MANAGER.config)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def pytest_configure(config: _pytest.config.Config) -> None:
config.addinivalue_line("markers", "integration: mark as integration test.")


CLI_COMMAND = "gitp"
REPO_NAME = "repo-name"
REPO = f"org/{REPO_NAME}"
REPO2 = f"org/{REPO_NAME}2"
Expand Down
Loading