File size: 1,097 Bytes
fbf3c28 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """
id: gh_tools
title: GitHub CLI Wrapper
author: admin
description: Create PRs and comments using gh CLI in a repo.
version: 0.1.0
license: Proprietary
"""
import subprocess
class Tools:
def pr_create(
self, repo: str, title: str, body: str = "", base: str = "main", head: str = ""
) -> dict:
cmd = (
f"gh pr create --repo {repo} --title {title!r} --body {body!r} --base {base} "
+ (f"--head {head} " if head else "")
)
p = subprocess.run(["bash", "-lc", cmd], capture_output=True, text=True)
return {
"stdout": p.stdout,
"stderr": p.stderr,
"exit_code": p.returncode,
"cmd": cmd,
}
def pr_comment(self, repo: str, pr_number: int, body: str) -> dict:
cmd = f"gh pr comment {pr_number} --repo {repo} --body {body!r}"
p = subprocess.run(["bash", "-lc", cmd], capture_output=True, text=True)
return {
"stdout": p.stdout,
"stderr": p.stderr,
"exit_code": p.returncode,
"cmd": cmd,
}
|