Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Transfer a Repository Using GitHub REST API

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import os
import subprocess
from getpass import getpass
from requests.exceptions import HTTPError
from github_rest_api import Organization, Repository, RepositoryType, User
org = Organization(token="", owner="legendu-net")
org
<github_rest_api.github.Organization at 0x7f437431c830>
repos = org.get_repositories(RepositoryType.PUBLIC)
repos_docker = [
    repo
    for repo in repos
    if repo["name"].startswith("docker-")
]
repos_docker[0]["full_name"]
'legendu-net/docker-rstudio'
env = os.environ.copy()
env["GOPASS_AGE_PASSWORD"] = getpass("Enter gopass password: ")
token = subprocess.run(
    ["gopass", "show", "-o", "github.com/token"],
    check=True,
    capture_output=True,
    text=True,
    env=env,
).stdout
for repo in repos_docker:
    Repository(token=token, repo=repo["full_name"]).transfer(new_owner="dclong")