Skip to content

Instantly share code, notes, and snippets.

@bchopson
Created January 24, 2025 15:58
Show Gist options
  • Save bchopson/0a5bc9068e66ceb314d91196004e6f81 to your computer and use it in GitHub Desktop.
Save bchopson/0a5bc9068e66ceb314d91196004e6f81 to your computer and use it in GitHub Desktop.
Issue copying tool
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "click",
# "pygithub",
# ]
# ///
import os
from time import sleep
import click
from github import Github
from github.Issue import Issue
from github.Repository import Repository
def create_client():
return Github(os.getenv("GITHUB_TOKEN"))
def copy_issue(issue: Issue, target: Repository):
new_issue = target.create_issue(title=issue.title, body=issue.body or "")
comments = issue.get_comments()
for comment in comments:
new_issue.create_comment(comment.body)
sleep(0.5)
new_issue.create_comment(f"Original issue: {issue.html_url}")
if issue.state == "closed":
new_issue.edit(state="closed")
sleep(0.5)
@click.command()
@click.argument("source_repo", required=True)
@click.argument("target_repo", required=True)
def copy_issues(source_repo: str, target_repo: str):
g = create_client()
source = g.get_repo(source_repo)
target = g.get_repo(target_repo)
all_issues = source.get_issues(state="all")
errors = []
for issue in all_issues:
try:
copy_issue(issue, target)
except Exception as e:
print(e)
errors.append(issue.id)
for error in errors:
print(error)
if __name__ == "__main__":
copy_issues()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment