Move issues to discussions. #3
Replies: 4 comments
-
from github import Github
def migrate_issue_to_discussion(issue_url, access_token=None):
"""
Copies an issue and its comments to a new discussion in the same repository.
:param issue_url: URL of the issue to migrate.
:return: URL of the new discussion.
"""
# Authenticate with the GitHub API using an access token
access_token = access_token or os.environ.get('GITHUB_TOKEN', None)
assert access_token, f"Need to specify a github access_token"
g = Github(access_token)
# Get the repository and issue objects from the issue URL
repo_name = issue_url.split("/")[3:5]
repo = g.get_repo("/".join(repo_name))
issue_number = int(issue_url.split("/")[-1])
issue = repo.get_issue(issue_number)
# Create a new discussion with the same title and body as the issue
discussion = repo.create_discussion(issue.title, body=issue.body) # <--- THIS DOESN'T WORK
# Copy all comments from the issue to the new discussion
for comment in issue.get_comments():
discussion.create_comment(comment.body)
# Return the URL of the new discussion
return discussion.html_urlExcept that, I can't find any Note that "discussion" objects are mentioned in The API exists though: https://docs.github.com/en/rest/teams/discussions?apiVersion=2022-11-28#create-a-discussion |
Beta Was this translation helpful? Give feedback.
-
|
Found mentioned in the (commented out) "welcome to discussions" md: ➡️ You can convert issues to discussions either individually or bulk by labels. Looking at you, issues labeled “question” or “discussion”. Google brought me to this. It says (and I verified):
But how to convert issues in bulk? |
Beta Was this translation helpful? Give feedback.
-
|
This answer says that the functionality doesn't exist anymore (and yet). Maybe the only way is through the API (directly, not via |
Beta Was this translation helpful? Give feedback.
-
|
ChatGPT says: Yes, it is possible to convert issues to discussions in bulk on GitHub using the GitHub API. The API provides a way to automate various tasks, including converting issues to discussions. Here are the general steps to convert issues to discussions in bulk on GitHub: Create a Personal Access Token (PAT) on GitHub with the necessary permissions. You will need the "repo" scope to access repositories and the "public_repo" scope if you want to access public repositories. Use the GitHub API to retrieve a list of issues for the repository using the /repos/:owner/:repo/issues endpoint. For each issue, use the /repos/:owner/:repo/issues/:issue_number/transfer endpoint to convert the issue to a discussion. This will transfer all the comments from the issue to the discussion. Repeat step 3 for all the issues in the repository. Here is an example of how to use the GitHub API to convert issues to discussions using Python: import requests
import json
# Set the API endpoint and the access token
endpoint = "https://api.github.com"
access_token = "your_personal_access_token"
# Set the owner and repository name
owner = "your_github_username"
repo = "your_repository_name"
# Get the list of issues from the API
response = requests.get(f"{endpoint}/repos/{owner}/{repo}/issues", headers={"Authorization": f"token {access_token}"})
issues = json.loads(response.text)
# Loop through each issue and convert it to a discussion
for issue in issues:
issue_number = issue["number"]
payload = {"target": "discussions"}
response = requests.post(f"{endpoint}/repos/{owner}/{repo}/issues/{issue_number}/transfer", headers={"Authorization": f"token {access_token}"}, json=payload)
print(response.text)Note: Before running this script, make sure to replace your_personal_access_token, your_github_username, and your_repository_name with your own values. Also, keep in mind that this script will permanently transfer all the issues in the repository to discussions, so use it with caution. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Historically, I've been using issues in lieu of wikis: A place to jot down ideas, notes, design discussions, etc.
I use issues instead of wikis when, for example, I want to encourage comments, or simply because I can't use wikis (no wikis in private repos).
This won't change the private repos limitation, but as far as public ones go, it might be better to have a lot of the "issues" that we have be migrated to discussions. This is because it seems that a lot of metrics perceive open issues as open problems, where as I see it as open discussions.
Here's some code to start off with:
Beta Was this translation helpful? Give feedback.
All reactions