This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pyGitHub.py
119 lines (88 loc) · 3.06 KB
/
pyGitHub.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import pycurl
import urllib
import json
GITHUB_API_URL = "https://api.github.com"
class pyGitHub(object):
"""
"""
def __init__(self, username=None, password=None):
self.username = username
self.password = password
self.data = None
def setUsername(self, user):
self.username = username
def setPassword(self, pwd):
self.password = password
def curl(self, url, args={}, custom=None):
conn = pycurl.Curl()
self.data = ""
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.WRITEFUNCTION, self.callback)
if self.username is not None:
conn.setopt(pycurl.USERNAME, self.username)
if self.password is not None:
conn.setopt(pycurl.PASSWORD, self.password)
if len(args) != 0:
data = json.dumps(args)
conn.setopt(pycurl.POSTFIELDS, data)
if custom is not None:
conn.setopt(pycurl.CUSTOMREQUEST, custom)
conn.perform()
conn.close()
def ls(self):
url = GITHUB_API_URL + "/user/repos"
self.curl(url)
list = json.loads(self.data)
for i in range(len(list)):
print list[i]['name']
print " " + list[i]['description']
print " " + list[i]['clone_url']
def mk(self, name, org=None, homepage=None, description=None,
team_id=None, private=False):
url = GITHUB_API_URL + "/user/repos"
if org is not None:
url = GITHUB_API_URL + "/orgs/" + org + "/repos"
args = {
"name": name,
"has_issues": True,
"has_wiki": True,
"has_downloads": True
}
if homepage is not None:
args["homepage"] = homepage
if description is not None:
args["description"] = description
if team_id is not None:
args["team_id"] = team_id
if private is not None:
args["private"] = private
self.curl(url, args=args)
msg = json.loads(self.data)
print msg['name'], "Created"
print " " + msg['description']
print " " + msg['clone_url']
def rm(self, owner, repo):
url = GITHUB_API_URL + "/repos/" + owner + "/" + repo
print "rm %s" % url
self.curl(url, custom="DELETE")
if self.data != "":
msg = json.loads(self.data)
print msg["message"]
else:
print "Done"
def callback(self, data):
self.data = self.data + data
if __name__ == "__main__":
GH = pyGitHub(username="gjover", password="")
# List repositories
GH.ls()
# Create Repository
# GH.mk("Test_usr", description="personal test")
GH.mk("Test_org", org="tango-controls",
homepage="http://www.tango-controls.org/",
description="Test project. " +
"All the information will be used in searches. " +
"Tags: " + "/Instrumentation/Tektronix".replace("/"," "),
)
# Delete Repo
GH.rm("tango-controls","Test_org")