| name | github-pr |
| description | Make changes to a GitHub repository and open a pull request — clone, branch, edit, commit, push with git, then create the PR via the GitHub REST API. Use when a task asks you to fix, change, or add something in a repo and propose it for review (not just read it). |
| metadata | {"homepage":"https://github.com/bradflaugher/LFG"} |
github-pr
End-to-end "implement and propose" loop using the git CLI plus the GitHub
REST API (via python3 + requests, both in the sandbox). Requires
GITHUB_TOKEN forwarded into the container with LFG_PASS_ENV=GITHUB_TOKEN
(a token with repo scope).
Steps
-
Clone and enter the repo, with a credential helper so the token never
lands in .git/config:
export GIT_CRED='!f() { echo username=x-access-token; echo "password=$GITHUB_TOKEN"; }; f'
git -c credential.helper="$GIT_CRED" clone https://github.com/OWNER/NAME.git
cd NAME
-
Identify yourself to git (once per workspace):
git config user.name "lfg-agent"
git config user.email "lfg-agent@users.noreply.github.com"
-
Branch off the default branch with a descriptive name:
git switch -c fix/short-description
-
Make the change. Edit files with normal shell tools. Keep the diff
focused on the task; don't reformat unrelated code. If the repo has tests,
run them and make sure they pass before continuing.
-
Commit with a clear message:
git add -A
git commit -m "Fix: short description of what changed and why"
-
Push and open the PR (the API call prints the PR URL). Write the real
title and body into the script before running it:
git -c credential.helper="$GIT_CRED" push -u origin HEAD
python3 - <<'EOF'
import os, subprocess
import requests
branch = subprocess.check_output(
["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True).strip()
remote = subprocess.check_output(
["git", "remote", "get-url", "origin"], text=True).strip()
owner_repo = remote.removeprefix("https://github.com/").removesuffix(".git")
base = subprocess.check_output(
["git", "rev-parse", "--abbrev-ref", "origin/HEAD"], text=True
).strip().removeprefix("origin/")
r = requests.post(
f"https://api.github.com/repos/{owner_repo}/pulls",
headers={"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}",
"Accept": "application/vnd.github+json"},
json={"title": "Fix: short description",
"body": "What changed, why, and how it was verified.",
"head": branch, "base": base},
timeout=30,
)
r.raise_for_status()
print(r.json()["html_url"])
EOF
-
Report the printed PR URL as your final output.
Rules
- Never force-push or commit to
main/master directly — always a branch + PR.
- If you can't push (missing token, no write access), stop and report exactly
what's missing rather than half-finishing.
- Match the repository's existing style and conventions. Read neighbouring code
before adding new code.
- Keep the PR body honest: if you couldn't run the tests, say so.