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.

Archive 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!

from github_rest_api import Organization, Repository, RepositoryType
org = Organization(token="", owner="legendu-net")
org
<github_rest_api.github.Organization at 0x7f977b6d4830>
repos = org.get_repositories(RepositoryType.PUBLIC)
repos_active_docker = [
    repo
    for repo in repos
    if repo["name"].startswith("docker-") and not repo["archived"]
]
repos_active_docker[0]["full_name"]
'legendu-net/docker-ubuntu_cn'
token = "ghp_xxx"
for repo in repos_active_docker:
    Repository(token=token, repo=repo["full_name"]).archive()