forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.py
More file actions
346 lines (258 loc) · 11.1 KB
/
Copy pathapi.py
File metadata and controls
346 lines (258 loc) · 11.1 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
"""
github3.api
===========
:copyright: (c) 2012 by SigmaVirus24
:license: Modified BSD, see LICENSE for more details
"""
from .github import GitHub, GitHubEnterprise # NOQA
gh = GitHub()
def authorize(login, password, scopes, note='', note_url='', client_id='',
client_secret=''):
"""Obtain an authorization token from the GitHub API for the GitHub
API.
:param str login: (required)
:param str password: (required)
:param list scopes: (required), areas you want this token to apply to,
i.e., 'gist', 'user'
:param str note: (optional), note about the authorization
:param str note_url: (optional), url for the application
:param str client_id: (optional), 20 character OAuth client key for which
to create a token
:param str client_secret: (optional), 40 character OAuth client secret for
which to create the token
:returns: :class:`Authorization <Authorization>`
"""
return gh.authorize(login, password, scopes, note, note_url)
def login(username=None, password=None, token=None):
"""Constructs and returns a GitHub session with the username and
password, or token
:param str username: login name
:param str password: password for the login
:param str token: OAuth token
:returns: :class:`GitHub <github3.github.GitHub>`
"""
g = None
if (username and password) or token:
g = GitHub()
g.login(username, password, token)
return g
def gist(id_num):
"""Get the gist identified by ``id_num``.
:param int id_num: (required), unique id of the gist
:returns: :class:`Gist <github3.gists.Gist>`
"""
return gh.gist(id_num)
def gitignore_template(language):
"""Returns the template for language.
:returns: str
"""
return gh.gitignore_template(language)
def gitignore_templates():
"""Returns the list of available templates.
:returns: list of template names
"""
return gh.gitignore_templates()
def iter_all_repos(number=-1):
"""Iterate over every repository in the order they were created.
:param int number: (optional), number of repositories to return.
Default: -1, returns all of them
:returns: generator of :class:`Repository <github3.repos.Repository>`
"""
return gh.iter_all_repos(number)
def iter_all_users(number=-1):
"""Iterate over every user in the order they signed up for GitHub.
:param int number: (optional), number of users to return. Default: -1,
returns all of them
:returns: generator of :class:`User <github3.users.User>`
"""
return gh.iter_all_users(number)
def iter_events(number=-1):
"""Iterate over public events.
:param int number: (optional), number of events to return. Default: -1
returns all available events
:returns: generator of :class:`Event <github3.events.Event>`\ s
"""
return gh.iter_events(number)
def iter_followers(username, number=-1):
"""List the followers of ``username``.
:param str username: (required), login of the person to list the followers
of
:param int number: (optional), number of followers to return, Default: -1,
return all of them
:returns: generator of :class:`User <github3.users.User>`
"""
return gh.iter_followers(username, number) if username else []
def iter_following(username, number=-1):
"""List the people ``username`` follows.
:param str username: (required), login of the user
:param int number: (optional), number of users being followed by username
to return. Default: -1, return all of them
:returns: generator of :class:`User <github3.users.User>`
"""
return gh.iter_following(username, number) if username else []
def iter_gists(username=None, number=-1):
"""Get public gists or gists for the provided username.
:param str username: (optional), if provided, get the gists for this user
instead of the authenticated user.
:param int number: (optional), number of gists to return. Default: -1,
return all of them
:returns: generator of :class:`Gist <github3.gists.Gist>`\ s
"""
return gh.iter_gists(username, number)
def iter_repo_issues(owner, repository, filter='', state='', labels='',
sort='', direction='', since='', number=-1):
"""List issues on owner/repository. Only owner and repository are
required.
:param str owner: login of the owner of the repository
:param str repository: name of the repository
:param int milestone: None, '*', or ID of milestone
:param str state: accepted values: ('open', 'closed')
api-default: 'open'
:param str assignee: '*' or login of the user
:param str mentioned: login of the user
:param str labels: comma-separated list of label names, e.g.,
'bug,ui,@high'
:param str sort: accepted values: ('created', 'updated', 'comments')
api-default: created
:param str direction: accepted values: ('asc', 'desc')
api-default: desc
:param str since: ISO 8601 formatted timestamp, e.g.,
2012-05-20T23:10:27Z
:param int number: (optional), number of issues to return.
Default: -1 returns all issues
:returns: generator of :class:`Issue <github3.issues.Issue>`\ s
"""
if owner and repository:
return gh.iter_repo_issues(owner, repository, filter, state, labels,
sort, direction, since, number)
return iter([])
def iter_orgs(username, number=-1):
"""List the organizations associated with ``username``.
:param str username: (required), login of the user
:param int number: (optional), number of orgs to return. Default: -1,
return all of the issues
"""
return gh.iter_orgs(username, number) if username else []
def iter_repos(login, type='', sort='', direction='', number=-1):
"""List public repositories for the specified ``login`` or all
repositories for the authenticated user if ``login`` is not
provided.
:param str login: (required)
:param str type: (optional), accepted values:
('all', 'owner', 'public', 'private', 'member')
API default: 'all'
:param str sort: (optional), accepted values:
('created', 'updated', 'pushed', 'full_name')
API default: 'created'
:param str direction: (optional), accepted values:
('asc', 'desc'), API default: 'asc' when using 'full_name',
'desc' otherwise
:param int number: (optional), number of repositories to return.
Default: -1 returns all repositories
:returns: generator of :class:`Repository <github3.repos.Repository>`
objects
"""
if login:
return gh.iter_repos(login, type, sort, direction, number)
return iter([])
def iter_starred(username, number=-1):
"""Iterate over repositories starred by ``username``.
:param str username: (optional), name of user whose stars you want to see
:param int number: (optional), number of repositories to return.
Default: -1 returns all repositories
:returns: generator of :class:`Repository <github3.repos.Repository>`
"""
return gh.iter_starred(username, number)
def iter_subscriptions(username, number=-1):
"""Iterate over repositories subscribed to by ``username``.
:param str username: (optional), name of user whose subscriptions you want
to see
:param int number: (optional), number of repositories to return.
Default: -1 returns all repositories
:returns: generator of :class:`Repository <github3.repos.Repository>`
"""
return gh.iter_subscriptions(username, number)
def create_gist(description, files):
"""Creates an anonymous public gist.
:param str description: (required), short description of the gist
:param dict files: (required), file names with associated
dictionaries for content, e.g.
{'spam.txt': {'content': 'File contents ...'}}
:returns: :class:`Gist <github3.gists.Gist>`
"""
return gh.create_gist(description, files) # (No coverage)
def issue(owner, repository, number):
"""Anonymously gets issue :number on :owner/:repository.
:param str owner: (required), repository owner
:param str repository: (required), repository name
:param int number: (required), issue number
:returns: :class:`Issue <github3.issues.Issue>`
"""
return gh.issue(owner, repository, number)
def markdown(text, mode='', context='', raw=False):
"""Render an arbitrary markdown document.
:param str text: (required), the text of the document to render
:param str mode: (optional), 'markdown' or 'gfm'
:param str context: (optional), only important when using mode 'gfm',
this is the repository to use as the context for the rendering
:param bool raw: (optional), renders a document like a README.md, no gfm,
no context
:returns: str -- HTML formatted text
"""
return gh.markdown(text, mode, context, raw)
def octocat():
"""Returns an easter egg from the API."""
return gh.octocat()
def organization(login):
"""See :func:`organization <github3.github.GitHub.organization>`."""
return gh.organization(login)
def pull_request(owner, repository, number):
"""Anonymously retrieve pull request :number on :owner/:repository
:param str owner: (required), repository owner
:param str repository: (required), repository name
:param int number: (required), pull request number
:returns: :class:`PullRequest <github3.pulls.PullRequest>`
"""
return gh.pull_request(owner, repository, number)
def repository(owner, repository):
"""See :func:`repository <github3.github.GitHub.repository>`."""
return gh.repository(owner, repository)
def search_issues(owner, repo, state, keyword):
"""Find issues by state and keyword.
:param str owner: (required)
:param str repo: (required)
:param str state: (required), accepted values: ('open', 'closed')
:param str keyword: (required), what to search for
:returns: list of :class:`LegacyIssue <github3.legacy.LegacyIssue>`\ s
"""
return gh.search_issues(owner, repo, state, keyword)
def search_repos(keyword, **params):
"""Search all repositories by keyword.
:param keyword: (required)
:type keyword: str
:param params: (optional), filter by language and/or start_page
:type params: dict
:returns: list of :class:`LegacyRepo <github3.legacy.LegacyRepo>`\ s
"""
return gh.search_repos(keyword, **params)
def search_users(keyword):
"""Search all users by keyword.
:param str keyword: (required)
:returns: list of :class:`LegacyUser <github3.legacy.LegacyUser>`\ s
"""
return gh.search_users(keyword)
def search_email(email):
"""Search users by email.
:param str email: (required)
:returns: :class:`LegacyUser <github3.legacy.LegacyUser>`
"""
return gh.search_email(email)
def user(login):
"""See :func:`user <github3.github.GitHub.user>`."""
return gh.user(login)
def ratelimit_remaining():
"""Get the remaining number of requests allowed."""
return gh.ratelimit_remaining
def zen():
"""Returns a quote from the Zen of GitHub. Yet another API Easter Egg"""
return gh.zen()