Automate forking a github repository

108
March 21, 2022, at 06:00 AM

Here is a script in Python that is used to clone repositories given the github account name (source_account), the name of the source repo (source_repo), and the source branch (source_branch). Is there a way I could change this in order to Fork all public repo's from a User's account given a username?

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")
Answer 1

In your case (python program), you can use sigmavirus24/github3.py which give you access to a wrapper to GitHub CLI.

The gh repo fork command mentioned in the comments is available through their own API functions.

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)
Rent Charter Buses Company
READ ALSO
Variable inconsistency in Python?

Variable inconsistency in Python?

I've run into a strange inconsistencyThis is a simplified version of the problem:

90
How can create a nested directory?

How can create a nested directory?

What is to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried:

140
owl carousel stop showing images

owl carousel stop showing images

Add owl carousel css and js:

122
Incremental BR tag counter isn´t working, something is missing

Incremental BR tag counter isn´t working, something is missing

I have the following code, in order to add an incremental counter next to each BR tag, as a per line counter for a lyric song, but it isnĀ“t workingHelp is apreciated!

93