Skip to content
Snippets Groups Projects
Commit b26841b7 authored by Ian Cordasco's avatar Ian Cordasco
Browse files

Merge pull request #337 from sigmavirus24/stable/0.9

Merge latest 0.9 into master
parents ebdcbbf2 6e97462a
No related branches found
No related tags found
No related merge requests found
Showing with 214 additions and 131 deletions
language: python
python:
- 2.6
- 2.7
- 3.2
- 3.3
- 3.4
- pypy
# command to run tests, e.g. python setup.py test
before_script:
- pip install -r dev-requirements.txt
- pip install tox
- pip install -U requests"$REQUESTS_VERSION"
 
# test script
script: make travis
script: tox -e ${TOX_ENV}
notifications:
on_success: change
on_failure: always
on_success: change
on_failure: always
 
env:
global:
- TRAVIS_GH3="True"
matrix:
- REQUESTS_VERSION="==2.0.1"
- REQUESTS_VERSION="" # Latest
- TOX_ENV=py26 REQUESTS_VERSION="==2.0.1"
- TOX_ENV=py27 REQUESTS_VERSION="==2.0.1"
- TOX_ENV=py32 REQUESTS_VERSION="==2.0.1"
- TOX_ENV=py33 REQUESTS_VERSION="==2.0.1"
- TOX_ENV=py34 REQUESTS_VERSION="==2.0.1"
- TOX_ENV=pypy REQUESTS_VERSION="==2.0.1"
- TOX_ENV=py26 REQUESTS_VERSION=""
- TOX_ENV=py27 REQUESTS_VERSION=""
- TOX_ENV=py32 REQUESTS_VERSION=""
- TOX_ENV=py33 REQUESTS_VERSION=""
- TOX_ENV=py34 REQUESTS_VERSION=""
- TOX_ENV=pypy REQUESTS_VERSION=""
- TOX_ENV=py27-flake8
- TOX_ENV=py34-flake8
matrix:
allow_failures:
- env: TOX_ENV=py27-flake8
- env: TOX_ENV=py34-flake8
Loading
Loading
@@ -66,3 +66,17 @@ Contributors
- David Moss (@damoss007)
 
- John Barbuto (@jbarbuto)
- Nikolay Bryskin (@nikicat)
- Tomi Äijö (@tomiaijo)
- jnothman (@jnothman)
- Cameron Davidson-Pilon (@CamDavidsonPilon)
- Alex Couper (@alexcouper)
- Marc Abramowitz (@msabramo)
- Adrian Moisey (@adrianmoisey)
History/Changelog
-----------------
 
0.9.3: 2014-11-04
~~~~~~~~~~~~~~~~~
- Backport of ``PullRequest#create_review_comment`` by Adrian Moisey
- Backport of ``PullRequest#review_comments`` by Adrian Moisey
- Backport of a fix that allows authenticated users to download Release
Assets. Original bug reported by Eugene Fidelin in issue #288.
- Documentation typo fix by Marc Abramowitz
0.9.2: 2014-10-05
~~~~~~~~~~~~~~~~~
- Updates for `new team management`_ API changes
- Add ``Team#invite``, ``Team#membership_for``, and
``Team#revoke_membership``
- Deprecate ``Team#add_member``, ``Team#remove_member``, and
``Organization#add_member``.
- Update payload handler for ``TeamAddEvent``.
.. _new team management:
https://developer.github.com/changes/2014-09-23-one-more-week-before-the-add-team-member-api-breaking-change/
0.9.1: 2014-08-10
~~~~~~~~~~~~~~~~~
 
Loading
Loading
Loading
Loading
@@ -14,11 +14,11 @@ __title__ = 'github3'
__author__ = 'Ian Cordasco'
__license__ = 'Modified BSD'
__copyright__ = 'Copyright 2012-2014 Ian Cordasco'
__version__ = '0.9.1'
__version__ = '0.9.3'
__version_info__ = tuple(int(i) for i in __version__.split('.'))
 
from github3.api import *
from github3.github import GitHub, GitHubEnterprise, GitHubStatus
from github3.models import GitHubError
from .api import *
from .github import GitHub, GitHubEnterprise, GitHubStatus
from .models import GitHubError
 
# flake8: noqa
Loading
Loading
@@ -8,8 +8,8 @@ This module contains the Authorization object.
"""
from __future__ import unicode_literals
 
from github3.decorators import requires_basic_auth
from github3.models import GitHubCore
from .decorators import requires_basic_auth
from .models import GitHubCore
 
 
class Authorization(GitHubCore):
Loading
Loading
Loading
Loading
@@ -37,7 +37,7 @@ def requires_auth(func):
if auth:
return func(self, *args, **kwargs)
else:
from github3.models import GitHubError
from .models import GitHubError
# Mock a 401 response
r = generate_fake_error_response(
'{"message": "Requires authentication"}'
Loading
Loading
@@ -58,7 +58,7 @@ def requires_basic_auth(func):
if hasattr(self, '_session') and self._session.auth:
return func(self, *args, **kwargs)
else:
from github3.models import GitHubError
from .models import GitHubError
# Mock a 401 response
r = generate_fake_error_response(
'{"message": "Requires username/password authentication"}'
Loading
Loading
@@ -80,7 +80,7 @@ def requires_app_credentials(func):
if client_id and client_secret:
return func(self, *args, **kwargs)
else:
from github3.models import GitHubError
from .models import GitHubError
# Mock a 401 response
r = generate_fake_error_response(
'{"message": "Requires username/password authentication"}'
Loading
Loading
Loading
Loading
@@ -8,10 +8,10 @@ This module contains the class(es) related to Events
"""
from __future__ import unicode_literals
 
from github3.models import GitHubObject
from .models import GitHubCore
 
 
class Event(GitHubObject):
class Event(GitHubCore):
 
"""The :class:`Event <Event>` object. It structures and handles the data
returned by via the `Events <http://developer.github.com/v3/events>`_
Loading
Loading
@@ -29,10 +29,10 @@ class Event(GitHubObject):
 
"""
 
def __init__(self, event):
super(Event, self).__init__(event)
from github3.users import User
from github3.orgs import Organization
def __init__(self, event, session=None):
super(Event, self).__init__(event, session)
from .users import User
from .orgs import Organization
#: :class:`User <github3.users.User>` object representing the actor.
self.actor = User(event.get('actor')) if event.get('actor') else None
#: datetime object representing when the event was created.
Loading
Loading
@@ -48,7 +48,7 @@ class Event(GitHubObject):
handler = _payload_handlers.get(self.type, identity)
#: Dictionary with the payload. Payload structure is defined by type_.
# _type: http://developer.github.com/v3/events/types
self.payload = handler(event.get('payload'))
self.payload = handler(event.get('payload'), self)
#: Return ``tuple(owner, repository_name)``
self.repo = event.get('repo')
if self.repo is not None:
Loading
Loading
@@ -74,94 +74,102 @@ class Event(GitHubObject):
return self.public
 
 
def _commitcomment(payload):
from github3.repos.comment import RepoComment
def _commitcomment(payload, session):
from .repos.comment import RepoComment
if payload.get('comment'):
payload['comment'] = RepoComment(payload['comment'], None)
payload['comment'] = RepoComment(payload['comment'], session)
return payload
 
 
def _follow(payload):
from github3.users import User
def _follow(payload, session):
from .users import User
if payload.get('target'):
payload['target'] = User(payload['target'], None)
payload['target'] = User(payload['target'], session)
return payload
 
 
def _forkev(payload):
from github3.repos import Repository
def _forkev(payload, session):
from .repos import Repository
if payload.get('forkee'):
payload['forkee'] = Repository(payload['forkee'], None)
payload['forkee'] = Repository(payload['forkee'], session)
return payload
 
 
def _gist(payload):
from github3.gists import Gist
def _gist(payload, session):
from .gists import Gist
if payload.get('gist'):
payload['gist'] = Gist(payload['gist'], None)
payload['gist'] = Gist(payload['gist'], session)
return payload
 
 
def _issuecomm(payload):
from github3.issues import Issue
from github3.issues.comment import IssueComment
def _issuecomm(payload, session):
from .issues import Issue
from .issues.comment import IssueComment
if payload.get('issue'):
payload['issue'] = Issue(payload['issue'], None)
payload['issue'] = Issue(payload['issue'], session)
if payload.get('comment'):
payload['comment'] = IssueComment(payload['comment'], None)
payload['comment'] = IssueComment(payload['comment'], session)
return payload
 
 
def _issueevent(payload):
from github3.issues import Issue
def _issueevent(payload, session):
from .issues import Issue
if payload.get('issue'):
payload['issue'] = Issue(payload['issue'], None)
payload['issue'] = Issue(payload['issue'], session)
return payload
 
 
def _member(payload):
from github3.users import User
def _member(payload, session):
from .users import User
if payload.get('member'):
payload['member'] = User(payload['member'], None)
payload['member'] = User(payload['member'], session)
return payload
 
 
def _pullreqev(payload):
from github3.pulls import PullRequest
def _pullreqev(payload, session):
from .pulls import PullRequest
if payload.get('pull_request'):
payload['pull_request'] = PullRequest(payload['pull_request'], None)
payload['pull_request'] = PullRequest(payload['pull_request'],
session)
return payload
 
 
def _pullreqcomm(payload):
from github3.pulls import ReviewComment
if payload.get('comment'):
payload['comment'] = ReviewComment(payload['comment'], None)
def _pullreqcomm(payload, session):
from .pulls import PullRequest, ReviewComment
# Transform the Pull Request attribute
pull = payload.get('pull_request')
if pull:
payload['pull_request'] = PullRequest(pull, session)
# Transform the Comment attribute
comment = payload.get('comment')
if comment:
payload['comment'] = ReviewComment(comment, session)
return payload
 
 
def _release(payload):
from github3.repos.release import Release
def _release(payload, session):
from .repos.release import Release
release = payload.get('release')
if release:
payload['release'] = Release(release)
payload['release'] = Release(release, session)
return payload
 
 
def _team(payload):
from github3.orgs import Team
from github3.repos import Repository
from github3.users import User
def _team(payload, session):
from .orgs import Team
from .repos import Repository
from .users import User
if payload.get('team'):
payload['team'] = Team(payload['team'], None)
payload['team'] = Team(payload['team'], session)
if payload.get('repo'):
payload['repo'] = Repository(payload['repo'], None)
if payload.get('user'):
payload['user'] = User(payload['user'], None)
payload['repo'] = Repository(payload['repo'], session)
if payload.get('sender'):
payload['sender'] = User(payload['sender'], session)
return payload
 
 
def identity(x):
def identity(x, session):
return x
 
 
Loading
Loading
@@ -177,7 +185,7 @@ _payload_handlers = {
'IssueCommentEvent': _issuecomm,
'IssuesEvent': _issueevent,
'MemberEvent': _member,
'PublicEvent': lambda x: '',
'PublicEvent': identity,
'PullRequestEvent': _pullreqev,
'PullRequestReviewCommentEvent': _pullreqcomm,
'PushEvent': identity,
Loading
Loading
Loading
Loading
@@ -8,8 +8,8 @@ Module containing the logic for a GistComment
"""
from __future__ import unicode_literals
 
from github3.models import BaseComment
from github3.users import User
from ..models import BaseComment
from ..users import User
 
 
class GistComment(BaseComment):
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ Module containing the logic for the GistFile object.
"""
from __future__ import unicode_literals
 
from github3.models import GitHubObject
from ..models import GitHubObject
 
 
class GistFile(GitHubObject):
Loading
Loading
Loading
Loading
@@ -9,12 +9,12 @@ This module contains the Gist class alone for simplicity.
from __future__ import unicode_literals
 
from json import dumps
from github3.models import GitHubCore
from github3.decorators import requires_auth
from github3.gists.comment import GistComment
from github3.gists.file import GistFile
from github3.gists.history import GistHistory
from github3.users import User
from ..models import GitHubCore
from ..decorators import requires_auth
from .comment import GistComment
from .file import GistFile
from .history import GistHistory
from ..users import User
 
 
class Gist(GitHubCore):
Loading
Loading
Loading
Loading
@@ -8,8 +8,8 @@ Module containing the logic for the GistHistory object.
"""
from __future__ import unicode_literals
 
from github3.models import GitHubCore
from github3.users import User
from ..models import GitHubCore
from ..users import User
 
 
class GistHistory(GitHubCore):
Loading
Loading
@@ -63,6 +63,6 @@ class GistHistory(GitHubCore):
:returns: :class:`Gist <github3.gists.gist.Gist>`
 
"""
from github3.gists.gist import Gist
from .gist import Gist
json = self._json(self._get(self._api), 200)
return Gist(json, self)
Loading
Loading
@@ -11,9 +11,9 @@ from __future__ import unicode_literals
 
from json import dumps
from base64 import b64decode
from github3.models import GitHubObject, GitHubCore, BaseCommit
from github3.users import User
from github3.decorators import requires_auth
from .models import GitHubObject, GitHubCore, BaseCommit
from .users import User
from .decorators import requires_auth
 
 
class Blob(GitHubObject):
Loading
Loading
Loading
Loading
@@ -8,20 +8,20 @@ This module contains the main GitHub session object.
"""
from __future__ import unicode_literals
 
from github3.auths import Authorization
from github3.decorators import (requires_auth, requires_basic_auth,
requires_app_credentials)
from github3.events import Event
from github3.gists import Gist
from github3.issues import Issue, issue_params
from github3.models import GitHubCore
from github3.orgs import Organization, Team
from github3.repos import Repository
from github3.search import (CodeSearchResult, IssueSearchResult,
RepositorySearchResult, UserSearchResult)
from github3.structs import SearchIterator
from github3.users import User, Key
from github3.notifications import Thread
from .auths import Authorization
from .decorators import (requires_auth, requires_basic_auth,
requires_app_credentials)
from .events import Event
from .gists import Gist
from .issues import Issue, issue_params
from .models import GitHubCore
from .orgs import Membership, Organization, Team
from .repos import Repository
from .search import (CodeSearchResult, IssueSearchResult,
RepositorySearchResult, UserSearchResult)
from .structs import SearchIterator
from .users import User, Key
from .notifications import Thread
from uritemplate import URITemplate
 
 
Loading
Loading
@@ -931,6 +931,14 @@ class GitHub(GitHubCore):
return req.content
return '' # (No coverage)
 
@requires_auth
def membership_in(self, organization):
"""Retrieve the user's membership in the specified organization."""
url = self._build_url('user', 'memberships', 'orgs',
str(organization))
json = self._json(self._get(url), 200)
return Membership(json, self)
def meta(self):
"""Returns a dictionary with arrays of addresses in CIDR format
specifying theaddresses that the incoming service hooks will originate
Loading
Loading
@@ -962,6 +970,22 @@ class GitHub(GitHubCore):
json = self._json(self._get(url), 200)
return Organization(json, self) if json else None
 
@requires_auth
def organization_memberships(self, state=None, number=-1, etag=None):
"""List organizations of which the user is a current or pending member.
:param str state: (option), state of the membership, i.e., active,
pending
:returns: iterator of :class:`Membership <github3.orgs.Membership>`
"""
params = None
url = self._build_url('user', 'memberships', 'orgs')
if state is not None and state.lower() in ('active', 'pending'):
params = {'state': state.lower()}
return self._iter(int(number), url, Membership,
params=params,
etag=etag)
@requires_auth
def pubsubhubbub(self, mode, topic, callback, secret=''):
"""Create/update a pubsubhubbub hook.
Loading
Loading
@@ -976,7 +1000,7 @@ class GitHub(GitHubCore):
:returns: bool
"""
from re import match
m = match('https://[\w\d\-\.\:]+/\w+/[\w\._-]+/events/\w+', topic)
m = match('https?://[\w\d\-\.\:]+/\w+/[\w\._-]+/events/\w+', topic)
status = False
if mode and topic and callback and m:
data = [('hub.mode', mode), ('hub.topic', topic),
Loading
Loading
@@ -1454,13 +1478,13 @@ class GitHub(GitHubCore):
class GitHubEnterprise(GitHub):
"""For GitHub Enterprise users, this object will act as the public API to
your instance. You must provide the URL to your instance upon
initializaiton and can provide the rest of the login details just like in
initialization and can provide the rest of the login details just like in
the :class:`GitHub <GitHub>` object.
 
There is no need to provide the end of the url (e.g., /api/v3/), that will
be taken care of by us.
If you have a self signed SSL for your local github enterprise you can
If you have a self signed SSL for your local github enterprise you can
override the validation by passing `verify=False`.
"""
def __init__(self, url, login='', password='', token='', verify=True):
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ This module contains the classes related to issues.
See also: http://developer.github.com/v3/issues/
"""
 
from github3.utils import timestamp_parameter
from ..utils import timestamp_parameter
from .issue import Issue
 
__all__ = [Issue]
Loading
Loading
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
 
from github3.models import BaseComment
from github3.users import User
from ..models import BaseComment
from ..users import User
 
 
class IssueComment(BaseComment):
Loading
Loading
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
 
from github3.models import GitHubCore
from github3.users import User
from ..models import GitHubCore
from ..users import User
 
 
class IssueEvent(GitHubCore):
Loading
Loading
@@ -36,7 +36,7 @@ class IssueEvent(GitHubCore):
#: :class:`Issue <github3.issues.Issue>` where this comment was made.
self.issue = event.get('issue')
if self.issue:
from github3.issues import Issue
from .issue import Issue
self.issue = Issue(self.issue, self)
 
#: :class:`User <github3.users.User>` who caused this event.
Loading
Loading
Loading
Loading
@@ -3,13 +3,13 @@ from __future__ import unicode_literals
 
from re import match
from json import dumps
from github3.decorators import requires_auth
from github3.issues.comment import IssueComment
from github3.issues.event import IssueEvent
from github3.issues.label import Label
from github3.issues.milestone import Milestone
from github3.models import GitHubCore
from github3.users import User
from ..decorators import requires_auth
from .comment import IssueComment
from .event import IssueEvent
from .label import Label
from .milestone import Milestone
from ..models import GitHubCore
from ..users import User
from uritemplate import URITemplate
 
 
Loading
Loading
@@ -77,7 +77,7 @@ class Issue(GitHubCore):
self.number = issue.get('number')
#: Dictionary URLs for the pull request (if they exist)
self.pull_request = issue.get('pull_request')
m = match('https://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)/\d+',
m = match('https?://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)/\d+',
self.html_url)
#: Returns ('owner', 'repository') this issue was filed on.
self.repository = m.groups()
Loading
Loading
Loading
Loading
@@ -2,8 +2,8 @@
from __future__ import unicode_literals
 
from json import dumps
from github3.decorators import requires_auth
from github3.models import GitHubCore
from ..decorators import requires_auth
from ..models import GitHubCore
 
 
class Label(GitHubCore):
Loading
Loading
Loading
Loading
@@ -2,10 +2,10 @@
from __future__ import unicode_literals
 
from json import dumps
from github3.decorators import requires_auth
from github3.issues.label import Label
from github3.models import GitHubCore
from github3.users import User
from ..decorators import requires_auth
from .label import Label
from ..models import GitHubCore
from ..users import User
 
 
class Milestone(GitHubCore):
Loading
Loading
Loading
Loading
@@ -10,9 +10,9 @@ from __future__ import unicode_literals
 
from json import dumps
from requests.compat import urlparse, is_py2
from github3.decorators import requires_auth
from github3.session import GitHubSession
from github3.utils import UTC
from .decorators import requires_auth
from .session import GitHubSession
from .utils import UTC
from datetime import datetime
from logging import getLogger
 
Loading
Loading
@@ -29,8 +29,8 @@ class GitHubObject(object):
if json is not None:
self.etag = json.pop('ETag', None)
self.last_modified = json.pop('Last-Modified', None)
self._uniq = json.get('url', None)
self._json_data = json
self._uniq = json.get('url', None)
 
def to_json(self):
"""Return the json representing this object."""
Loading
Loading
@@ -169,7 +169,7 @@ class GitHubCore(GitHubObject):
:param params dict: (optional) Parameters for the request
:param str etag: (optional), ETag from the last call
"""
from github3.structs import GitHubIterator
from .structs import GitHubIterator
return GitHubIterator(count, url, cls, self, params, etag)
 
@property
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment