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:
- When a user types
- [ ] repo#123
, parse that to extract the repo name and issue number.
- 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}
- Extract the issue title from the API response.
- 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!