关于 gitcode-pr
面向 OpenHarmony 仓库的 GitCode PR 工作流技能,可识别上游与 fork 远程地址,并按流程处理 issue 和 PR。它依赖 GitCode MCP 工具执行相关操作。
主要功能
- 01识别上游与 fork 远程地址
- 02检查仓库状态和现有 PR
- 03根据模板创建 issue
- 04推送更改并创建关联 PR
- 05处理远程地址不明确等情况
适用场景
- 01向 OpenHarmony 上游仓库提交更改
- 02为新 PR 检查是否已有重复请求
- 03依据仓库模板创建 issue 和 PR
- 04在多远程地址仓库中确定推送目标
MCP 相关
该技能要求使用 GitCode MCP;若不可用,应警告并立即终止。它调用 GitCode 工具检查、创建和更新 issue 与 PR。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ openharmonyinsight/ openharmony-skills --skill gitcode-pr安装后在 Claude Code 中输入/gitcode-pr确认已加载。
附带文件references/issue_template.md
详细介绍
OpenHarmony 的 GitCode PR 工作流
为 OpenHarmony 仓库处理完整的 GitCode PR 提交,包括智能检测远程仓库和关联问题与 PR。使用 gitcode mcp。如果未提供 gitcode mcp,请警告用户并立即终止该技能。
智能检测远程仓库
识别算法
切勿假定远程仓库名称。使用以下算法识别上游仓库和 Fork:
# Step 1: List all remotes
git remote -v
# Step 2: Parse each remote
for remote in $(git remote); do
url=$(git remote get-url $remote)
# Parse owner from URL
# Format: https://gitcode.com/<owner>/<repo> or https://gitcode.com/<owner>/<repo>.git
if [[ "$url" =~ https://gitcode\.com/([^/]+)/(.+) ]]; then
owner="${BASH_REMATCH[1]}"
repo=$(echo "${BASH_REMATCH[2]}" | sed 's/\.git$//')
# Determine type
if [ "$owner" = "openharmony" ]; then
echo "$remote: UPSTREAM ($owner/$repo)"
else
echo "$remote: FORK ($owner/$repo)"
fi
fi
done
远程仓库分类
| 所有者 | 类型 | 用途 |
|---|---|---|
openharmony | UPSTREAM | PR 模板来源、PR 目标、问题创建目标 |
| 其他用户名 | FORK | 推送目标、PR 源分支 |
决策矩阵
| 上游远程仓库 | Fork 远程仓库 | 操作 |
|---|---|---|
| 已找到 | 已找到 | 两者都使用:在上游仓库创建问题/PR,推送到 Fork |
| 已找到 | 未找到 | 询问用户:“已找到上游仓库,但未找到 Fork。需要先创建 Fork 吗?” |
| 未找到 | 已找到 | 将 Fork 同时用作推送目标和 PR 目标(不常见) |
| 未找到 | 多个(没有 openharmony) | 询问用户选择:“要使用哪个远程仓库?” |
| 未找到 | 一个(没有 openharmony) | 将其用作 Fork,并警告:“未找到上游(openharmony)远程仓库” |
向用户发出提示
远程仓库存在歧义时,提示用户:
I found these GitCode remotes:
- **remote_name**: owner/repo (UPSTREAM/FORK)
Which remote should I use for:
- Pushing changes?
- Creating the PR?
Please specify the remote name, or press Enter to use [default].
工作流
用户请求提交 PR 时,遵循此工作流:
1. 检查当前状态
检查 git 状态和分支:
git status
git branch --show-current
git remote -v
确定:
- 当前分支名称是什么?
- 使用上述算法识别上游仓库和 Fork 远程仓库
2. 检查 PR 是否存在
使用 gitcode_list_pull_requests 检查是否已有 PR:
# Get upstream owner/repo (parse from upstream remote URL)
UPSTREAM_REMOTE=$(detect_upstream_remote)
UPSTREAM_URL=$(git remote get-url $UPSTREAM_REMOTE)
# Parse: openharmony/security_code_signature from URL
# List PRs for upstream repo
gitcode_list_pull_requests --owner $UPSTREAM_OWNER --repo $UPSTREAM_REPO
# Search for PR with matching branch name and owner name
如果 PR 已存在:只推送到 Fork 并告知用户。
git push -u $FORK_REMOTE <branch-name>
如果 PR 不存在:继续执行步骤 4–6,创建问题和 PR。
3. 创建问题
加载问题模板并创建问题:
- 读取问题模板:
references/issue_template.md - 根据上下文(提交消息、变更文件等)填写模板字段
- 使用
gitcode_create_issue在上游所有者/仓库中创建问题
注意:使用提交消息和 git diff 自动生成问题描述。
4. 推送到 Fork
推送到你的 Fork(检测到的 Fork 远程仓库):
git push -u $FORK_REMOTE <branch-name>
5. 从 Fork 向上游仓库创建 PR
从上游仓库加载 PR 模板,并创建关联问题的 PR:
-
获取上游 PR 模板:
# Try local copy first if [ -f .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md ]; then cat .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md else # Fetch from upstream git fetch $UPSTREAM_REMOTE master git show $UPSTREAM_REMOTE/master:.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md fi -
填写模板: 按照模板中的说明操作。
-
使用
gitcode_create_pull_request创建 PR:重要:对于跨仓库 PR,
head参数的格式至关重要。- 必须严格使用:
<fork-owner>:<branch-name>(不要添加额外前缀) - GitCode API 会严格校验跨 Fork PR 的此格式
参数:
owner:上游所有者(例如,openharmony)repo:上游仓库(例如,security_code_signature)title:遵循提交消息格式head:<fork-owner>:<branch-name>(从 Fork 远程仓库解析)base:上游的目标分支(通常为master或main)body:包含问题引用的模板内容
- 必须严格使用:
示例:
# After detection
UPSTREAM_OWNER="openharmony"
UPSTREAM_REPO="security_code_signature"
FORK_OWNER="someone"
FORK_REMOTE="fork"
gitcode_create_pull_request \
--owner $UPSTREAM_OWNER \
--repo $UPSTREAM_REPO \
--title "fix(code_signature): add null check for buffer pointer" \
--head "$FORK_OWNER:$BRANCH_NAME" \
--base "master" \
--body "$(cat .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | \
sed 's/^### 关联的issue:$/### 关联的issue:\n#$ISSUE_NUMBER/')"
模板
上游 PR 模板
位于上游仓库中的 .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md。
本地问题模板
参见 references/issue_template.md,了解标准问题格式。
主要部分:
- 问题描述:问题或功能请求是什么?
- 复现步骤:适用于错误报告(如适用)
- 预期行为:应该发生什么?
- 实际行为:实际发生了什么?
- 环境信息:任何相关的环境详情
远程 URL 解析
从远程 URL 中解析所有者和仓库:
# Function to parse GitCode URL
parse_gitcode_url() {
local url="$1"
# Remove .git suffix if present
url=$(echo "$url" | sed 's/\.git$//')
# Extract owner and repo
if [[ "$url" =~ https://gitcode\.com/([^/]+)/(.+) ]]; then
echo "${BASH_REMATCH[1]}|${BASH_REMATCH[2]}"
fi
}
# Usage
result=$(parse_gitcode_url "https://gitcode.com/openharmony/security_code_signature")
owner="${result%%|*}"
repo="${result##*|}"
# owner=openharmony, repo=security_code_signature
PR 模板中的问题引用
在 .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md 中填写问题引用:
### 关联的issue:
#123
PR 合并后将自动关闭问题 #123。
GitCode 工具
使用这些工具执行 GitCode 操作:
gitcode_list_pull_requests- 检查现有 PR(使用上游 owner/repo)gitcode_get_pull_request- 获取 PR 详情gitcode_create_pull_request- 创建新 PR(head 指向 fork)gitcode_update_pull_request- 更新现有 PRgitcode_create_issue- 创建新 issue(使用上游 owner/repo)gitcode_get_issue- 获取 issue 详情
错误处理
- 身份验证失败:检查是否已配置 GitCode 令牌
- fork 上找不到分支:创建 PR 前先推送到 fork
- PR 已存在:告知用户并提供链接,不要创建重复 PR
- 没有上游远程仓库:请用户配置上游远程仓库(owner=openharmony)
- 没有 fork 远程仓库:询问用户要推送到哪个远程仓库,或者是否需要先 fork
- 存在多个非 openharmony 远程仓库:询问用户选择哪个作为自己的 fork
- 找不到 PR 模板:检查上游是否存在
.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md - Owner/repo 解析错误:验证远程 URL 格式
决策树
User requests PR
↓
Check git status
↓
Changes uncommitted? → Yes → Commit changes
↓ No
List and parse remotes
↓
Detect upstream (owner=openharmony) and fork
↓
┌─────────────────────────────────────┐
│ Remote detection result: │
│ - Upstream found? │
│ - Fork found? │
└─────────────────────────────────────┘
↓
┌─────────────────────────────────────┐
│ Need user input? │
│ - No fork? │
│ - Ambiguous remotes? │
└─────────────────────────────────────┘
↓ Yes → Ask user
↓ No
Push to fork
↓
List PRs (upstream repo)
↓
PR exists for branch? → Yes → Inform user (PR already exists)
↓ No
Create issue (upstream repo)
↓
Get PR template from upstream (.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md)
↓
Create PR (head: fork-owner:branch, base: upstream-branch)
↓
Done
收集上下文
创建 issue 或 PR 时,从以下信息中收集上下文:
git log -1- 最新提交消息git diff HEAD~1- 已更改的文件和差异- 分支名称 - 功能上下文
- 用户输入 - 用户提供的其他说明
git remote -v- 所有远程仓库及其 URL- 远程仓库解析 - 上游 owner/repo 和 fork owner/repo