0

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?

FedFranz
  • 529
  • 1
  • 5
  • 15

2 Answers2

0

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:

RefIssues

Source: GitHub Docs

FedFranz
  • 529
  • 1
  • 5
  • 15
0

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: - [ ] [<issue_title>]({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"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

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!

Aymendps
  • 1,346
  • 4
  • 20