From cc-copilot-plugin
建立與維護 GitHub Pull Request 的專用 skill,應在以下情況立即使用:使用者提到建立/開 PR、open a PR、submit PR、make a PR、push and create PR、修改或更新 PR 標題/描述/標籤/審核者、查看 PR 狀態或 CI 結果。自動偵測預設分支、檢查未提交變更、分析 commit 與 diff,產生符合 Conventional Commits 規範的標題,並依 PR 規模選擇精簡版或完整版模板。支援中英文切換(含 english / 英文 / 用英語 等關鍵字)。透過 GitHub CLI (gh) 執行。不適用於純 git push、git merge、PR code review/審查程式碼(由獨立 review skill 處理)或非 GitHub 平台的 PR 操作。
How this skill is triggered — by the user, by Claude, or both
Slash command
/cc-copilot-plugin:pull-requestThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
建立與維護 GitHub Pull Request,涵蓋 PR 建立、描述/標題/標籤/審核者更新以及狀態查詢。**程式碼審查 (code review) 不在此 skill 範圍內,請使用獨立的 review skill。**
建立與維護 GitHub Pull Request,涵蓋 PR 建立、描述/標題/標籤/審核者更新以及狀態查詢。程式碼審查 (code review) 不在此 skill 範圍內,請使用獨立的 review skill。
前置需求:已安裝並登入 GitHub CLI (gh auth status 通過)。
english、in English、用英文、英文、用英語、以英文 任一字詞時,全程改用英文輸出。graph TD
A[使用者請求] --> B{語言偵測}
B -- 含 english/英文/用英文/用英語/以英文 --> LANG_EN[語言:English]
B -- 其他 --> LANG_ZH[語言:zh-TW]
LANG_EN & LANG_ZH --> C{請求類型}
C -- 建立/開 PR/create PR --> PRE[Pre-flight: git status --porcelain]
C -- 修改/更新/edit PR --> F2[修改流程]
C -- PR 狀態/CI 結果 --> S[gh pr status / gh pr view]
C -- review/審查程式碼 --> OUT[導向獨立 review skill]
C -- 無法識別 --> UND[輸出 undecidable + 詢問意圖]
PRE -- 有未提交變更 --> STOP[提示先執行 cc-copilot-plugin:commit-message]
PRE -- 乾淨 --> BASE[gh repo view 偵測 defaultBranchRef]
BASE --> D[檢查當前分支 PR 狀態]
D -- PR 不存在 --> E{PR 規模判斷}
D -- PR 已存在 --> F2
E -- commits≤2 且 檔案≤10 --> G[精簡模板]
E -- 其餘 --> H[完整模板]
H --> DEPLOY{符合 Deployment 觸發?}
DEPLOY -- 是 --> H2[插入 Deployment 區塊]
DEPLOY -- 否 --> I
H2 --> I[gh pr create --body-file pr-body.md]
G --> I
I --> CLEAN[刪除 pr-body.md]
請嚴格按照以下順序評估,一旦滿足某項規則,立即執行對應動作並終止後續判斷。
語言判斷(最優先)
規則 L1:若使用者訊息含 english、in English、用英文、英文、用英語、以英文 任一字詞,則全程使用英文輸出。
規則 L2:否則,使用繁體中文 (zh-TW) 輸出。
請求類型判斷
規則一:若請求含「建立」「開 PR」「create PR」「new PR」「make a PR」等建立意圖,則進入建立 PR 流程。
規則二:若請求含「修改」「更新」「edit PR」「update PR」「改描述」「改標題」等修改意圖,則進入修改 PR 流程。
規則三:若請求含「狀態」「CI」「check」「status」「PR 有沒有過」等查詢意圖,則執行 gh pr status 或 gh pr view 並顯示結果。
規則四:若請求含「review」「審查」「審閱」「檢查程式碼」「code review」等審查意圖,不在本 skill 範圍,請回覆使用者並建議改用獨立的 PR review skill。
回退規則:若請求無法明確歸類至上述任何意圖,輸出 <undecidable> 並詢問:「請問你想要建立新 PR、修改 PR 描述,還是查看 PR 狀態?」
PR 規模判斷(建立 PR 流程專用)
規則 S1:若 commits ≤ 2 且 變更檔案 ≤ 10,則使用精簡版模板。
規則 S2:其餘情況,使用完整版模板;若同時符合 Deployment 觸發條件(詳見 references/pr-template.md),則在完整版「備註」前插入 Deployment 區塊。
產生的標題必須符合以下格式:
<type>(<scope>): <summary>
feat: 新功能fix: 修復 Bugperf: 效能優化refactor: 程式碼重構docs: 僅文件變更test: 測試相關build/ci: 建置系統或 CI 配置chore: 常規維護!,例如 feat(api)!: 修改端點。git status --porcelain
cc-copilot-plugin:commit-message skill 完成提交。# 動態取得 base branch,取代硬編的 origin/main
BASE=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
# 確認已推送到遠端;若尚未設 upstream,`-u` 會建立追蹤關係。
# 任何錯誤(無可推送 commit、衝突等)應直接顯示給使用者處理,不抑制輸出。
git push -u origin HEAD
git log "origin/$BASE..HEAD" --oneline | wc -l # commit 數(兩點:HEAD 相對 BASE 的新 commits)
git diff --name-only "origin/$BASE...HEAD" | wc -l # 變更檔案數(三點:相對 merge-base,與 GitHub PR diff 一致)
git diff "origin/$BASE...HEAD" # 完整 diff(三點,與 gh pr diff 一致)
兩點 vs 三點:
git log A..B顯示「B 有但 A 沒有」的 commit;git diff A...B比較「merge-base(A,B) 與 B」——後者才是 GitHub PR 頁面顯示的 diff,file-count 與完整 diff 都應使用三點以保持一致。
references/pr-template.md)根據規模判斷填寫對應模板,並:
references/pr-template.md 的 Issue 參照表)。繁體中文內容必須透過檔案輸入給 gh,避免在 Windows cmd / PowerShell 預設 cp950 終端機下被 shell 位元組層破壞。
# 先確認 pr-body.md 為 UTF-8 無 BOM(見下方「編碼規範」)
gh pr create \
--draft \
--body-file pr-body.md \
--title "<type>(<scope>): <summary>"
--body-file,禁止用 --body "$(cat pr-body.md)" 或 heredoc 直接傳字串——那會走 shell 展開。gh pr create 無 --title-file 旗標,直接傳字串等於 shell 展開,無法透過 "$(cat file)" 規避。此情境只能使用下列二段式:
# Step A:用 ASCII 占位標題建立草稿 PR,取得 PR 編號
gh pr create --draft --body-file pr-body.md --title "chore: draft (title pending)"
# Step B:立即以 gh api PATCH 的 @file 模式覆寫真實標題
printf '%s' "<type>(<scope>): <summary>" > pr-title.txt
gh api -X PATCH "repos/:owner/:repo/pulls/<新建立的 PR number>" -f [email protected]
rm -f pr-title.txt
git-bash / WSL / macOS / Linux 終端機預設 UTF-8,可直接傳標題;Windows 使用者也可於同 session 先執行 chcp 65001 後再單段建立。建議以 --draft 建立,確認 CI 通過再 gh pr ready <number> 轉正式。
rm -f pr-body.md pr-title.txt
即使 gh pr create 失敗也務必清除,避免殘留檔案。
當使用者要求「修改 PR」「更新描述」「edit PR」或 PR 已存在時自動進入此流程。
重要:
gh pr edit對 title/body 的更新因 GitHub Projects (classic) 棄用而已不可靠,請改用gh api -X PATCH直接呼叫 REST API。標籤與審核者仍可使用gh pr edit。
gh pr view --json number,title,body,labels,assignees
詢問使用者要修改的欄位(標題、描述、標籤、審核者等)。
重要:所有含中文的欄位 (title / body) 必須以 gh 的
@filename語法讀檔,由 gh 以 UTF-8 位元組直接送出;不可用-f body="$(cat file)"讓 shell 展開,否則在 Windows cmd / PowerShell 下會因 cp950 轉碼產生亂碼。檔案必須為 UTF-8 無 BOM(見下方「編碼規範」)。
pr-body.md,再:
gh api -X PATCH "repos/:owner/:repo/pulls/<number>" -f [email protected]
rm -f pr-body.md
# 標題短可直接傳;若終端機非 UTF-8 且標題含中文,改用檔案模式
gh api -X PATCH "repos/:owner/:repo/pulls/<number>" -f title='<新標題>'
# 檔案模式(避免 cp950 亂碼)
printf '%s' '<新標題>' > pr-title.txt
gh api -X PATCH "repos/:owner/:repo/pulls/<number>" -f [email protected]
rm -f pr-title.txt
printf '%s' '<新標題>' > pr-title.txt
gh api -X PATCH "repos/:owner/:repo/pulls/<number>" \
-f [email protected] \
-f [email protected]
rm -f pr-body.md pr-title.txt
gh pr edit <number> --add-label "<label>" --remove-label "<label>"gh pr edit <number> --add-reviewer "<username>"若
gh pr edit的 label / reviewer 更新回報錯誤,改用 REST:
- 加標籤:
gh api -X POST "repos/:owner/:repo/issues/<number>/labels" -f "labels[]=<label>"- 加審核者:
gh api -X POST "repos/:owner/:repo/pulls/<number>/requested_reviewers" -f "reviewers[]=<user>"
詳細指令請參閱 references/gh-pr-commands.md。
| 功能 | 指令 |
|---|---|
| 偵測預設分支 | gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name' |
| 檢查狀態 | gh pr status |
| 查看內容 | gh pr view --json number,title,body |
| 建立草稿 | gh pr create --draft --body-file pr-body.md |
| 更新標題/描述 | gh api -X PATCH "repos/:owner/:repo/pulls/<n>" -f title=... -f body=... |
| 修改標籤 | gh pr edit <number> --add-label "bug,release" |
| 查看 Diff | gh pr diff <number> |
繁體中文 PR 在 GitHub 網頁顯示亂碼的根因是 shell 在把字串送進 gh 前就做了錯誤轉碼(Windows cmd / PowerShell 預設 cp950,把 UTF-8 位元組當成 big5 重新編碼)。
--body-file pr-body.md(建立)或 -f [email protected](修改),讓 gh 以 UTF-8 位元組直接讀檔,繞過 shell。--body "$(cat file)"、-f body="$(cat file)" 或 heredoc 內嵌中文傳給 gh。-f [email protected])。chcp 65001 切 UTF-8;git-bash / WSL / macOS / Linux 預設即為 UTF-8。送出前可快速確認 pr-body.md 編碼:
# 檢查是否有 BOM(UTF-8 BOM 為 EF BB BF)。輸出不應以 efbbbf 開頭。
head -c 3 pr-body.md | od -An -tx1
# file 工具可直接判斷(若可用)
file pr-body.md # 期望:UTF-8 Unicode text
# 目視抽樣:確認中文正確解碼
head -5 pr-body.md
若檢出 BOM,重新產生檔案即可(Write 工具預設不寫 BOM)。
Refs INTERNAL-1234)連結。PR 在 open-source repo 通常公開可見。gh 指令後,務必刪除 pr-body.md、pr-title.txt 等暫存檔案(即使指令失敗)。@filename / --body-file 路徑,檔案為 UTF-8 無 BOM(詳見「編碼規範」)。Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub gn00678465/cc-copilot-plugins --plugin cc-copilot-plugin