8000 Consistency is a hobgoblin of a small mind by sigmavirus24 · Pull Request #773 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Consistency is a hobgoblin of a small mind #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
90d737a
Update Email class for attributes and docs
sigmavirus24 Dec 28, 2017
ea9c834
Re-organize attribute documentation for *User objects
sigmavirus24 Jan 11, 2018
9722e2c
Fix-up docstrings and add GitHubException
sigmavirus24 Jan 11, 2018
8e38d15
Update github3.users.Key to access attributes
sigmavirus24 Jan 11, 2018
0ae0f25
Migrate Plan to accessing values directly
sigmavirus24 Jan 12, 2018
331f56c
Update github3.pulls to access attributes directly
sigmavirus24 Jan 16, 2018
e73bb36
Merge remote-tracking branch 'origin/develop' into consistency-is-a-h…
sigmavirus24 Jan 16, 2018
a91c04d
Fix up tests from recent pull request changes
sigmavirus24 Jan 26, 2018
c68d0b3
Fix-up projects documentation
sigmavirus24 Jan 26, 2018
e65d27b
Split out ShortTeam from Team
sigmavirus24 Feb 3, 2018
973435c
Update our notifications module to conform
sigmavirus24 Feb 11, 2018
f854318
Update licenses module to better represent differences
sigmavirus24 Feb 11, 2018
9981ea4
Fix up documentation for a passing CI build
sigmavirus24 Feb 14, 2018
f64a47e
Update events classes for attribute fetching
omgjlk Feb 14, 2018
6f733b1
Update github3.auths to remove get_attribute
omgjlk Feb 14, 2018
f7ad5a5
Update github3.git to remove get_attribute
omgjlk Feb 14, 2018
45103a5
Add py36 to python environments to test in
omgjlk Feb 15, 2018
c49af2c
Merge 'develop' into consistency-is-a-hobgoblin
sigmavirus24 Feb 17, 2018
73362a1
Merge branch 'no-get-attribute-773' of omgjlk
sigmavirus24 Feb 18, 2018
2d67ae8
Remove and ignore .DS_Store
sigmavirus24 Feb 18, 2018
112caa6
Further update github3.git for consistency
sigmavirus24 Feb 18, 2018
929c131
Bring github3.git into a consistent state
sigmavirus24 Feb 19, 2018
f2b0bdd
Update github3.git API docs
sigmavirus24 Feb 19, 2018
e8e45ea
Fix line length and docstring
sigmavirus24 Feb 19, 2018
e5d6994
Add documentation for classes in github3.events
sigmavirus24 Feb 22, 2018
5b35075
Clean up docstring violations in github3.decorators
sigmavirus24 Feb 22, 2018
d2fb594
Update the authorization class and its methods
sigmavirus24 Feb 24, 2018
0751ee8
Remove GistComment dependence on BaseComment
sigmavirus24 Feb 24, 2018
373a582
Fix-up GistFile docstring
sigmavirus24 Feb 24, 2018
b21bd44
Touch up ShortGist and Gist docstrings
sigmavirus24 Feb 24, 2018
58eef77
Clean up gists imports and GistHistory docstrings
sigmavirus24 Feb 24, 2018
86e66e0
Ensure created_at and updated_at are datetimes
sigmavirus24 Feb 25, 2018
787e9b0
Update IssueComment for consistency with project
sigmavirus24 Feb 28, 2018
fd23bb5
Update github3.issues.event to be consistent
sigmavirus24 Feb 28, 2018
ad6e03f
Further clean up github3.issues.issue and add docs
sigmavirus24 Mar 2, 2018
5659877
Update Labels for consistency
sigmavirus24 Mar 2, 2018
ab727a1
Update Milestones for consistency and improve docs
sigmavirus24 Mar 2, 2018
c74e5c0
Update search submodule for consistency with docs
sigmavirus24 Mar 2, 2018
a38a111
Update github3.repos.branch for consistency
sigmavirus24 Mar 3, 2018
0b1e5cd
Update RepoComment for consistency
sigmavirus24 Mar 3, 2018
0517bbe
Update github3.repos.commit for consistency
sigmavirus24 Mar 3, 2018
fca45b0
Update github3.repos.comparison for consistency
sigmavirus24 Mar 3, 2018
5aa47f1
Update github3.repos.contents for consistency
sigmavirus24 Mar 4, 2018
2b4594c
Update github3.repos.deployment for consistency
sigmavirus24 Mar 5, 2018
f7748b6
Finish updating github3.repos.deployment
sigmavirus24 Mar 5, 2018
232cff2
Update github3.repos.hook for consistency
sigmavirus24 Mar 6, 2018
b273037
Add dateutil to parse timestamps
sigmavirus24 Mar 7, 2018
adf165d
Update github3.repos.issue_import for consistency
sigmavirus24 Mar 10, 2018
f38845b
Update github3.repos.pages for consistency
sigmavirus24 Mar 10, 2018
f93ca04
Update github3.repos.release for consistency
sigmavirus24 Mar 10, 2018
7f32e37
Update github3.repos.stats for consistency
sigmavirus24 Mar 10, 2018
dcace1d
Update github3.repos.status for consistency
sigmavirus24 Mar 11, 2018
ad56d5a
Update github3.repos.tag for consistency
sigmavirus24 Mar 11, 2018
ac8c1b6
Update github3.search.user for consistency
sigmavirus24 Mar 11, 2018
e0ec86d
Remove final few stragglers of _get_attribute
sigmavirus24 Mar 11, 2018
10d9ac6
Remove _class_attribute and missed _strptime_attribute
sigmavirus24 Mar 11, 2018
81e6047
Clean-up github3.models and remove BaseCommit
sigmavirus24 Mar 11, 2018
5814c53
Clean-up github3.github for consistency
sigmavirus24 Mar 11, 2018
7e5a00b
Update github3.repos.repo for consistency
sigmavirus24 Mar 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff 10000 line number Diff line change
Expand Up @@ -18,3 +18,4 @@ build/
.ipynb_checkpoints
.cache/
tests/id_rsa
*.DS_Store
31 changes: 29 additions & 2 deletions LATEST_VERSION_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,38 @@
Unreleased
~~~~~~~~~~

Breaking Changes (since 1.0.0a4)
````````````````````````````````

- Remove ``Thread.comment``, ``Thread.thread``, ``Thread.urls`` attributes.

- Remove ``Thread#is_unread`` method. Use the ``Thread.unread`` attribute
instead.

- ``Subscription`` has been split into two objects: ``ThreadSubscription`` and
``RepositorySubscription`` with the same methods.

- Remove ``is_ignored`` method from our Subscription objects. Use the
``ignored`` attribute instead.

- Remove ``is_subscribed`` method from our Subscription objects. Use the
``subscribed`` attribute instead.

Features Added (since 1.0.0a4)
``````````````````````````````

- Add ``Organization#all_events``.
- Deprecate ``Organization#events`` in favor of ``Organization#public_events``.
- Fix test failtures on windows caused by unclosed file handles.

- Add ``Tag.tagger_as_User`` which attempts to return the tagger as as User.

- Add ``Repo.statuses`` and a corresponding ``repo.status.CombinedStatus`` to

Deprecations and Other Changes (since 1.0.0a4)
``````````````````````````````````````````````

- Deprecate ``Organization#events`` in favor of ``Organization#public_events``.

- Fix test failtures on windows caused by unclosed file handles.
get a combined view of commit statuses for a given ref.

1.0.0a4: 2016-02-19
Expand Down
10 changes: 7 additions & 3 deletions docs/git.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ section of the GitHub API.

- :class:`Blob <Blob>`
- :class:`Commit <Commit>`
- :class:`GitData <GitData>`
- :class:`GitObject <GitObject>`
- :class:`Hash <Hash>`
- :class:`Reference <Reference>`
Expand All @@ -27,12 +26,12 @@ Git Objects

------

.. autoclass:: Commit
.. autoclass:: ShortCommit
:inherited-members:

------

.. autoclass:: GitData
.. autoclass:: Commit
:inherited-members:

------
Expand All @@ -59,3 +58,8 @@ Git Objects

.. autoclass:: Tree
:inherited-members:

------

.. autoclass:: CommitTree
:inherited-members:
15 changes: 0 additions & 15 deletions docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,3 @@ Objects

.. autoclass:: GitHubCore
:inherited-members:

------

.. autoclass:: BaseAccount
:inherited-members:

------

.. autoclass:: BaseComment
:inherited-members:

------

.. autoclass:: BaseCommit
:inherited-members:
13 changes: 10 additions & 3 deletions docs/notifications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
Notifications
=============

This part of the documentation covers the :class:`Thread <Thread>` and
:class:`Subscription <Subscription>` objects.
This part of the documentation covers the
:class:`~github3.notifications.Thread`,
:class:`~github3.notifications.RepositorySubscription`, and
:class:`~github3.notifications.ThreadSubscription` objects.

Notification Objects
--------------------
Expand All @@ -15,5 +17,10 @@ Notification Objects

------

.. autoclass:: Subscription
.. autoclass:: RepositorySubscription
:inherited-members:

------

.. autoclass:: ThreadSubscription
:inherited-members:
172 changes: 114 additions & 58 deletions github3/auths.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,104 @@
# -*- coding: utf-8 -*-
"""
github3.auths
=============

This module contains the Authorization object.

"""
"""This module contains the Authorization object."""
from __future__ import unicode_literals

from .decorators import requires_basic_auth
from .models import GitHubCore


class Authorization(GitHubCore):
"""Representation of an OAuth Authorization.

"""The :class:`Authorization <Authorization>` object.
See also: https://developer.github.com/v3/oauth_authorizations/

Two authorization instances can be checked like so::
This object has the following attributes:

a1 == a2
a1 != a2
.. attribute:: app

And is equivalent to::
Details about the application the authorization was created for.

a1.id == a2.id
a1.id != a2.id
.. attribute:: created_at

See also: http://developer.github.com/v3/oauth/#oauth-authorizations-api
A :class:`~datetime.datetime` representing when this authorization was
created.

"""
.. attribute:: fingerprint

def _update_attributes(self, auth):
self._api = self._get_attribute(auth, 'url')
.. versionadded:: 1.0

The optional parameter that is used to allow an OAuth application to
create multiple authorizations for the same user. This will help
distinguish two authorizations for the same app.

.. attribute:: hashed_token

.. versionadded:: 1.0

This is the base64 of the SHA-256 digest of the token.

.. seealso::

`Removing Authorization Tokens`_
The blog post announcing the removal of :attr:`token`.

.. attribute:: id

The unique identifier for this authorization.

#: Details about the application (name, url)
self.app = self._get_attribute(auth, 'app', {})
.. attribute:: note_url

#: Returns the Authorization token
self.token = self._get_attribute(auth, 'token')
The URL that points to a longer description about the purpose of this
autohrization.

#: App name
self.name = self._get_attribute(self.app, 'name')
.. attribute:: note

#: URL about the note
self.note_url = self._get_attribute(auth, 'note_url')
The short note provided when this authorization was created.

#: Note about the authorization
self.note = self._get_attribute(auth, 'note')
.. attribute:: scopes

#: List of scopes this applies to
self.scopes = self._get_attribute(auth, 'scopes')
The list of scopes assigned to this token.

#: Unique id of the authorization
self.id = self._get_attribute(auth, 'id')
.. seealso::

#: datetime object representing when the authorization was created.
self.created_at = self._strptime_attribute(auth, 'created_at')
`Scopes for OAuth Applications`_
GitHub's documentation around available scopes and what they
mean

#: datetime object representing when the authorization was updated.
self.updated_at = self._strptime_attribute(auth, 'updated_at')
.. attribute:: token

If this authorization was created, this will contain the full token.
Otherwise, this attribute will be an empty string.

.. attribute:: token_last_eight

.. versionadded:: 1.0

The last eight characters of the token. This allows users to identify
a token after the initial retrieval.

.. attribute:: updated_at

A :class:`~datetime.datetime` representing when this authorization was
most recently updated.

.. _Scopes for OAuth Applications:
https://developer.github.com/apps/building-oauth-apps/scopes-for-oauth-apps/
.. _Removing Authorization Tokens:
https://developer.github.com/changes/2014-12-08-removing-authorizations-token/#what-should-you-do
"""

def _update_attributes(self, auth):
self._api = auth['url']
self.app = auth['app']
self.created_at = self._strptime(auth['created_at'])
self.fingerprint = auth['fingerprint']
self.id = auth['id']
self.note_url = auth['note_url']
self.note = auth['note']
self.scopes = auth['scopes']
self.token = auth['token']
self.token_last_eight = auth['token_last_eight']
self.updated_at = self._strptime(auth['updated_at'])

def _repr(self):
return '<Authorization [{0}]>'.format(self.name)
Expand All @@ -79,23 +119,32 @@ def _update(self, scopes_data, note, note_url):

@requires_basic_auth
def add_scopes(self, scopes, note=None, note_url=None):
"""Adds the scopes to this authorization.
"""Add 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, False otherwise
:rtype: bool
: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, False otherwise
:rtype:
bool
"""
return self._update({'add_scopes': scopes}, note, note_url)

@requires_basic_auth
def delete(self):
"""Delete this authorization."""
"""Delete this authorization.

:returns:
True if successful, False otherwise
:rtype:
bool
"""
return self._boolean(self._delete(self._api), 204, 404)

@requires_basic_auth
Expand All @@ -104,13 +153,16 @@ def remove_scopes(self, scopes, note=None, note_url=None):

.. 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 successful, False otherwise
:rtype: bool
: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 successful, False otherwise
:rtype:
bool
"""
return self._update({'rm_scopes': scopes}, note, note_url)

Expand All @@ -120,11 +172,15 @@ def replace_scopes(self, scopes, note=None, note_url=None):

.. 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
:rtype: bool
: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
:rtype:
bool
"""
return self._update({'scopes': scopes}, note, note_url)
12 changes: 5 additions & 7 deletions github3/decorators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# -*- coding: utf-8 -*-
"""
github3.decorators
==================

This module provides decorators to the rest of the library

"""
"""This module provides decorators to the rest of the library."""

from functools import wraps
from requests.models import Response
Expand All @@ -20,7 +14,10 @@


class RequestsStringIO(StringIO):
"""Shim compatibility for string IO."""

def read(s 7495 elf, n=-1, *args, **kwargs):
"""Ignore extra args and kwargs."""
# StringIO is an old-style class, so can't use super
return StringIO.read(self, n)

Expand Down Expand Up @@ -86,6 +83,7 @@ def auth_wrapper(self, *args, **kwargs):


def generate_fake_error_response(msg, status_code=401, encoding='utf-8'):
"""Generate a fake Response from requests."""
r = Response()
r.status_code = status_code
r.encoding = encoding
Expand Down
Loading
0