自动分叉github存储库



这里有一个Python脚本,用于克隆给定github帐户名(source_account(、源repo名称(source_repo(和源分支(source_branch(的存储库。有没有办法改变这一点,以便从给定用户名的用户帐户中分叉所有公共回购?

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)

最新更新