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
214 lines (156 loc) · 5.82 KB
/
Copy pathapi.py
File metadata and controls
214 lines (156 loc) · 5.82 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
"""
github3.api
===========
:copyright: (c) 2012 by SigmaVirus24
:license: Modified BSD, see LICENSE for more details
"""
from .github import GitHub
gh = GitHub()
def authorize(login, password, scopes, note='', note_url=''):
"""See :func:`authorize <github3.github.GitHub.authorize>`"""
return gh.authorize(login, password, scopes, note, note_url)
def login(username, password, token=None):
"""Constructs and returns a GitHub session with the username and
password, or token
:param username: login name
:type username: str
:param password: password for the login
:type password: str
:param token: (optional), OAuth token
:type token: str
:returns: :class:`GitHub <github3.github.GitHub>`
"""
g = GitHub()
g.login(username, password, token)
return g
def gist(id_num):
"""Get the gist identified by ``id_num``.
:param id_num: (required), unique id of the gist
:type id_num: int
:returns: :class:`Gist <github3.gist.Gist>`
"""
return gh.gist(id_num)
def list_gists(username=None):
"""Get public gists or gists for the provided username.
:param username: (optional), if provided, get the gists for this user
instead of the authenticated user.
:type username: str
:returns: list of :class:`Gist <github3.gist.Gist>`\ s
"""
return gh.list_gists(username)
def list_followers(username):
"""List the followers of ``username``.
:param username: (required), login of the person to list the followers of
:type username: str
"""
return gh.list_followers(username) if username else []
def list_following(username):
"""List the people ``username`` follows.
:param username: (required), login of the user
:type username: str
"""
return gh.list_following(username) if username else []
def list_issues(owner, repository, filter='', state='', labels='', sort='',
direction='', since=''):
"""See :func:`github3.github.GitHub.list_issues`"""
issues = []
if owner and repository:
issues = gh.list_issues(owner, repository, filter, state, labels,
sort, direction, since)
return issues
def list_orgs(username):
"""List the organizations associated with ``username``.
:param username: (required), login of the user
:type username: str
"""
return gh.list_orgs(username) if username else []
def list_repos(login, type='', sort='', direction=''):
"""See :func:`github3.github.GitHub.list_repos`"""
return gh.list_repos(login, type, sort, direction) if login else []
def create_gist(description, files):
"""Creates an anonymous public gist.
:param description: (required), short description of the gist
:type description: str
:param files: (required), file names with associated
dictionaries for content, e.g.
{'spam.txt': {'content': 'File contents ...'}}
:type files: dict
:returns: :class:`Gist <github3.gist.Gist>`
"""
return gh.create_gist(description, files)
def issue(owner, repository, number):
"""Anonymously gets issue :number on :owner/:repository.
:param owner: (required), repository owner
:type owner: str
:param repository: (required), repository name
:type repository: str
:param number: (required), issue number
:type number: int
:returns: :class:`Issue <github3.issue.Issue>`
"""
return gh.issue(owner, repository, number)
def list_events():
"""List all recent public events from GitHub.
:returns: list of :class:`Event <github3.event.Event>`\ s
"""
return gh.list_events()
def markdown(text, mode='', context='', raw=False):
"""Render an arbitrary markdown document.
:param text: (required), the text of the document to render
:type text: str
:param mode: (optional), 'markdown' or 'gfm'
:type mode: str
:param context: (optional), only important when using mode 'gfm',
this is the repository to use as the context for the rendering
:type context: str
:param raw: (optional), renders a document like a README.md, no gfm, no
context
:type raw: bool
:returns: str -- HTML formatted text
"""
return gh.markdown(text, mode, context, raw)
def organization(login):
"""See :func:`organization <github3.github.GitHub.organization>`."""
return gh.organization(login)
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 owner: (required)
:type owner: str
:param repo: (required)
:type repo: str
:param state: (required), accepted values: ('open', 'closed')
:type state: str
:param keyword: (required), what to search for
:type keyword: str
: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 keyword: (required)
:type keyword: str
:returns: list of :class:`LegacyUser <github3.legacy.LegacyUser>`\ s
"""
return gh.search_users(keyword)
def search_email(email):
"""Search users by email.
:param email: (required)
:type keyword: str
:returns: :class:`LegacyUser <github3.legacy.LegacyUser>`
"""
return gh.search_email(email)
def ratelimit_remaining():
"""Get the remaining number of requests allowed."""
return gh.ratelimit_remaining