|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | +from github import Github |
| 4 | + |
| 5 | + |
| 6 | +def fork(): |
| 7 | + |
| 8 | + print("To quit at any point click ctrl-c") |
| 9 | + accOrOrg = input( |
| 10 | + "Fork to your profile or an organization" |
| 11 | + "(type org for organization, acc for profile): ") |
| 12 | + while (accOrOrg != "acc" and accOrOrg != "org"): |
| 13 | + accOrOrg = input("invalid answer: acc or org: ") |
| 14 | + username = input("Your github username: ") |
| 15 | + password = input("Your github password: ") |
| 16 | + try: |
| 17 | + g = Github(username, password) |
| 18 | + user = g.get_user() |
| 19 | + repo = input( |
| 20 | + "Name of repo you want to fork (in the form owner/repo): ") |
| 21 | + if (accOrOrg == "acc"): |
| 22 | + user.create_fork(g.get_repo(repo)) |
| 23 | + else: |
| 24 | + org = input("name of your organization: ") |
| 25 | + org = g.get_organization(org) |
| 26 | + org.create_fork(g.get_repo(repo)) |
| 27 | + clone(username, repo) |
| 28 | + except Exception as e: |
| 29 | + print("ERROR: " + str(e)) |
| 30 | + print("You can try again or click ctrl-c and exit") |
| 31 | + fork() |
| 32 | + |
| 33 | + |
| 34 | +def clone(repo): |
| 35 | + |
| 36 | + location = input( |
| 37 | + "Path for cloning repo into" |
| 38 | + "(default is current directory): ") |
| 39 | + try: |
| 40 | + if len(location.strip()) != 0: |
| 41 | + arr = repo.split("/") |
| 42 | + subprocess.run( |
| 43 | + "git clone https://github.com/" + repo + ".git " + location |
| 44 | + + "\\" + arr[0] + "\\" + arr[1], shell=True, check=True) |
| 45 | + else: |
| 46 | + subprocess.run( |
| 47 | + "git clone https://github.com/" + repo + ".git", |
| 48 | + shell=True, check=True) |
| 49 | + |
| 50 | + except Exception as e: |
| 51 | + print("ERROR: " + str(e)) |
| 52 | + fnc = input( |
| 53 | + "To start from the forking type fork, to start from" |
| 54 | + "cloning type clone, to exit press ctrl-c: ").lower() |
| 55 | + if fnc == "fork": |
| 56 | + fork() |
| 57 | + elif fnc == "clone": |
| 58 | + clone(repo) |
| 59 | + else: |
| 60 | + print("Invalid Input: Exiting Now") |
| 61 | + sys.exit() |
| 62 | + |
| 63 | + |
| 64 | +if __name__ == "__main__": |
| 65 | + fork() |
0 commit comments