-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.py
48 lines (39 loc) · 1.41 KB
/
repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import requests
from pprint import pprint
import argparse
import os
#YOU HAVE TO ADD THE FOLDER DIST TO YOUR SYSTEM VARIABLES PATH
parser = argparse.ArgumentParser()
parser.add_argument("--name","-n",type=str,dest="name",required=True)
parser.add_argument("--private","-p",dest="is_private",action="store_true")
args = parser.parse_args()
print(args)
repo_name = args.name
is_private = args.is_private
api_url = "https://api.github.com"
if is_private:
payload = '{"name":"' + repo_name + '", "private": true }'
else:
payload = '{"name":"' + repo_name + '", "private": false }'
print(payload)
github_token = "YOUR-PERSONAL-TOKEN-FROM-API-OF-GITHUB"
headers = {
"Authorization": "token " + github_token,
"Accept": "application/vnd.github.v3+json"
}
try:
r = requests.post(api_url+"/user/repos", data=payload, headers=headers)
r.raise_for_status()
except requests.exceptions.RequestException as err:
raise SystemExit(err)
try:
repo_path = "/Users/57304/Documents/Repositories/"
os.chdir(repo_path)
os.system("mkdir " + repo_name)
os.chdir(repo_path + repo_name)
os.system("git init")
os.system("git remote add origin https://github.com/Ivan-Sanchez-Diaz/" + repo_name + ".git")
os.system("echo # " + repo_name + " >> README.md")
os.system("git add . && git commit -m 'initial' && git push origin master")
except FileExistsError as err:
raise SystemExit(err)