Initial commit
This commit is contained in:
54
skills/pr-creator/scripts/detect_pr_template.py
Normal file
54
skills/pr-creator/scripts/detect_pr_template.py
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Detect PR template in git repository with worktree support."""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
async def run_git_command(command: str) -> tuple[str, int]:
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout, _ = await process.communicate()
|
||||
return stdout.decode("utf-8").strip(), process.returncode or 0
|
||||
|
||||
|
||||
async def find_pr_template() -> dict[str, str | bool | None]:
|
||||
git_root_output, returncode = await run_git_command("git rev-parse --show-toplevel")
|
||||
|
||||
if returncode != 0:
|
||||
return {"error": "Not a git repository", "found": False}
|
||||
|
||||
git_root = Path(git_root_output)
|
||||
|
||||
template_locations = [
|
||||
git_root / ".github" / "PULL_REQUEST_TEMPLATE.md",
|
||||
git_root / ".github" / "pull_request_template.md",
|
||||
git_root / "docs" / "PULL_REQUEST_TEMPLATE.md",
|
||||
git_root / "PULL_REQUEST_TEMPLATE.md",
|
||||
]
|
||||
|
||||
for template_path in template_locations:
|
||||
if template_path.exists() and template_path.is_file():
|
||||
content = template_path.read_text(encoding="utf-8")
|
||||
return {"found": True, "path": str(template_path), "content": content}
|
||||
|
||||
return {"found": False}
|
||||
|
||||
|
||||
async def main() -> int:
|
||||
try:
|
||||
result = await find_pr_template()
|
||||
print(json.dumps(result, indent=2, ensure_ascii=False))
|
||||
return 0
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e), "type": type(e).__name__, "found": False}), file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(asyncio.run(main()))
|
||||
67
skills/pr-creator/scripts/get_git_status.py
Normal file
67
skills/pr-creator/scripts/get_git_status.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Parallel git status fetcher using asyncio subprocess."""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
async def run_git_command(command: str) -> tuple[str, str, int]:
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
return (
|
||||
stdout.decode("utf-8", errors="replace").strip(),
|
||||
stderr.decode("utf-8", errors="replace").strip(),
|
||||
process.returncode or 0,
|
||||
)
|
||||
|
||||
|
||||
async def gather_git_status() -> dict[str, Any]:
|
||||
commands = {
|
||||
"status": "git status",
|
||||
"diff": "git diff",
|
||||
"diff_staged": "git diff --staged",
|
||||
"log": "git log --oneline -10",
|
||||
"current_branch": "git branch --show-current",
|
||||
}
|
||||
|
||||
tasks = {key: run_git_command(cmd) for key, cmd in commands.items()}
|
||||
results = await asyncio.gather(*[tasks[key] for key in commands.keys()])
|
||||
|
||||
output = {}
|
||||
for (key, _), (stdout, stderr, returncode) in zip(commands.items(), results):
|
||||
output[key] = {"stdout": stdout, "stderr": stderr, "returncode": returncode, "success": returncode == 0}
|
||||
|
||||
return output
|
||||
|
||||
|
||||
async def main() -> int:
|
||||
try:
|
||||
check_process = await asyncio.create_subprocess_shell(
|
||||
"git rev-parse --git-dir",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
)
|
||||
await check_process.communicate()
|
||||
|
||||
if check_process.returncode != 0:
|
||||
print(json.dumps({"error": "Not a git repository", "cwd": str(Path.cwd())}), file=sys.stderr)
|
||||
return 1
|
||||
|
||||
results = await gather_git_status()
|
||||
print(json.dumps(results, indent=2, ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e), "type": type(e).__name__}), file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(asyncio.run(main()))
|
||||
Reference in New Issue
Block a user