GitHub Issues:如何在任务列表中引用来自不同仓库的问题

huangapple go评论86阅读模式
英文:

GitHub Issues: how to reference issues from different repos in a tasklist

问题

GitHub Issues中的任务列表允许使用格式 #ISSUE_NUMBER 自动引用同一存储库中的其他问题。此引用会自动显示问题的名称和状态。

虽然存在一种类似的格式(repo#ISSUE_NUMBER)用于不同存储库中的问题,但在任务列表中无法使用此格式。

如何为不同存储库中的问题创建类似于 #ISSUE_NUMBER 的自动引用呢?

英文:

Tasklists in GitHub Issues allow to automatically reference others issues in the same repo using the format #ISSUE_NUMBER.
This reference automatically shows the name of the Issue and it state.

While there exists a similar format (repo#ISSUE_NUMBER) for issues in a different repo, this does not work in a tasklist.

How can I create an automated reference like with #ISSUE_NUMBER bot for issues in a different repo?

答案1

得分: 0

您可以创建一个自动引用不同仓库中的问题(在任务列表中),只需将该问题的URL放入其中。
例如:

 - [x] #739
 - [ ] https://github.com/octo-org/octo-repo/issues/740
 - [ ] 在所有任务完成时增加愉悦体验 :tada:

将呈现如下:

GitHub Issues:如何在任务列表中引用来自不同仓库的问题

来源:GitHub文档

英文:

You can create an automated reference to issues in a different repo (in a tasklist) simply putting the URL to that issue.
For instance:

 - [x] #739
 - [ ] https://github.com/octo-org/octo-repo/issues/740
 - [ ] Add delight to the experience when all tasks are complete :tada:

would render like this:

GitHub Issues:如何在任务列表中引用来自不同仓库的问题

Source: GitHub Docs

答案2

得分: 0

为了在不同的GitHub存储库中自动引用问题(使用 - [ ] 语法),您需要使用GitHub的API。以下是您可以实现此功能的方式:

  1. 当用户键入 - [ ] repo#123 时,解析以提取存储库名称和问题编号。
  2. 使用GitHub API从该存储库获取问题数据。API端点将是:
    https://api.github.com/repos/{repo_name}/issues/{issue_number}
  3. 从API响应中提取问题标题。
  4. 将评论中的 - [ ] repo#123 替换为:
    - [ ] [<issue_title>]({issue_url})
    这将显示问题标题作为链接,链接到完整的问题页面。

因此,代码将如下所示:

import requests

def link_other_issue(comment, repo_name, issue_num):
  issue_url = f"https://github.com/{repo_name}/issues/{issue_num}"
  issue_resp = requests.get(f"https://api.github.com/repos/{repo_name}/issues/{issue_num}")
  issue_title = issue_resp.json()["title"]
  
  comment = comment.replace(f"{repo_name}#{issue_num}", f"[{issue_title}]({issue_url})")
  return comment

每当您在新评论中检测到 repo#123 模式时,都可以调用此函数,并将该文本替换为链接的问题标题。
这需要对GitHub API进行身份验证,可以使用OAuth令牌或GitHub应用程序。如果您有其他问题,请告诉我!

英文:

To automatically reference issues in a different GitHub repository within tasklists (using the - [ ] syntax), you'll need to use GitHub's API. Here's how you can implement this:

  1. When a user types - [ ] repo#123, parse that to extract the repo name and issue number.
  2. Use the GitHub API to fetch the issue data from that repository. The API endpoint would be:
    https://api.github.com/repos/{repo_name}/issues/{issue_number}
  3. Extract the issue title from the API response.
  4. Replace - [ ] repo#123 in the comment with:
    - [ ] [&lt;issue_title&gt;]({issue_url})
    This will show the issue title as a link, linking to the full issue page.

So the code would look like this:

py
import requests

def link_other_issue(comment, repo_name, issue_num):
  issue_url = f&quot;https://github.com/{repo_name}/issues/{issue_num}&quot;
  issue_resp = requests.get(f&quot;https://api.github.com/repos/{repo_name}/issues/{issue_num}&quot;)
  issue_title = issue_resp.json()[&quot;title&quot;]
  
  comment = comment.replace(f&quot;{repo_name}#{issue_num}&quot;, f&quot;[{issue_title}]({issue_url})&quot;)
  return comment

You would call this function whenever you detect the repo#123 pattern in a new comment, and replace that text with the linked issue title.
This requires authentication to the GitHub API, either using OAuth tokens or GitHub Apps. Let me know if you have any other questions!

huangapple
  • 本文由 发表于 2023年6月8日 21:23:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76432314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定