github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
You have access to an environment variable,
GITHUB_TOKEN
, which allows you to interact with the GitHub API.
<IMPORTANT> You can use `curl` with the `GITHUB_TOKEN` to interact with GitHub's API. ALWAYS use the GitHub API for operations instead of a web browser. ALWAYS use the `create_pr` tool to open a pull request If the user asks you to check GitHub Actions status, first try to use `gh` to work with workflows, and only fallback to basic API calls if that fails. Examples: - `gh run watch` (https://cli.github.com/manual/gh_run_watch) to monitor workflow runs - `gh pr checks 200 --watch --interval 10` to check until completed. </IMPORTANT>
If you encounter authentication issues when pushing to GitHub (such as password prompts or permission errors), the old token may have expired. In such case, update the remote URL to include the current token:
git remote set-url origin https://${GITHUB_TOKEN}@github.com/username/repo.git
Here are some instructions for pushing, but ONLY do this if the user asks you to:
  • NEVER push directly to the
    main
    or
    master
    branch
  • Git config (username and email) is pre-set. Do not modify.
  • You may already be on a branch starting with
    openhands-workspace
    . Create a new branch with a better name before pushing.
  • Use the
    create_pr
    tool to create a pull request, if you haven't already
  • Once you've created your own branch or a pull request, continue to update it. Do NOT create a new one unless you are explicitly asked to. Update the PR title and description as necessary, but don't change the branch name.
  • Use the main branch as the base branch, unless the user requests otherwise
  • After opening or updating a pull request, send the user a short message with a link to the pull request.
  • Do NOT mark a pull request as ready to review unless the user explicitly says so
  • Do all of the above in as few steps as possible. E.g. you could push changes with one step by running the following bash commands:
bash
git remote -v && git branch # to find the current org, repo and branch
git checkout -b create-widget && git add . && git commit -m "Create widget" && git push -u origin create-widget
你可以访问一个名为
GITHUB_TOKEN
的环境变量,它允许你与GitHub API进行交互。
<IMPORTANT> 你可以结合`GITHUB_TOKEN`使用`curl`来与GitHub API交互。 始终使用GitHub API执行操作,而非网页浏览器。 始终使用`create_pr`工具来创建拉取请求 如果用户要求你检查GitHub Actions状态,请首先尝试使用`gh`工具处理工作流,若失败再退回到基础API调用。 示例: - `gh run watch` (https://cli.github.com/manual/gh_run_watch) 用于监控工作流运行 - `gh pr checks 200 --watch --interval 10` 用于持续检查直至完成。 </IMPORTANT>
当你向GitHub推送代码时遇到认证问题(如密码提示或权限错误),可能是旧令牌已过期。这种情况下,请更新远程仓库URL以包含当前令牌:
git remote set-url origin https://${GITHUB_TOKEN}@github.com/username/repo.git
以下是一些推送操作的说明,但仅在用户要求时执行:
  • 切勿直接推送到
    main
    master
    分支
  • Git配置(用户名和邮箱)已预先设置,请勿修改
  • 你当前可能处于以
    openhands-workspace
    开头的分支。在推送前请创建一个命名更合理的新分支
  • 若尚未创建拉取请求,请使用
    create_pr
    工具创建
  • 创建好自己的分支或拉取请求后,持续对其进行更新。除非用户明确要求,否则不要创建新的分支或拉取请求。必要时更新PR的标题和描述,但不要修改分支名称
  • 除非用户另有要求,否则将主分支作为基础分支
  • 创建或更新拉取请求后,向用户发送一条包含该拉取请求链接的简短消息
  • 除非用户明确指示,否则不要将拉取请求标记为可评审状态
  • 请用尽可能少的步骤完成上述操作。例如,你可以通过运行以下bash命令一步完成推送更改:
bash
git remote -v && git branch # 查看当前组织、仓库和分支
git checkout -b create-widget && git add . && git commit -m "Create widget" && git push -u origin create-widget

Handling Review Comments

处理评审评论

  • Critically evaluate each review comment before acting on it. Not all feedback is worth implementing:
    • Does it fix a real bug or improve clarity significantly?
    • Does it align with the project's engineering principles (simplicity, maintainability)?
    • Is the suggested change proportional to the benefit, or does it add unnecessary complexity?
  • It's acceptable to respectfully decline suggestions that add verbosity without clear benefit, over-engineer for hypothetical edge cases, or contradict the project's pragmatic approach.
  • After addressing (or deciding not to address) inline review comments, mark the corresponding review threads as resolved.
  • Before resolving a thread, leave a reply comment that either explains the reason for dismissing the feedback or references the specific commit (e.g., commit SHA) that addressed the issue.
  • Prefer resolving threads only once fixes are pushed or a clear decision is documented.
  • Use the GitHub GraphQL API to reply to and resolve review threads (see below).
  • After making changes to a PR, verify the title and description still match the content. Update them if the scope, features, or intent changed.
  • 在执行评审评论的建议前,请先审慎评估每条评论。并非所有反馈都值得采纳:
    • 该建议是否能修复真实的bug或显著提升代码清晰度?
    • 该建议是否符合项目的工程原则(简洁性、可维护性)?
    • 建议的变更带来的收益是否与成本成正比,还是会增加不必要的复杂度?
  • 对于那些无明显收益却增加冗余、为假设性边缘情况过度设计,或与项目务实理念相悖的建议,你可以礼貌地拒绝。
  • 在处理(或决定不处理)行内评审评论后,请将对应的评审线程标记为已解决。
  • 在标记线程为已解决前,请留下回复说明拒绝该反馈的原因,或引用解决问题的具体提交(如提交SHA值)。
  • 仅在修复已推送或明确决策已记录后再标记线程为已解决。
  • 使用GitHub GraphQL API来回复和解决评审线程(详见下文)。
  • 在对PR进行更改后,请验证标题和描述是否仍与内容匹配。若范围、功能或意图发生变化,请更新标题和描述。

Resolving Review Threads via GraphQL

通过GraphQL解决评审线程

To resolve existing review threads programmatically:
  1. Get the thread IDs (replace
    <OWNER>
    ,
    <REPO>
    ,
    <PR_NUMBER>
    ):
bash
gh api graphql -f query='
{
  repository(owner: "<OWNER>", name: "<REPO>") {
    pullRequest(number: <PR_NUMBER>) {
      reviewThreads(first: 20) {
        nodes {
          id
          isResolved
          comments(first: 1) {
            nodes { body }
          }
        }
      }
    }
  }
}'
  1. Reply to the thread explaining how the feedback was addressed:
bash
gh api graphql -f query='
mutation {
  addPullRequestReviewThreadReply(input: {
    pullRequestReviewThreadId: "<THREAD_ID>"
    body: "Fixed in <COMMIT_SHA>"
  }) {
    comment { id }
  }
}'
  1. Resolve the thread:
bash
gh api graphql -f query='
mutation {
  resolveReviewThread(input: {threadId: "<THREAD_ID>"}) {
    thread { isResolved }
  }
}'
  1. Get the failed workflow run ID and rerun it:
bash
undefined
要以编程方式解决现有的评审线程:
  1. 获取线程ID(替换
    <OWNER>
    <REPO>
    <PR_NUMBER>
    ):
bash
gh api graphql -f query='
{
  repository(owner: "<OWNER>", name: "<REPO>") {
    pullRequest(number: <PR_NUMBER>) {
      reviewThreads(first: 20) {
        nodes {
          id
          isResolved
          comments(first: 1) {
            nodes { body }
          }
        }
      }
    }
  }
}'
  1. 回复线程说明反馈问题的处理方式:
bash
gh api graphql -f query='
mutation {
  addPullRequestReviewThreadReply(input: {
    pullRequestReviewThreadId: "<THREAD_ID>"
    body: "Fixed in <COMMIT_SHA>"
  }) {
    comment { id }
  }
}'
  1. 解决线程:
bash
gh api graphql -f query='
mutation {
  resolveReviewThread(input: {threadId: "<THREAD_ID>"}) {
    thread { isResolved }
  }
}'
  1. 获取失败的工作流运行ID并重新运行:
bash
undefined

Find the run ID from the failed check URL, or use:

从失败的检查URL中找到运行ID,或使用以下命令:

gh run list --repo <OWNER>/<REPO> --branch <BRANCH> --limit 5
gh run list --repo <OWNER>/<REPO> --branch <BRANCH> --limit 5

Rerun failed jobs

重新运行失败的作业

gh run rerun <RUN_ID> --repo <OWNER>/<REPO> --failed
undefined
gh run rerun <RUN_ID> --repo <OWNER>/<REPO> --failed
undefined