Repository

Looks good to me!

User Tools

Site Tools


kb:tools:github:start

Github

Changelog

  • 2025-08-28: Init

Not a tutorial. More of handy scripts.

2024-02-07 Wednesday

Migrating issues and comments into a different Github repository, using gh-issues-import.py as a base.

#!/usr/bin/env python3
"""Pretty prints issues and comments for importing into new GitHub repository.
 
GitHub has deprecated password-based authentication to write to repositories, which
means the 'gh-issues-import' script will not fully work. Adopted the issue format and
created a small script to parse the comments, for manually importing.
 
Instructions:
    1. Populate 'config.ini' as usual.
    2. Comment out gh-issues-import.py:L200 that adds the Basic Auth header
    3. On gh-issues-import.py:L373, add the following code:
 
        import pickle
        with open("backup.pkl", "wb") as f: pickle.dump(new_issues, f); raise
 
    4. Run the 'gh-issues-import.py' script with Python 3.
    5. Install 'arrow' library, i.e. 'pip3 install arrow'.
    6. Copy 'gh-issue-pprint.py' script into same directory and run.
    7. Copy and paste the generated issues and comments into new repository,
       which have been populated in a 'output' subdirectory.
 
References:
    [1]: Original script (10y ago), <https://github.com/IQAndreas/github-issues-import>
    [2]: Provenance (13y ago), <https://github.com/mkorenkov/tools>
 
Changelog:
    2024-02-07, Justin: Init
"""
import pathlib
import pickle
from pprint import pprint
 
import arrow
 
with open("backup.pkl", "rb") as f:
    issues = pickle.load(f)
 
output = pathlib.Path("output")
output.mkdir(exist_ok=True)
for i, issue in enumerate(issues, start=1):
 
    # Get relevant information
    title = issue["title"]
    body = issue["body"]
    comments = issue.get("comments", [])
 
    for j, comment in enumerate(comments, start=1):
        comment_body = comment["body"]
        comment_date = comment["updated_at"]
        comment_url = comment["html_url"]
        comment_user = comment["user"]
 
        comment_user_url = comment_user["html_url"]
        comment_user_avatar = comment_user["avatar_url"]
        comment_user_login = comment_user["login"]
 
        # Construct comment
        comment_header = \
            f'**Comment by [{comment_user_login}]({comment_user_url})**\n' \
            f'_{arrow.get(comment_date).format("dddd MMM DD, YYYY [at] HH:mm [GMT]")}_\n' \
            f'_Originally commented as {comment_url}_\n\n----\n\n' \
            f'{comment_body}\n'
 
        with open(f"{output}/issue{i}_comment{j}.txt", "w") as f:
            f.write(comment_header)
 
    with open(f"{output}/issue{i}.txt", "w") as f:
        f.write(title)
        f.write("\n")
        f.write(body)
kb/tools/github/start.txt · Last modified: 39 hours ago (28 August 2025) by justin