mirror of
https://github.com/ansible/ansible-documentation.git
synced 2026-03-27 13:28:51 +07:00
pr_labeler: allow setting custom repo via CLI (#354)
This makes testing on a different repo easier.
This commit is contained in:
@@ -46,12 +46,14 @@ def log(ctx: IssueOrPrCtx, *args: object) -> None:
|
|||||||
print(f"{ctx.member.number}:", *args)
|
print(f"{ctx.member.number}:", *args)
|
||||||
|
|
||||||
|
|
||||||
def get_repo(authed: bool = True) -> tuple[github.Github, github.Repository.Repository]:
|
def get_repo(
|
||||||
|
*, authed: bool = True, owner: str, repo: str
|
||||||
|
) -> tuple[github.Github, github.Repository.Repository]:
|
||||||
gclient = github.Github(
|
gclient = github.Github(
|
||||||
auth=github.Auth.Token(os.environ["GITHUB_TOKEN"]) if authed else None,
|
auth=github.Auth.Token(os.environ["GITHUB_TOKEN"]) if authed else None,
|
||||||
)
|
)
|
||||||
repo = gclient.get_repo(f"{OWNER}/{REPO}")
|
repo_obj = gclient.get_repo(f"{owner}/{repo}")
|
||||||
return gclient, repo
|
return gclient, repo_obj
|
||||||
|
|
||||||
|
|
||||||
def get_event_info() -> dict[str, Any]:
|
def get_event_info() -> dict[str, Any]:
|
||||||
@@ -63,6 +65,12 @@ def get_event_info() -> dict[str, Any]:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclasses.dataclass()
|
||||||
|
class GlobalArgs:
|
||||||
|
owner: str
|
||||||
|
repo: str
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass()
|
@dataclasses.dataclass()
|
||||||
class LabelerCtx:
|
class LabelerCtx:
|
||||||
client: github.Github
|
client: github.Github
|
||||||
@@ -221,21 +229,31 @@ APP = typer.Typer()
|
|||||||
|
|
||||||
|
|
||||||
@APP.callback()
|
@APP.callback()
|
||||||
def cb():
|
def cb(*, click_ctx: typer.Context, owner: str = OWNER, repo: str = REPO):
|
||||||
"""
|
"""
|
||||||
Basic triager for ansible/ansible-documentation
|
Basic triager for ansible/ansible-documentation
|
||||||
"""
|
"""
|
||||||
|
click_ctx.obj = GlobalArgs(owner, repo)
|
||||||
|
|
||||||
|
|
||||||
@APP.command(name="pr")
|
@APP.command(name="pr")
|
||||||
def process_pr(
|
def process_pr(
|
||||||
pr_number: int, dry_run: bool = False, authed_dry_run: bool = False
|
*,
|
||||||
|
click_ctx: typer.Context,
|
||||||
|
pr_number: int,
|
||||||
|
dry_run: bool = False,
|
||||||
|
authed_dry_run: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
global_args = click_ctx.ensure_object(GlobalArgs)
|
||||||
|
|
||||||
authed = not dry_run
|
authed = not dry_run
|
||||||
if authed_dry_run:
|
if authed_dry_run:
|
||||||
dry_run = True
|
dry_run = True
|
||||||
authed = True
|
authed = True
|
||||||
gclient, repo = get_repo(authed=authed)
|
|
||||||
|
gclient, repo = get_repo(
|
||||||
|
authed=authed, owner=global_args.owner, repo=global_args.repo
|
||||||
|
)
|
||||||
pr = repo.get_pull(pr_number)
|
pr = repo.get_pull(pr_number)
|
||||||
ctx = PRLabelerCtx(
|
ctx = PRLabelerCtx(
|
||||||
client=gclient,
|
client=gclient,
|
||||||
@@ -257,13 +275,21 @@ def process_pr(
|
|||||||
|
|
||||||
@APP.command(name="issue")
|
@APP.command(name="issue")
|
||||||
def process_issue(
|
def process_issue(
|
||||||
issue_number: int, dry_run: bool = False, authed_dry_run: bool = False
|
*,
|
||||||
|
click_ctx: typer.Context,
|
||||||
|
issue_number: int,
|
||||||
|
dry_run: bool = False,
|
||||||
|
authed_dry_run: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
global_args = click_ctx.ensure_object(GlobalArgs)
|
||||||
|
|
||||||
authed = not dry_run
|
authed = not dry_run
|
||||||
if authed_dry_run:
|
if authed_dry_run:
|
||||||
dry_run = True
|
dry_run = True
|
||||||
authed = True
|
authed = True
|
||||||
gclient, repo = get_repo(authed=authed)
|
gclient, repo = get_repo(
|
||||||
|
authed=authed, owner=global_args.owner, repo=global_args.repo
|
||||||
|
)
|
||||||
issue = repo.get_issue(issue_number)
|
issue = repo.get_issue(issue_number)
|
||||||
ctx = IssueLabelerCtx(
|
ctx = IssueLabelerCtx(
|
||||||
client=gclient,
|
client=gclient,
|
||||||
|
|||||||
Reference in New Issue
Block a user