Skip to content

Instantly share code, notes, and snippets.

@eschmar
Created January 12, 2025 09:39
Show Gist options
  • Save eschmar/4548aaa4494015c5ddfb3093241a0efb to your computer and use it in GitHub Desktop.
Save eschmar/4548aaa4494015c5ddfb3093241a0efb to your computer and use it in GitHub Desktop.
Backup all wiki sub-repositories for a given Github organisation.
import requests
import subprocess
import argparse
def fetch_repos_with_wikis(organization, token):
url = f"https://api.github.com/orgs/{organization}/repos"
headers = {"Authorization": f"token {token}"}
repos_with_wikis = []
page = 1
while True:
response = requests.get(url, headers=headers, params={"per_page": 100, "page": page})
if response.status_code != 200:
print(f"Error: {response.status_code}, {response.json()}")
break
repos = response.json()
if not repos:
break
for repo in repos:
if repo.get("has_wiki"):
repos_with_wikis.append(repo["full_name"])
page += 1
return repos_with_wikis
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Clone all GitHub repositories with wikis.")
parser.add_argument("organization", help="The name of the GitHub organization")
parser.add_argument("token", help="Your GitHub personal access token")
args = parser.parse_args()
organization = args.organization
token = args.token
repos_with_wikis = fetch_repos_with_wikis(organization, token)
print("Clone all wikis:")
for repo in repos_with_wikis:
subprocess.run(["git", "clone", f"git@github.com:{repo}.wiki.git", f"wikis/{repo.replace(f"{organization}/",'')}"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment