feat(forge): pr merge squash-merges a ready, passing pull request; pr checks and pr diff #14
No reviewers
Labels
No labels
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Tooling!14
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Tooling:feat/forge-pr-merge"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Agents open pull requests with
forge.py pr create, but when they're told to "open the PR and merge it" they can't: forge.py has no merge. The only other way is to take the stored git token and call Forgejo's API by hand, and agents must not do that. This adds the merge to forge.py, with the same checks a person makes before pressing the button.What changed
scripts/forge.py, documented indocs/forge.md(new section Merging a pull request) and the script's help:pr merge N [--delete-branch] [--force]squash-merges into main throughPOST /pulls/{n}/merge, the way the merge box on the PR's page does. The commit's title is the PR's title plus(#N). The message is the description, then aCo-authored-by:for each other author of the PR's commits, thenReviewed-on: <PR link>. If the API gets no message, the commit has only its title. The merge sendshead_commit_id, so Forgejo refuses it if someone pushes after the checks were read. It prints the merge commit's link and the PR's.--delete-branchsendsdelete_branch_after_merge. If the merge goes through and only the branch deletion fails, it prints a warning and exits 0.It refuses before posting anything when the PR is:
pr ready);Unless
--forceis given, it also refuses when the description fails the checkpr readyruns, or when a check on the head commit failed, is still running, or is waiting for a maintainer to approve the run.--forcegets past only those last two, with a warning. The docs say agents use it only when the person they work for asks. Forgejo still enforces who may merge.pr checks Nlists the CI statuses on the head commit: state, name, what it says, and its link, then how many passed, failed and are still running. It exits 1 when a check failed or is still running. A repository with no CI shows no checks and exits 0.pr diff Nprints the PR's diff exactly as Forgejo gives it, the same.diffthatpr reviewalready reads.How it was tested
tests/test_forge_pr.pyadds 6 tests against the stand-in Forgejo:pr checksoutput and exit codes, with passing, failing, running and no checks;pr diff;head_commit_id) and the printed result;--forcecan't get past;--force;--delete-branch, the server refusing the merge, and a merge that stands when only the branch deletion fails.LONGSHOT=<Longshot checkout> python -I -B tests/run_all.py: 82 tests intest_forge_pr.py, every new one passing. The one failure,test_create_draft_is_the_default_and_wip_is_not_doubled, is already failing on main, as #11 says. It expects no PATCH after apr create --body, which has not been true since #2 (allow_maintainer_edit). This PR leaves it alone.pr checkson LongshotLauncher#137 (success and skipped, exit 0), Longshot#1062 (9 runs waiting for approval, exit 1) and Tooling#11 (no checks, exit 0);pr diffon LongshotLauncher#137;Co-authored-by:for the commits' other author, thenReviewed-on:.routers/api/v1/repo/pull.go,MergePullRequestForm), and its message matches the squash commits already on main.🤖 Generated with Claude Code