Skip to content

Commit

Permalink
chore: remove argparse usage from stack module
Browse files Browse the repository at this point in the history
Change-Id: Ic4dee15f244a08330482808942e0e0d9a9901dc6
  • Loading branch information
sileht committed Nov 5, 2024
1 parent 2fb864c commit ec29a85
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
15 changes: 11 additions & 4 deletions mergify_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async def get_default_token() -> str:
async def _stack_push(args: argparse.Namespace) -> None:
if args.setup:
# backward compat
await setup.stack_setup(args)
await setup.stack_setup()
return

await push.stack_push(
Expand Down Expand Up @@ -135,7 +135,7 @@ def register_stack_setup_parser(
description="Configure the git hooks",
help="Initial installation of the required git commit-msg hook",
)
parser.set_defaults(func=setup.stack_setup)
parser.set_defaults(func=lambda _: setup.stack_setup)


def register_stack_edit_parser(
Expand All @@ -146,7 +146,14 @@ def register_stack_edit_parser(
description="Edit the stack history",
help="Edit the stack history",
)
parser.set_defaults(func=edit.stack_edit)
parser.set_defaults(func=lambda _: edit.stack_edit)


async def _stack_github_action_auto_rebase(args: argparse.Namespace) -> None:
await github_action_auto_rebase.stack_github_action_auto_rebase(
args.github_server,
args.token,
)


def register_stack_github_action_autorebase(
Expand All @@ -157,7 +164,7 @@ def register_stack_github_action_autorebase(
description="Autorebase a pull requests stack",
help="Checkout a pull requests stack",
)
parser.set_defaults(func=github_action_auto_rebase.stack_github_action_auto_rebase)
parser.set_defaults(func=_stack_github_action_auto_rebase)


async def register_stack_checkout_parser(
Expand Down
3 changes: 1 addition & 2 deletions mergify_cli/stack/edit.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import argparse
import os

from mergify_cli import utils


async def stack_edit(_: argparse.Namespace) -> None:
async def stack_edit() -> None:
os.chdir(await utils.git("rev-parse", "--show-toplevel"))
trunk = await utils.get_trunk()
base = await utils.git("merge-base", trunk, "HEAD")
Expand Down
19 changes: 7 additions & 12 deletions mergify_cli/stack/github_action_auto_rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import os
import sys
import typing

import aiofiles

Expand All @@ -13,11 +12,7 @@
from mergify_cli.stack import push


if typing.TYPE_CHECKING:
import argparse


async def stack_github_action_auto_rebase(args: argparse.Namespace) -> None:
async def stack_github_action_auto_rebase(github_server: str, token: str) -> None:
for env in ("GITHUB_EVENT_NAME", "GITHUB_EVENT_PATH", "GITHUB_REPOSITORY"):
if env not in os.environ:
console.log("This action only works in a GitHub Action", style="red")
Expand All @@ -37,7 +32,7 @@ async def stack_github_action_auto_rebase(args: argparse.Namespace) -> None:
)
sys.exit(1)

async with utils.get_github_http_client(args.github_server, args.token) as client:
async with utils.get_github_http_client(github_server, token) as client:
await client.post(
f"/repos/{user}/{repo}/issues/comments/{event['comment']['id']}/reactions",
json={"content": "+1"},
Expand Down Expand Up @@ -71,8 +66,8 @@ async def stack_github_action_auto_rebase(args: argparse.Namespace) -> None:
await utils.git("branch", "--set-upstream-to", f"origin/{base}")

await checkout.stack_checkout(
args.github_server,
args.token,
github_server,
token,
user=user,
repo=repo,
branch_prefix="",
Expand All @@ -82,8 +77,8 @@ async def stack_github_action_auto_rebase(args: argparse.Namespace) -> None:
dry_run=False,
)
await push.stack_push(
args.github_server,
args.token,
github_server,
token,
skip_rebase=False,
next_only=False,
branch_prefix="",
Expand All @@ -95,7 +90,7 @@ async def stack_github_action_auto_rebase(args: argparse.Namespace) -> None:
author=author,
)

async with utils.get_github_http_client(args.github_server, args.token) as client:
async with utils.get_github_http_client(github_server, token) as client:
body_quote = "> " + "\n> ".join(event["comment"]["body"].split("\n"))
await client.post(
f"/repos/{user}/{repo}/issues/{pull['number']}/comments",
Expand Down
7 changes: 1 addition & 6 deletions mergify_cli/stack/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
import pathlib
import shutil
import sys
import typing

import aiofiles

from mergify_cli import console
from mergify_cli import utils


if typing.TYPE_CHECKING:
import argparse


async def stack_setup(_: argparse.Namespace) -> None:
async def stack_setup() -> None:
hooks_dir = pathlib.Path(await utils.git("rev-parse", "--git-path", "hooks"))
installed_hook_file = hooks_dir / "commit-msg"

Expand Down

0 comments on commit ec29a85

Please sign in to comment.