SuperAPI AI Directory

create-pr

Coding & development

View repository

Updated 11-08 11:57

About this skill

create-pr

One stop:commit → code review → push → create/update PR. Invoking it authorizes push / PR creation, with no step-by-step confirmation; commit still goes through the commit-msg dialog. Do not tidy up historical commits, rewrite the remote, force push, or merge PRs.

Forks are not supported: origin must be yaklang/yakit(the PR is created in --repo yaklang/yakit). When origin points to a personal fork, stop at step 1 and prompt the user to push themselves and create the PR via the web page.

Interaction and skill loading

In this document, AskUserQuestion refers to an interaction tool available in the current environment (such as request_user_input_async); use it when the tool's purpose allows, and if no suitable tool exists, ask in the conversation. When an answer is needed, wait for the user's actual reply; an asynchronous request still awaiting an answer, a timeout, or an empty result does not count as consent; choices or authorizations already made explicit in this session are carried over directly.

Invoke the skill through the loading mechanism of the current environment; when there is no dedicated Skill tool, directly read the actual SKILL.md and the references it requires and follow them. A missing tool does not mean a missing skill; only when the skill content cannot be found or read do you take the missing branch.

Inputs (all optional, may appear together)

Identify from the user's original text; do not ask follow-up questions, do not guess, do not search:

  1. Merge method:merge / squash / rebase or "merge commit / squash merge / rebase merge". If present, use it directly and do not apply the automatic rules.
  2. Associations: issues in this repository (close / fix / ref #xxxx) and PR URLs from other repositories (such as the yaklang engine).Write only when explicitly provided by the user. If neither exists, fill "Associated Issue / PR" with None。

1. Pre-checks

  • Get the branch:pr_branch="$(git branch --show-current)"; stop if the command fails, the branch name is empty (detached HEAD), or it is master .

  • The following Bash/Zsh example passes the branch name via "$pr_branch" ; each independent shell invocation must first perform the above assignment and check the result. Do not backfill the read branch name into shell command text or pass it to eval; other execution tools should use parameter arrays or the corresponding shell's safe variable passing.

  • git remote -v: origin must be yaklang/yakit, otherwise stop (forks follow the prompt above).

  • gh:command -v gh + gh auth status(PowerShell:Get-Command gh). If installed and logged in, continue; otherwise take the fallback below,do not stop directly。

  • code-review skill must exist(step 3 depends on it unconditionally; when a scope is specified externally, execute directly without showing a dialog). If it does not exist,stop immediately, and do not perform the review yourself—at this point nothing has been committed / pushed yet.

  • git fetch origin master; the PR base is fixed to master。

  • git status + git log origin/master..HEAD --oneline preliminary check. If there are no commits and no changes in the workspace → stop.

  • When gh is available, first check for duplicates and save a snapshot of the old PR, for reuse in reviewing historical issues and in steps 5–7:

    gh pr view "$pr_branch" --repo yaklang/yakit --json number,url,state,title,body
    

    Only when it explicitly returns "no PR for this branch" should it be treated as a new PR; if authentication, network, or other query failures occur → stop and report the error, and do not treat it as nonexistent. In manual mode, skip the query; if the user provides an old description, use its content.

🔴 CHECKPOINT: gh degraded (not installed or not logged in)

AskUserQuestion Choose one (the question states the current gh status); selecting Other to cancel stops the process:

  • Install and log in to gh:macOS brew install gh;Windows winget install GitHub.cli(or scoop / choco); on Linux, point to the official installation. After installation, have the user run gh auth loginthemselves (interactive, the agent cannot do it on their behalf); after confirmation,return to step 1 to recheck. If installation or login fails, stop.
  • Create the PR manually: follow steps 1–6 as usual, but change step 7 to "manual mode" (do not run any gh)。

2. Handle workspace changes

git status(including untracked). If clean, skip; do not make empty commits.🔴 CHECKPOINT: choice for handling uncommitted changes,AskUserQuestion(summary such as "3 modified + 1 untracked"); selecting Other to cancel stops the process:

  • Commit as a single commit:git add -A, generateone commit. Prefer calling commit-msgvia the loading mechanism above; if the skill cannot be found or read, do it yourself according to its specification (confirm the complete message and scope → preserve line breaks and write a temporary file → git commit -F; based on the diff, summarize by actual change type, one line per type type: subject, primarily Chinese, within 72 characters per line, without (#PR号))。final-state verification: proceed to step 3 only if COMMITTED and git rev-parse HEAD has moved forward, andgit diff --cached is empty; ifCANCELLED / FAILED or verification does not match → STOP: stop the entire process, and do not review or push with the old HEAD.
  • Stash the changes:git stash push -u -m "create-pr: 暂存未提交改动". This PR does not include these changes; report that the stash has been created,do not automatically stash pop。

3. Code review (mandatory, before push)

Target:git diff origin/master...HEAD(the final HEAD after step 2). Read-only: only record issues, do not fix them along the way (including P0).

  • At the start of the review, record the git rev-parse HEAD full SHA.
  • Must call code-reviewvia the loading mechanism above, scoped to this branch vs origin/master(scope already specified, no dialog). If the skill cannot be found or read → stop; do not review on your own. When updating the PR, also recheck the historical issues in the snapshot (including fixed items) and record current evidence; without rechecking, they cannot be considered fixed.
  • Extract from the report: all P0+P1 (warnings are not written into the PR) → "Issues recommended to fix before merging"; the conclusion (not passed / needs fixes / can merge) and statistics line from "III. Merge conclusion" → "Code review conclusion" (required). For each issue, record 文件:行号 + one sentence. The conclusion may only come from the actual code-review output and must not be fabricated.

4. Push to remote

  • Before pushing, run git rev-parse HEADagain; continue only if it matches the SHA from step 3; if not, stop.
  • Bare git pushis forbidden. Run git push -u origin "HEAD:refs/heads/$pr_branch"(explicit origin).
  • After pushing:git ls-remote origin "refs/heads/$pr_branch" 's OID == local HEAD, otherwise stop.
  • Push rejected (remote has commits that the local does not): stop; do not pull / rebase / force push.

5. Generate PR title and description

Title(git log origin/master..HEAD --format='%B' read the complete message of all commits,do not use the branch name): single line type: subject(primarily Chinese, no period, without (#PR号), preferably 72 characters; count Chinese characters as 2). If there is only one commit and the message is a single line, you may reuse it directly; if the message has multiple lines or there are multiple commits, summarize the main semantics into a one-line PR title (type: feat/fix/docs/style/perf/refactor/test/build/ci/chore).

Update an existing PR: old title == branch name -> replace with a summary title; old title != branch name -> keep the old title。

Description: first read .github/PULL_REQUEST_TEMPLATE.md(do not write from memory), fill in according to the template; HTML comments may be deleted butkeep all sections. When updating an OPEN PR, use the snapshot from step 1, and migrate old fields and issue status according to the rules in step 7. If the template does not exist, use references/pr-examples.md 's agreed structure; the "Merge method" must still have three checkboxes and must not be written as a single line. Information that cannot be confirmed from the diff / log / user input should be marked "to be supplemented", and explained to the user before creation. See that references for positive examples and synchronization examples.

  • Change types: read the full messages of all commits in this PR (including multi-line type: subject / type(scope): subject), use the types in them as clues, combine them with origin/master...HEAD 's actual changes to summarize and deduplicate, then check all that apply, with no limit on the number and not restricted by the single type of the PR title. Map to the template: feat -> new feature, fix -> bug fix, docs -> documentation change, style -> style / UI adjustment, perf -> performance optimization, refactor -> refactor, test -> test change, build -> build / dependency / packaging configuration, ci -> CI workflow change, chore -> miscellaneous. If the type cannot be identified, judge based on the diff; do not treat ordinary text in the message body as a type.
  • fix attribution: check the code before and after the fix, the related commits, and origin/master 's corresponding behavior. If it only patches a problem introduced by a new feat on this branch, attribute it to that feat and do not additionally check Bug fix; only when this PR fixes a problem that already existed in the baseline should that checkbox be added. When a single PR both adds a feature and fixes a baseline problem, check both feat and fix. Do not judge only by commit prefix, commit order, or whether files are newly added; if evidence is insufficient, mark it as to be confirmed and do not automatically check fix. When updating an existing PR, the user's original checkboxes are still retained according to step 7.
  • 🔗 Related Issue / PR: issues explicitly provided by the user (close / fix / ref #xxxx) and cross-repository PR URLs; if none, fill in None. Do not fabricate numbers or links.
  • 💡 Background and approach: original problem -> this approach; based on the full diff, do not list files one by one.
  • Impact scope: user-visible behavior changes; for pure refactoring write "does not change user-visible behavior"; for UI changes, screenshots are recommended.
  • Merge method: check the option selected in step 6.

Append outside the template(insert after "Impact scope" and before "Merge method"):

## 代码评审结论

**结论:不通过**(正确 6 项 / 问题 3 项(P0 1 项 / P1 2 项)/ 警告 2 项)

Required section; place it before "Problems recommended to fix before merging"Previously. When updating an existing PR,overwrite and rewrite each time。

## 建议合并前修复的问题

- [ ] `src/xxx.ts:123` <问题描述>

All P0+P1 from step 3; fixed - [x]. If there are no such problems, omit the entire section. When updating an existing PR, this sectionis retained cumulatively(including those marked as fixed), and must not be lost due to regenerating the description; whether it is fixed is based on the current review, and the synchronization rules are in step 7.

6. Merge method selection

  1. Specified by the user this time -> use it directly.
  2. Updating an OPEN PR and the user did not specify -> keep the method already checked in the old description's "## Merge method"(gh pr edit --body is a full replacement). If the section is absent or none of the three are checked → priority 3.
  3. Auto (new, or update but the old description has no valid checks):git log origin/master..HEAD --format='%an' deduplicated author count + total commit count,top to bottom:
Order Condition Method
1 Authors ≥ 2,or commit > 3 merge
2 commit = 1 rebase
3 commit 2–3 and the same author squash

Check the corresponding item in the description,keep the full text of all three items(consistent with the template):

## 合并方式

- [ ] Create a merge commit(保留完整提交历史)
- [x] Squash and merge(压缩为一条提交)
- [ ] Rebase and merge(线性历史)

See for a judgment example references/pr-examples.md。

7. Create or update the PR

When gh is available, choose the following branch according to the snapshot in step 1, and do not regenerate already determined fields; if the user chose "manually create PR", skip to "Manual mode" at the end.

Dynamic text (body / title)must not be interpolated into shell: first write to a temporary file in the system temporary directory (referred to below as <pr-body-file> ), use --body-file, and delete it after use. Wrap title in single quotes and escape internal single quotes.

  • Existing OPEN PR:Do not create a new one,gh pr edit update the description, andevery time must include --title(the final title after intelligent replacement in step 5; omitting --title may change the title):

    Before writing, re-read by PR number number,url,state,title,body. If the query fails, stop; if the state is no longer OPEN, stop and report, and do not continue editing. If the title or body differs from the snapshot, replace the snapshot with the latest content, re-review newly added or changed historical issues, and re-execute steps 5–6 and the migration rules below before writing, to avoid overwriting modifications made during review.

    gh pr edit <PR number> --repo yaklang/yakit --title '<最终标题>' --body-file /tmp/pr-body.md
    

    When generating the description in step 5, apply the following rules based on the old description in the snapshot:

    • Change type: keep all checked items in the old section, then additionally check the types confirmed in step 5 based on the diff and baseline attribution; do not uncheck the user's existing checks, and do not add duplicate entries. If nothing is checked or the section is absent, generate according to step 5.
    • Linked Issue / PR: if the old content is not None , keep it; if the user provides new links this time, merge and deduplicate; only fill in if the old value is None and none is provided this time None。
    • Merge method: step 6 priority 2.
    • Issues recommended to fix before merging: synchronize based on this review and re-review evidence in step 3, and do not delete historical entries (including the old "## P0 issues"):
      • All state transitions update the original entry, retaining previous fix hashes and recurrence records in chronological order; when fixing again, append this fix record, and do not discard existing history even if evidence is insufficient or the fix commit cannot be located. Do not append duplicate records for repeated re-reviews with the same state and same evidence. The following format only illustrates the current state and must not overwrite existing history; when the old "this re-review" becomes history, rename it to "previously reviewed".
      • Current evidence confirms it is fixed:- [x] ~~<原问题>~~(✅ 已修复:<核实的修复短哈希>); if the fix commit cannot be located, write "confirmed in this re-review, fix commit not located", and do not fabricate a hash.
      • Previously marked as fixed, currently confirmed the same defect has recurred: change the original entry to - [ ] <原问题>(曾修复:<原短哈希>;本次复核:已复发), remove the strikethrough, keep the fix history, and do not append duplicate entries.
      • Insufficient evidence at this time: keep the original question, mark - [ ] and "pending review"; change the original already-fixed annotation to "previously marked as fixed: <original short hash>", and it must not be treated as a fix confirmed this time.
      • Still not fixed: keep as is; change the old plain list to - [ ]; new issue - [ ] append.
      • The old version had no such section and this time also has no P0/P1: do not generate this section.

    Report after completion: PR link, updated description, merge method (reuse old checkboxes / specified this time / automatic), review conclusion and statistics, related information, suggested fixes and status.

  • An existing CLOSED / MERGED PR:do not update, do not reopen, follow the belowCreate new; generate the new description according to step 5, and do not migrate the old PR history.

  • No OPEN PR(not found, or only CLOSED / MERGED):

    gh pr create --repo yaklang/yakit --base master --head "$pr_branch" --title '<commit 总结标题>' --body-file /tmp/pr-body.md
    

    Title is the one from step 5 based on all commits type: subject(for multiple commits, do not copy a single message). After success, report: link, title, merge method, review conclusion and statistics, related information, suggested fixes (if any).

  • If create reports "A pull request already exists": first re-read according to step 1 number,url,state,title,body; if the query fails, stop. After confirming OPEN, re-review its historical issues, regenerate the title, description, and merge method according to the update rules in steps 5–7, then gh pr edit(must include --title); do not overwrite old fields with the newly created description. If it is already CLOSED / MERGED, stop and report the status, and do not repeatedly create.

  • Read-back verification:gh pr view <PR number> --repo yaklang/yakit --json title,body --jq '{title: .title, body: .body}'(number: for updates use the deduplication result; for new creation use the number in the link output by create, to avoid interference from old closed PRs). ① Title == the final title from step 5 (new creation = summary title; update = smart replacement); if it does not match, then gh pr edit ... --title '<最终标题>'; ② The description contains the complete "## Merge method" and the checkboxes are consistent with step 6; if not, then gh pr edit. Only report to the user after both points pass.

When the user only requests generating a description and not creating, trim the steps according to the actual request, and do not force running the entire process.

Manual mode

The first 6 steps proceed as usual; in this step do not execute any gh、do not write any files, and after the title and description are displayed in the dialog box, end (the user handles the creation result themselves):

  1. PR title: a separate code block (the summary title from step 5).
  2. Full description: display the markdown in a code block source code(do not truncate, do not render).
  3. Creation entry:https://github.com/yaklang/yakit/compare/master...<当前分支>?expand=1. Automatic deduplication is unavailable; remind the user to first check whether the page already has a PR.
  4. If the old PR description cannot be read, by default do not include old checkboxes / related information / merge method / accumulated issues. If the user pastes the full old description to the agent, merge it according to the synchronization rules in step 7; if not provided, remind the user to merge it manually in the web editor.