desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Builds a new API url from scratch.'
| def build_url(self, *args, **kwargs):
| parts = [(kwargs.get('base_url') or self.base_url)]
parts.extend(args)
parts = [str(p) for p in parts]
key = tuple(parts)
__logs__.info('Building a url from %s', key)
if (key not in __url_cache__):
__logs__.info('Missed the cache building the url')
__ur... |
'Use OAuth2 for authentication.
It is suggested you install requests-oauthlib to use this.
:param str client_id: Client ID retrieved from GitHub
:param str client_secret: Client secret retrieved from GitHub'
| def oauth2_auth(self, client_id, client_secret):
| raise NotImplementedError('These features are not implemented yet')
|
'Return the client credentials.
:returns: tuple(client_id, client_secret)'
| def retrieve_client_credentials(self):
| client_id = self.params.get('client_id')
client_secret = self.params.get('client_secret')
return (client_id, client_secret)
|
'Use an application token for authentication.
:param str token: Application token retrieved from GitHub\'s
/authorizations endpoint'
| def token_auth(self, token):
| if (not token):
return
self.headers.update({'Authorization': 'token {0}'.format(token)})
self.auth = None
|
'Unset authentication temporarily as a context manager.'
| @contextmanager
def no_auth(self):
| (old_basic_auth, self.auth) = (self.auth, None)
old_token_auth = self.headers.pop('Authorization', None)
(yield)
self.auth = old_basic_auth
if old_token_auth:
self.headers['Authorization'] = old_token_auth
|
'Create a comment on this gist.
:param str body: (required), body of the comment
:returns: :class:`GistComment <github3.gists.comment.GistComment>`'
| @requires_auth
def create_comment(self, body):
| json = None
if body:
url = self._build_url(u'comments', base_url=self._api)
json = self._json(self._post(url, data={u'body': body}), 201)
return self._instance_or_null(GistComment, json)
|
'Delete this gist.
:returns: bool -- whether the deletion was successful'
| @requires_auth
def delete(self):
| return self._boolean(self._delete(self._api), 204, 404)
|
'Edit this gist.
:param str description: (optional), description of the gist
:param dict files: (optional), files that make up this gist; the
key(s) should be the file name(s) and the values should be another
(optional) dictionary with (optional) keys: \'content\' and
\'filename\' where the former is the content of the... | @requires_auth
def edit(self, description=u'', files={}):
| data = {}
json = None
if description:
data[u'description'] = description
if files:
data[u'files'] = files
if data:
json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Fork this gist.
:returns: :class:`Gist <Gist>` if successful, ``None`` otherwise'
| @requires_auth
def fork(self):
| url = self._build_url(u'forks', base_url=self._api)
json = self._json(self._post(url), 201)
return self._instance_or_null(Gist, json)
|
'Check to see if this gist is starred by the authenticated user.
:returns: bool -- True if it is starred, False otherwise'
| @requires_auth
def is_starred(self):
| url = self._build_url(u'star', base_url=self._api)
return self._boolean(self._get(url), 204, 404)
|
'Iterate over comments on this gist.
:param int number: (optional), number of comments to iterate over.
Default: -1 will iterate over all comments on the gist
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of
:class:`GistComment <github3.gists.comment.GistComment>`'
| def comments(self, number=(-1), etag=None):
| url = self._build_url(u'comments', base_url=self._api)
return self._iter(int(number), url, GistComment, etag=etag)
|
'Iterate over the commits on this gist.
These commits will be requested from the API and should be the same as
what is in ``Gist.history``.
.. versionadded:: 0.6
.. versionchanged:: 0.9
Added param ``etag``.
:param int number: (optional), number of commits to iterate over.
Default: -1 will iterate over all commits asso... | def commits(self, number=(-1), etag=None):
| url = self._build_url(u'commits', base_url=self._api)
return self._iter(int(number), url, GistHistory)
|
'Iterator over the files stored in this gist.
:returns: generator of :class`GistFile <github3.gists.file.GistFile>`'
| def files(self):
| return iter(self._files)
|
'Iterator of forks of this gist.
.. versionchanged:: 0.9
Added params ``number`` and ``etag``.
:param int number: (optional), number of forks to iterate over.
Default: -1 will iterate over all forks of this gist.
:param str etag: (optional), ETag from a previous request to this
endpoint.
:returns: generator of :class:`... | def forks(self, number=(-1), etag=None):
| url = self._build_url(u'forks', base_url=self._api)
return self._iter(int(number), url, Gist, etag=etag)
|
'Star this gist.
:returns: bool -- True if successful, False otherwise'
| @requires_auth
def star(self):
| url = self._build_url(u'star', base_url=self._api)
return self._boolean(self._put(url), 204, 404)
|
'Un-star this gist.
:returns: bool -- True if successful, False otherwise'
| @requires_auth
def unstar(self):
| url = self._build_url(u'star', base_url=self._api)
return self._boolean(self._delete(url), 204, 404)
|
'Retrieve the gist at this version.
:returns: :class:`Gist <github3.gists.gist.Gist>`'
| def get_gist(self):
| from .gist import Gist
json = self._json(self._get(self._api), 200)
return self._instance_or_null(Gist, json)
|
'Retrieve contents of file from key \'raw_url\' if there is no
\'content\' key in Gist object.'
| def content(self):
| resp = self._get(self.raw_url)
if self._boolean(resp, 200, 404):
return resp.content
return None
|
'Return the contents of the file.
:returns: :class:`Contents <github3.repos.contents.Contents>`'
| def contents(self):
| json = self._json(self._get(self.contents_url), 200)
return self._instance_or_null(Contents, json)
|
'Close this Pull Request without merging.
:returns: bool'
| @requires_auth
def close(self):
| return self.update(self.title, self.body, u'closed')
|
'Create a comment on this pull request\'s issue.
:param str body: (required), comment body
:returns: :class:`IssueComment <github3.issues.comment.IssueComment>`'
| @requires_auth
def create_comment(self, body):
| url = self.comments_url
json = None
if body:
json = self._json(self._post(url, data={u'body': body}), 201)
return self._instance_or_null(IssueComment, json)
|
'Create a review comment on this pull request.
All parameters are required by the GitHub API.
:param str body: The comment text itself
:param str commit_id: The SHA of the commit to comment on
:param str path: The relative path of the file to comment on
:param int position: The line index in the diff to comment on.
:re... | @requires_auth
def create_review_comment(self, body, commit_id, path, position):
| url = self._build_url(u'comments', base_url=self._api)
data = {u'body': body, u'commit_id': commit_id, u'path': path, u'position': int(position)}
json = self._json(self._post(url, data=data), 201)
return self._instance_or_null(ReviewComment, json)
|
'Return the diff.
:returns: bytestring representation of the diff.'
| def diff(self):
| resp = self._get(self._api, headers={u'Accept': u'application/vnd.github.diff'})
return (resp.content if self._boolean(resp, 200, 404) else '')
|
'Check to see if the pull request was merged.
:returns: bool'
| def is_merged(self):
| if self.merged:
return self.merged
url = self._build_url(u'merge', base_url=self._api)
return self._boolean(self._get(url), 204, 404)
|
'Retrieve the issue associated with this pull request.
:returns: :class:`~github3.issues.Issue`'
| def issue(self):
| json = self._json(self._get(self.issue_url), 200)
return self._instance_or_null(Issue, json)
|
'Iterate over the commits on this pull request.
:param int number: (optional), number of commits to return. Default:
-1 returns all available commits.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of
:class:`RepoCommit <github3.repos.commit.RepoCommit>`\ s'
| def commits(self, number=(-1), etag=None):
| url = self._build_url(u'commits', base_url=self._api)
return self._iter(int(number), url, RepoCommit, etag=etag)
|
'Iterate over the files associated with this pull request.
:param int number: (optional), number of files to return. Default:
-1 returns all available files.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`PullFile <PullFile>`\ s'
| def files(self, number=(-1), etag=None):
| url = self._build_url(u'files', base_url=self._api)
return self._iter(int(number), url, PullFile, etag=etag)
|
'Iterate over the issue comments on this pull request.
:param int number: (optional), number of comments to return. Default:
-1 returns all available comments.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`IssueComment <IssueComment>`\ s'
| def issue_comments(self, number=(-1), etag=None):
| comments = self.links.get(u'comments', {})
url = comments.get(u'href')
if (not url):
url = self._build_url(u'comments', base_url=self._api.replace(u'pulls', u'issues'))
return self._iter(int(number), url, IssueComment, etag=etag)
|
'Merge this pull request.
:param str commit_message: (optional), message to be used for the
merge commit
:param str sha: (optional), SHA that pull request head must match
to merge.
:param bool squash: (optional), commit a single commit to the
head branch.
:returns: bool'
| @requires_auth
def merge(self, commit_message=None, sha=None, squash=False):
| parameters = {u'squash': squash}
if sha:
parameters[u'sha'] = sha
if (commit_message is not None):
parameters[u'commit_message'] = commit_message
url = self._build_url(u'merge', base_url=self._api)
json = self._json(self._put(url, data=dumps(parameters)), 200)
if (not json):
... |
'Return the patch.
:returns: bytestring representation of the patch'
| def patch(self):
| resp = self._get(self._api, headers={u'Accept': u'application/vnd.github.patch'})
return (resp.content if self._boolean(resp, 200, 404) else '')
|
'Re-open a closed Pull Request.
:returns: bool'
| @requires_auth
def reopen(self):
| return self.update(self.title, self.body, u'open')
|
'Iterate over the review comments on this pull request.
:param int number: (optional), number of comments to return. Default:
-1 returns all available comments.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`ReviewComment <ReviewComment>`\ s'
| def review_comments(self, number=(-1), etag=None):
| url = self._build_url(u'comments', base_url=self._api)
return self._iter(int(number), url, ReviewComment, etag=etag)
|
'Iterate over the reviews associated with this pull request.
:param int number: (optional), number of reviews to return. Default:
-1 returns all available files.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`PullReview <PullReview>`\ s'
| def reviews(self, number=(-1), etag=None):
| headers = {u'Accept': u'application/vnd.github.black-cat-preview+json'}
url = self._build_url(u'reviews', base_url=self._api)
return self._iter(int(number), url, PullReview, etag=etag, headers=headers)
|
'Update this pull request.
:param str title: (optional), title of the pull
:param str body: (optional), body of the pull request
:param str state: (optional), (\'open\', \'closed\')
:returns: bool'
| @requires_auth
def update(self, title=None, body=None, state=None):
| data = {u'title': title, u'body': body, u'state': state}
json = None
self._remove_none(data)
if data:
json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Reply to this review comment with a new review comment.
:param str body: The text of the comment.
:returns: The created review comment.
:rtype: :class:`~github3.pulls.ReviewComment`'
| @requires_auth
def reply(self, body):
| url = self._build_url(u'comments', base_url=self.pull_request_url)
index = (self._api.rfind(u'/') + 1)
in_reply_to = self._api[index:]
json = self._json(self._post(url, data={u'body': body, u'in_reply_to': in_reply_to}), 201)
return self._instance_or_null(ReviewComment, json)
|
'Delete subscription for this thread.
:returns: bool'
| def delete_subscription(self):
| url = self._build_url(u'subscription', base_url=self._api)
return self._boolean(self._delete(url), 204, 404)
|
'Tells you if the thread is unread or not.'
| def is_unread(self):
| return self.unread
|
'Mark the thread as read.
:returns: bool'
| def mark(self):
| return self._boolean(self._patch(self._api), 205, 404)
|
'Set the user\'s subscription for this thread
:param bool subscribed: (required), determines if notifications should
be received from this thread.
:param bool ignored: (required), determines if notifications should be
ignored from this thread.
:returns: :class:`Subscription <Subscription>`'
| def set_subscription(self, subscribed, ignored):
| url = self._build_url(u'subscription', base_url=self._api)
sub = {u'subscribed': subscribed, u'ignored': ignored}
json = self._json(self._put(url, data=dumps(sub)), 200)
return self._instance_or_null(Subscription, json)
|
'Checks the status of the user\'s subscription to this thread.
:returns: :class:`Subscription <Subscription>`'
| def subscription(self):
| url = self._build_url(u'subscription', base_url=self._api)
json = self._json(self._get(url), 200)
return self._instance_or_null(Subscription, json)
|
'Set the user\'s subscription for this subscription
:param bool subscribed: (required), determines if notifications should
be received from this thread.
:param bool ignored: (required), determines if notifications should be
ignored from this thread.'
| def set(self, subscribed, ignored):
| sub = {u'subscribed': subscribed, u'ignored': ignored}
json = self._json(self._put(self._api, data=dumps(sub)), 200)
self._update_attributes(json)
|
'Add labels to this issue.
:param str args: (required), names of the labels you wish to add
:returns: list of :class:`Label`\ s'
| @requires_auth
def add_labels(self, *args):
| url = self._build_url(u'labels', base_url=self._api)
json = self._json(self._post(url, data=args), 200)
return ([Label(l, self) for l in json] if json else [])
|
'Assigns user ``username`` to this issue. This is a short cut for
``issue.edit``.
:param str username: username of the person to assign this issue to
:returns: bool'
| @requires_auth
def assign(self, username):
| if (not username):
return False
number = (self.milestone.number if self.milestone else None)
labels = [str(l) for l in self.original_labels]
return self.edit(self.title, self.body, username, self.state, number, labels)
|
'Close this issue.
:returns: bool'
| @requires_auth
def close(self):
| assignee = (self.assignee.login if self.assignee else u'')
number = (self.milestone.number if self.milestone else None)
labels = [str(l) for l in self.original_labels]
return self.edit(self.title, self.body, assignee, u'closed', number, labels)
|
'Get a single comment by its id.
The catch here is that id is NOT a simple number to obtain. If
you were to look at the comments on issue #15 in
sigmavirus24/Todo.txt-python, the first comment\'s id is 4150787.
:param int id_num: (required), comment id, see example above
:returns: :class:`IssueComment <github3.issues.c... | def comment(self, id_num):
| json = None
if (int(id_num) > 0):
(owner, repo) = self.repository
url = self._build_url(u'repos', owner, repo, u'issues', u'comments', str(id_num))
json = self._json(self._get(url), 200)
return self._instance_or_null(IssueComment, json)
|
'Iterate over the comments on this issue.
:param int number: (optional), number of comments to iterate over
Default: -1 returns all comments
:param str sort: accepted valuees: (\'created\', \'updated\')
api-default: created
:param str direction: accepted values: (\'asc\', \'desc\')
Ignored without the sort parameter
:p... | def comments(self, number=(-1), sort=u'', direction=u'', since=None):
| url = self._build_url(u'comments', base_url=self._api)
params = issue_comment_params(sort, direction, since)
return self._iter(int(number), url, IssueComment, params)
|
'Create a comment on this issue.
:param str body: (required), comment body
:returns: :class:`IssueComment <github3.issues.comment.IssueComment>`'
| @requires_auth
def create_comment(self, body):
| json = None
if body:
url = self._build_url(u'comments', base_url=self._api)
json = self._json(self._post(url, data={u'body': body}), 201)
return self._instance_or_null(IssueComment, json)
|
'Edit this issue.
:param str title: Title of the issue
:param str body: markdown formatted body (description) of the issue
:param str assignee: login name of user the issue should be assigned
to
:param str state: accepted values: (\'open\', \'closed\')
:param int milestone: the NUMBER (not title) of the milestone to
as... | @requires_auth
def edit(self, title=None, body=None, assignee=None, state=None, milestone=None, labels=None, assignees=None):
| json = None
data = {u'title': title, u'body': body, u'assignee': assignee, u'state': state, u'milestone': milestone, u'labels': labels, u'assignees': assignees}
self._remove_none(data)
if data:
if ((u'milestone' in data) and (data[u'milestone'] == 0)):
data[u'milestone'] = None
... |
'Iterate over events associated with this issue only.
:param int number: (optional), number of events to return. Default: -1
returns all events available.
:returns: generator of
:class:`IssueEvent <github3.issues.event.IssueEvent>`\ s'
| def events(self, number=(-1)):
| url = self._build_url(u'events', base_url=self._api)
return self._iter(int(number), url, IssueEvent)
|
'Checks if the issue is closed.
:returns: bool'
| def is_closed(self):
| if (self.closed_at or (self.state == u'closed')):
return True
return False
|
'Iterate over the labels associated with this issue.
:param int number: (optional), number of labels to return. Default: -1
returns all labels applied to this issue.
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Label <github3.issues.label.Label>`\ s'
| def labels(self, number=(-1), etag=None):
| url = self._build_url(u'labels', base_url=self._api)
return self._iter(int(number), url, Label, etag=etag)
|
'Lock an issue.
:returns: bool'
| @requires_auth
def lock(self):
| url = self._build_url(u'lock', base_url=self._api)
return self._boolean(self._put(url), 204, 404)
|
'Retrieve the pull request associated with this issue.
:returns: :class:`~github3.pulls.PullRequest`'
| def pull_request(self):
| from .. import pulls
json = None
pull_request_url = self.pull_request_urls.get(u'url')
if pull_request_url:
json = self._json(self._get(pull_request_url), 200)
return self._instance_or_null(pulls.PullRequest, json)
|
'Removes label ``name`` from this issue.
:param str name: (required), name of the label to remove
:returns: list of :class:`Label`'
| @requires_auth
def remove_label(self, name):
| url = self._build_url(u'labels', name, base_url=self._api)
json = self._json(self._delete(url), 200, 404)
labels = ([Label(label, self) for label in json] if json else [])
return labels
|
'Remove all labels from this issue.
:returns: an empty list if successful'
| @requires_auth
def remove_all_labels(self):
| return self.replace_labels([])
|
'Replace all labels on this issue with ``labels``.
:param list labels: label names
:returns: list of :class:`Label`'
| @requires_auth
def replace_labels(self, labels):
| url = self._build_url(u'labels', base_url=self._api)
json = self._json(self._put(url, data=dumps(labels)), 200)
return ([Label(l, self) for l in json] if json else [])
|
'Re-open a closed issue.
:returns: bool'
| @requires_auth
def reopen(self):
| assignee = (self.assignee.login if self.assignee else u'')
number = (self.milestone.number if self.milestone else None)
labels = [str(l) for l in self.original_labels]
return self.edit(self.title, self.body, assignee, u'open', number, labels)
|
'Unlock an issue.
:returns: bool'
| @requires_auth
def unlock(self):
| url = self._build_url(u'lock', base_url=self._api)
return self._boolean(self._delete(url), 204, 404)
|
'Delete this label.
:returns: bool'
| @requires_auth
def delete(self):
| return self._boolean(self._delete(self._api), 204, 404)
|
'Update this label.
:param str name: (required), new name of the label
:param str color: (required), color code, e.g., 626262, no leading \'#\'
:returns: bool'
| @requires_auth
def update(self, name, color):
| json = None
if (name and color):
if (color[0] == u'#'):
color = color[1:]
json = self._json(self._patch(self._api, data=dumps({u'name': name, u'color': color})), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Delete this milestone.
:returns: bool'
| @requires_auth
def delete(self):
| return self._boolean(self._delete(self._api), 204, 404)
|
'Iterate over the labels of every associated issue.
.. versionchanged:: 0.9
Add etag parameter.
:param int number: (optional), number of labels to return. Default: -1
returns all available labels.
:param str etag: (optional), ETag header from a previous response
:returns: generator of :class:`Label <github3.issues.labe... | def labels(self, number=(-1), etag=None):
| url = self._build_url(u'labels', base_url=self._api)
return self._iter(int(number), url, Label, etag=etag)
|
'Update this milestone.
All parameters are optional, but it makes no sense to omit all of them
at once.
:param str title: (optional), new title of the milestone
:param str state: (optional), (\'open\', \'closed\')
:param str description: (optional)
:param str due_on: (optional), ISO 8601 time format:
YYYY-MM-DDTHH:MM:S... | @requires_auth
def update(self, title=None, state=None, description=None, due_on=None):
| data = {u'title': title, u'state': state, u'description': description, u'due_on': due_on}
self._remove_none(data)
json = None
if data:
json = self._json(self._patch(self._api, data=dumps(data)), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Helper for add_scopes, replace_scopes, remove_scopes.'
| def _update(self, scopes_data, note, note_url):
| if (note is not None):
scopes_data[u'note'] = note
if (note_url is not None):
scopes_data[u'note_url'] = note_url
json = self._json(self._post(self._api, data=scopes_data), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Adds the scopes to this authorization.
.. versionadded:: 1.0
:param list scopes: Adds these scopes to the ones present on this
authorization
:param str note: (optional), Note about the authorization
:param str note_url: (optional), URL to link to when the user views
the authorization
:returns: True if successful, Fals... | @requires_basic_auth
def add_scopes(self, scopes, note=None, note_url=None):
| return self._update({u'add_scopes': scopes}, note, note_url)
|
'Delete this authorization.'
| @requires_basic_auth
def delete(self):
| return self._boolean(self._delete(self._api), 204, 404)
|
'Remove the scopes from this authorization.
.. versionadded:: 1.0
:param list scopes: Remove these scopes from the ones present on this
authorization
:param str note: (optional), Note about the authorization
:param str note_url: (optional), URL to link to when the user views
the authorization
:returns: True if successf... | @requires_basic_auth
def remove_scopes(self, scopes, note=None, note_url=None):
| return self._update({u'rm_scopes': scopes}, note, note_url)
|
'Replace the scopes on this authorization.
.. versionadded:: 1.0
:param list scopes: Use these scopes instead of the previous list
:param str note: (optional), Note about the authorization
:param str note_url: (optional), URL to link to when the user views
the authorization
:returns: True if successful, False otherwise... | @requires_basic_auth
def replace_scopes(self, scopes, note=None, note_url=None):
| return self._update({u'scopes': scopes}, note, note_url)
|
'Update this comment.
:param str body: (required)
:returns: bool'
| @requires_auth
def update(self, body):
| json = None
if body:
json = self._json(self._post(self._api, data={u'body': body}), 200)
if json:
self._update_attributes(json)
return True
return False
|
'Get the tarball or zipball archive for this release.
:param str format: (required), accepted values: (\'tarball\',
\'zipball\')
:param path: (optional), path where the file should be saved
to, default is the filename provided in the headers and will be
written in the current directory.
it can take a file-like object a... | def archive(self, format, path=u''):
| resp = None
if (format in (u'tarball', u'zipball')):
repo_url = self._api[:self._api.rfind(u'/releases')]
url = self._build_url(format, self.tag_name, base_url=repo_url)
resp = self._get(url, allow_redirects=True, stream=True)
if (resp and self._boolean(resp, 200, 404)):
util... |
'Retrieve the asset from this release with ``asset_id``.
:param int asset_id: ID of the Asset to retrieve
:returns: :class:`~github3.repos.release.Asset`'
| def asset(self, asset_id):
| json = None
if (int(asset_id) > 0):
i = self._api.rfind(u'/')
url = self._build_url(u'assets', str(asset_id), base_url=self._api[:i])
json = self._json(self._get(url), 200)
return self._instance_or_null(Asset, json)
|
'Iterate over the assets available for this release.
:param int number: (optional), Number of assets to return
:param str etag: (optional), last ETag header sent
:returns: generator of :class:`Asset <Asset>` objects'
| def assets(self, number=(-1), etag=None):
| url = self._build_url(u'assets', base_url=self._api)
return self._iter(number, url, Asset, etag=etag)
|
'Users with push access to the repository can delete a release.
:returns: True if successful; False if not successful'
| @requires_auth
def delete(self):
| url = self._api
return self._boolean(self._delete(url, headers=Release.CUSTOM_HEADERS), 204, 404)
|
'Users with push access to the repository can edit a release.
If the edit is successful, this object will update itself.
:param str tag_name: (optional), Name of the tag to use
:param str target_commitish: (optional), The "commitish" value that
determines where the Git tag is created from. Defaults to the
repository\'s... | @requires_auth
def edit(self, tag_name=None, target_commitish=None, name=None, body=None, draft=None, prerelease=None):
| url = self._api
data = {u'tag_name': tag_name, u'target_commitish': target_commitish, u'name': name, u'body': body, u'draft': draft, u'prerelease': prerelease}
self._remove_none(data)
r = self.session.patch(url, data=json.dumps(data), headers=Release.CUSTOM_HEADERS)
successful = self._boolean(r, 200... |
'Upload an asset to this release.
All parameters are required.
:param str content_type: The content type of the asset. Wikipedia has
a list of common media types
:param str name: The name of the file
:param asset: The file or bytes object to upload.
:param label: (optional), An alternate short description of the asset.... | @requires_auth
def upload_asset(self, content_type, name, asset, label=None):
| headers = {u'Content-Type': content_type}
params = {u'name': name, u'label': label}
self._remove_none(params)
url = self.upload_urlt.expand(params)
r = self._post(url, data=asset, json=False, headers=headers)
if (r.status_code in (201, 202)):
return Asset(r.json(), self)
raise error_... |
'Download the data for this asset.
:param path: (optional), path where the file should be saved
to, default is the filename provided in the headers and will be
written in the current directory.
it can take a file-like object as well
:type path: str, file
:returns: name of the file, if successful otherwise ``None``
:rty... | def download(self, path=u''):
| headers = {u'Accept': u'application/octet-stream'}
resp = self._get(self._api, allow_redirects=False, stream=True, headers=headers)
if (resp.status_code == 302):
headers.update({u'Content-Type': None})
with self.session.no_auth():
resp = self._get(resp.headers[u'location'], strea... |
'Delete this asset if the user has push access.
:returns: True if successful; False if not successful
:rtype: boolean'
| @requires_auth
def delete(self):
| url = self._api
return self._boolean(self._delete(url, headers=Release.CUSTOM_HEADERS), 204, 404)
|
'Edit this asset.
:param str name: (required), The file name of the asset
:param str label: (optional), An alternate description of the asset
:returns: boolean'
| def edit(self, name, label=None):
| if (not name):
return False
edit_data = {u'name': name, u'label': label}
self._remove_none(edit_data)
r = self._patch(self._api, data=json.dumps(edit_data), headers=Release.CUSTOM_HEADERS)
successful = self._boolean(r, 200, 404)
if successful:
self._update_attributes(r.json())
... |
'Add ``username`` as a collaborator to a repository.
:param username: (required), username of the user
:type username: str or :class:`User <github3.users.User>`
:returns: bool -- True if successful, False otherwise'
| @requires_auth
def add_collaborator(self, username):
| if (not username):
return False
url = self._build_url(u'collaborators', str(username), base_url=self._api)
return self._boolean(self._put(url), 204, 404)
|
'Get the tarball or zipball archive for this repo at ref.
See: http://developer.github.com/v3/repos/contents/#get-archive-link
:param str format: (required), accepted values: (\'tarball\',
\'zipball\')
:param path: (optional), path where the file should be saved
to, default is the filename provided in the headers and w... | def archive(self, format, path=u'', ref=u'master'):
| resp = None
if (format in (u'tarball', u'zipball')):
url = self._build_url(format, ref, base_url=self._api)
resp = self._get(url, allow_redirects=True, stream=True)
if (resp and self._boolean(resp, 200, 404)):
stream_response_to_file(resp, path)
return True
return False
|
'Return a single asset.
:param int id: (required), id of the asset
:returns: :class:`Asset <github3.repos.release.Asset>`'
| def asset(self, id):
| data = None
if (int(id) > 0):
url = self._build_url(u'releases', u'assets', str(id), base_url=self._api)
data = self._json(self._get(url, headers=Release.CUSTOM_HEADERS), 200)
return self._instance_or_null(Asset, data)
|
'Iterate over all assignees to which an issue may be assigned.
:param int number: (optional), number of assignees to return. Default:
-1 returns all available assignees
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`~github3.users.User`\ s'
| def assignees(self, number=(-1), etag=None):
| url = self._build_url(u'assignees', base_url=self._api)
return self._iter(int(number), url, users.ShortUser, etag=etag)
|
'Get the blob indicated by ``sha``.
:param str sha: (required), sha of the blob
:returns: :class:`Blob <github3.git.Blob>` if successful, otherwise
None'
| def blob(self, sha):
| url = self._build_url(u'git', u'blobs', sha, base_url=self._api)
json = self._json(self._get(url), 200)
return self._instance_or_null(Blob, json)
|
'Get the branch ``name`` of this repository.
:param str name: (required), branch name
:type name: str
:returns: :class:`Branch <github3.repos.branch.Branch>`'
| def branch(self, name):
| json = None
if name:
url = self._build_url(u'branches', name, base_url=self._api)
json = self._json(self._get(url, headers=Branch.PREVIEW_HEADERS), 200)
return self._instance_or_null(Branch, json)
|
'Iterate over the branches in this repository.
:param int number: (optional), number of branches to return. Default:
-1 returns all branches
:param bool protected: (optional), True lists only protected branches.
Default: False
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: gene... | def branches(self, number=(-1), protected=False, etag=None):
| url = self._build_url(u'branches', base_url=self._api)
params = ({u'protected': u'1'} if protected else None)
return self._iter(int(number), url, Branch, params, etag=etag, headers=Branch.PREVIEW_HEADERS)
|
'Iterate over the code frequency per week.
Returns a weekly aggregate of the number of additions and deletions
pushed to this repository.
:param int number: (optional), number of weeks to return. Default: -1
returns all weeks
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: gener... | def code_frequency(self, number=(-1), etag=None):
| url = self._build_url(u'stats', u'code_frequency', base_url=self._api)
return self._iter(int(number), url, list, etag=etag)
|
'Iterate over the collaborators of this repository.
:param int number: (optional), number of collaborators to return.
Default: -1 returns all comments
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`~github3.users.ShortUser`\ s'
| def collaborators(self, number=(-1), etag=None):
| url = self._build_url(u'collaborators', base_url=self._api)
return self._iter(int(number), url, users.ShortUser, etag=etag)
|
'Iterate over comments on all commits in the repository.
:param int number: (optional), number of comments to return. Default:
-1 returns all comments
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of
:class:`RepoComment <github3.repos.comment.RepoComment>`\ s'
| def comments(self, number=(-1), etag=None):
| url = self._build_url(u'comments', base_url=self._api)
return self._iter(int(number), url, RepoComment, etag=etag)
|
'Get a single (repo) commit.
See :func:`git_commit` for the Git Data Commit.
:param str sha: (required), sha of the commit
:returns: :class:`RepoCommit <github3.repos.commit.RepoCommit>` if
successful, otherwise None'
| def commit(self, sha):
| url = self._build_url(u'commits', sha, base_url=self._api)
json = self._json(self._get(url), 200)
return self._instance_or_null(RepoCommit, json)
|
'Iterate over last year of commit activity by week.
See: http://developer.github.com/v3/repos/statistics/
.. note:: All statistics methods may return a 202. On those occasions,
you will not receive any objects. You should store your
iterator and check the new ``last_status`` attribute. If it
is a 202 you should wait be... | def commit_activity(self, number=(-1), etag=None):
| url = self._build_url(u'stats', u'commit_activity', base_url=self._api)
return self._iter(int(number), url, dict, etag=etag)
|
'Get a single commit comment.
:param int comment_id: (required), id of the comment used by GitHub
:returns: :class:`RepoComment <github3.repos.comment.RepoComment>` if
successful, otherwise None'
| def commit_comment(self, comment_id):
| url = self._build_url(u'comments', str(comment_id), base_url=self._api)
json = self._json(self._get(url), 200)
return self._instance_or_null(RepoComment, json)
|
'Iterate over commits in this repository.
:param str sha: (optional), sha or branch to start listing commits
from
:param str path: (optional), commits containing this path will be
listed
:param str author: (optional), GitHub login, real name, or email to
filter commits by (using commit author)
:param int number: (optio... | def commits(self, sha=None, path=None, author=None, number=(-1), etag=None, since=None, until=None, per_page=None):
| params = {u'sha': sha, u'path': path, u'author': author, u'since': timestamp_parameter(since), u'until': timestamp_parameter(until), u'per_page': per_page}
self._remove_none(params)
url = self._build_url(u'commits', base_url=self._api)
return self._iter(int(number), url, RepoCommit, params, etag)
|
'Compare two commits.
:param str base: (required), base for the comparison
:param str head: (required), compare this against base
:returns: :class:`Comparison <github3.repos.comparison.Comparison>` if
successful, else None'
| def compare_commits(self, base, head):
| url = self._build_url(u'compare', ((base + u'...') + head), base_url=self._api)
json = self._json(self._get(url), 200)
return self._instance_or_null(Comparison, json)
|
'Iterate over the contributors list.
See also: http://developer.github.com/v3/repos/statistics/
.. note:: All statistics methods may return a 202. On those occasions,
you will not receive any objects. You should store your
iterator and check the new ``last_status`` attribute. If it
is a 202 you should wait before re-re... | def contributor_statistics(self, number=(-1), etag=None):
| url = self._build_url(u'stats', u'contributors', base_url=self._api)
return self._iter(int(number), url, ContributorStats, etag=etag)
|
'Iterate over the contributors to this repository.
:param bool anon: (optional), True lists anonymous contributors as
well
:param int number: (optional), number of contributors to return.
Default: -1 returns all contributors
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: genera... | def contributors(self, anon=False, number=(-1), etag=None):
| url = self._build_url(u'contributors', base_url=self._api)
params = {}
if anon:
params = {u'anon': u'true'}
return self._iter(int(number), url, users.ShortUser, params, etag)
|
'Create a blob with ``content``.
:param str content: (required), content of the blob
:param str encoding: (required), (\'base64\', \'utf-8\')
:returns: string of the SHA returned'
| @requires_auth
def create_blob(self, content, encoding):
| sha = u''
if (encoding in (u'base64', u'utf-8')):
url = self._build_url(u'git', u'blobs', base_url=self._api)
data = {u'content': content, u'encoding': encoding}
json = self._json(self._post(url, data=data), 201)
if json:
sha = json.get(u'sha')
return sha
|
'Create a comment on a commit.
:param str body: (required), body of the message
:param str sha: (required), commit id
:param str path: (optional), relative path of the file to comment
on
:param str position: (optional), line index in the diff to comment on
:param int line: (optional), line number of the file to comment... | @requires_auth
def create_comment(self, body, sha, path=None, position=None, line=1):
| json = None
if (body and sha and (line and (int(line) > 0))):
data = {u'body': body, u'line': line, u'path': path, u'position': position}
self._remove_none(data)
url = self._build_url(u'commits', sha, u'comments', base_url=self._api)
json = self._json(self._post(url, data=data), ... |
'Create a commit on this repository.
:param str message: (required), commit message
:param str tree: (required), SHA of the tree object this
commit points to
:param list parents: (required), SHAs of the commits that were parents
of this commit. If empty, the commit will be written as the root
commit. Even if there is ... | @requires_auth
def create_commit(self, message, tree, parents, author=None, committer=None):
| json = None
if (message and tree and isinstance(parents, list)):
url = self._build_url(u'git', u'commits', base_url=self._api)
data = {u'message': message, u'tree': tree, u'parents': parents, u'author': author, u'committer': committer}
self._remove_none(data)
json = self._json(se... |
'Create a deployment.
:param str ref: (required), The ref to deploy. This can be a branch,
tag, or sha.
:param list required_contexts: Optional array of status contexts
verified against commit status checks. To bypass checking
entirely pass an empty array. Default: []
:param str payload: Optional JSON payload with extr... | @requires_auth
def create_deployment(self, ref, required_contexts=None, payload=u'', auto_merge=False, description=u'', environment=None):
| json = None
if ref:
if (required_contexts is None):
required_contexts = []
url = self._build_url(u'deployments', base_url=self._api)
data = {u'ref': ref, u'required_contexts': required_contexts, u'payload': payload, u'auto_merge': auto_merge, u'description': description, u'en... |
'Create a file in this repository.
See also: http://developer.github.com/v3/repos/contents/#create-a-file
:param str path: (required), path of the file in the repository
:param str message: (required), commit message
:param bytes content: (required), the actual data in the file
:param str branch: (optional), branch to ... | @requires_auth
def create_file(self, path, message, content, branch=None, committer=None, author=None):
| if (content and (not isinstance(content, bytes))):
raise ValueError(u'content must be a bytes object')
json = None
if (path and message and content):
url = self._build_url(u'contents', path, base_url=self._api)
content = b64encode(content).decode(u'utf-8')
data... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.