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> 你可以结合`curl`和`GITHUB_TOKEN`来调用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 # 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

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).
  • 在执行评审评论前,请审慎评估每条评论。并非所有反馈都值得采纳:
    • 它是否能修复真实的bug或显著提升代码清晰度?
    • 它是否符合项目的工程原则(简洁性、可维护性)?
    • 建议的变更是否与收益成正比,还是会增加不必要的复杂度?
  • 对于那些无明显收益却增加冗余代码、过度设计以应对假设性边缘情况,或与项目务实理念相悖的建议,你可以礼貌地拒绝。
  • 在处理(或决定不处理)行内评审评论后,请将对应的评审线程标记为已解决。
  • 在解决线程前,请留下回复说明拒绝反馈的原因,或引用解决问题的具体提交(如提交SHA)。
  • 建议仅在修复已推送或明确决策已记录后再解决线程。
  • 使用GitHub GraphQL API来回复和解决评审线程(详见下文)。

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:

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

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

Rerun failed jobs

Rerun failed jobs

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