pr-link-issue
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLink a GitHub Issue + Linear Ticket on a PR
为PR关联GitHub Issue + Linear工单
Appends a Sentry-style block to a PR description, referencing both the GitHub issue and the Linear ticket pulled from the issue's comment.
#### Issueslinear-linkback在PR描述中添加Sentry风格的区块,同时引用GitHub issue以及从该issue的评论中提取的Linear工单。
#### Issueslinear-linkbackInputs
输入参数
- — GitHub issue URL like
<issue-url>. Issue number alone is fine if the PR is in the same repo.https://github.com/<owner>/<repo>/issues/<n> - (optional) — defaults to the open PR for the current branch.
<pr-number>
- — GitHub issue的URL,格式如
<issue-url>。如果PR与issue在同一个仓库中,仅提供issue编号即可。https://github.com/<owner>/<repo>/issues/<n> - (可选)— 默认值为当前分支对应的已打开PR的编号。
<pr-number>
Steps
操作步骤
-
Resolve the PR number — skip if user supplied one:bash
gh pr view --json number,body -q '.number'If no PR exists on the branch, stop and tell the user. -
Extract issue number + repo from the input URL, or accept a barefor current repo.
#1234 -
Fetch the Linear ticket from the issue's linear-linkback comment:bash
gh issue view <n> --repo <owner>/<repo> --json comments \ -q '.comments[] | select(.author.login=="linear-code") | .body' \ | grep -Eioe '[a-z]+-[0-9]+' | head -1If no match, fall back to asking the user for the Linear key, or omit it. -
Read the existing PR body so you can append rather than overwrite:bash
gh pr view <pr-number> --json body -q '.body' -
Construct the new body. If the body is empty, use just theblock. Otherwise, append it after a blank line. Don't duplicate — if
#### Issuesis already present, replace that section instead of adding a second one.#### IssuesFormat:markdown#### Issues * Resolves: #<n> * Resolves: <linear-key> -
Update the PR with a heredoc to preserve newlines:bash
gh pr edit <pr-number> --body "$(cat <<'EOF' <new body> EOF )" -
Confirm by echoing the resulting PR URL:bash
gh pr view <pr-number> --json url -q '.url'
-
确定PR编号 — 如果用户已提供则跳过此步骤:bash
gh pr view --json number,body -q '.number'如果当前分支没有对应的PR,请停止操作并告知用户。 -
从输入的URL中提取issue编号和仓库信息,或者接受当前仓库中的纯编号格式(如)。
#1234 -
从issue的linear-linkback评论中获取Linear工单:bash
gh issue view <n> --repo <owner>/<repo> --json comments \ -q '.comments[] | select(.author.login=="linear-code") | .body' \ | grep -Eioe '[a-z]+-[0-9]+' | head -1如果未匹配到结果,则询问用户提供Linear密钥,或者省略该信息。 -
读取PR的现有描述内容,以便进行追加而非覆盖:bash
gh pr view <pr-number> --json body -q '.body' -
构建新的PR描述内容。如果原描述为空,则仅使用区块;否则,在空行后追加该区块。注意避免重复——如果
#### Issues区块已存在,则替换该部分而非添加第二个。#### Issues格式如下:markdown#### Issues * Resolves: #<n> * Resolves: <linear-key> -
使用here-doc更新PR以保留换行符:bash
gh pr edit <pr-number> --body "$(cat <<'EOF' <new body> EOF )" -
输出PR的URL以确认操作完成:bash
gh pr view <pr-number> --json url -q '.url'
Notes
注意事项
- Linear linkback comments are posted by the GitHub user . The body contains a markdown link whose text is the Linear key, e.g.
linear-code.PY-2357 - Project keys vary per repo (for sentry-python,
PY-…for sentry-javascript, etc.) — the regexJS-…covers them.[a-z]+-[0-9]+ - Don't strip existing PR content. Always read first, append/replace second.
- If the issue doesn't have a Linear linkback yet (newly filed), proceed with just the GitHub issue reference and tell the user the Linear key is missing.
- Linear linkback评论由GitHub用户发布。评论内容包含一个markdown链接,链接文本即为Linear密钥,例如
linear-code。PY-2357 - 不同仓库的项目密钥格式不同(如sentry-python仓库为,sentry-javascript仓库为
PY-…等)——正则表达式JS-…可覆盖这些格式。[a-z]+-[0-9]+ - 不要删除PR的现有内容。务必先读取原内容,再进行追加或替换操作。
- 如果issue尚未添加Linear linkback评论(例如新创建的issue),则仅添加GitHub issue引用,并告知用户缺少Linear密钥。