自动分叉 github 个存储库

Automate forking a github repository

这是 Python 中的一个脚本,用于克隆给定 github 帐户名 (source_account) 的存储库,源存储库的名称 (source_repo ) 和源分支 (source_branch)。有没有一种方法可以更改此设置,以便从给定用户名的用户帐户中分叉所有 public 存储库?

import git
import os
import pandas as pd
import pandasql as ps

# reading csv file of Github_account_details
df = pd.read_csv('github_account_details.csv')

source_accounts = df['source_account'].unique()  # taking all distinct account names

print("****Please select a GitHub account from which you want to clone the Repositories****")

for names in source_accounts:
    print('-->', names)
selected_account = input()  # taking input from user for selecting the particular account

# extracting all the repositories for user's selected account
selected_repo = ps.sqldf(f"select source_repo from df where source_account = '{selected_account}'")
to_clone_repos = []

# making new list with 'source_repo' header
for i in selected_repo.index:
    to_clone_repos.append(selected_repo['source_repo'][i])

total_repos_count = len(to_clone_repos)
print(f"Total repositories in {selected_account} are: {total_repos_count}\n{to_clone_repos}")
permission_to_clone = input("Give permission to Clone Y/N")

# cloning all the repos from to_clone_repos
if permission_to_clone == 'Y' or permission_to_clone == 'Yes' or permission_to_clone == 'YES' or permission_to_clone == 'yes':
    for repos in to_clone_repos:
        if not os.path.exists(selected_account):
            os.makedirs(selected_account)
        print(f"{repos} -- Cloning in Progress")
        git.Git(f'{selected_account}/').clone(f'https://github.com/{selected_account}/{repos}.git')
        print(f"{repos} -- Cloned successfully")

对于您的情况(python 程序),您可以使用 sigmavirus24/github3.py 来访问 GitHub CLI 的包装器。

评论中提到的 gh repo fork 命令可以通过它们自己的 API 函数获得。

repository = self.gh.repository("kennethreitz", "requests")
forked_repo = repository.create_fork()
assert isinstance(forked_repo, github3.repos.Repository)

org_forked_repo = repository.create_fork("github3py")
assert isinstance(org_forked_repo, github3.repos.Repository)