8000 Merge tag '0.9.5' into debian · AndrewOrr/github3.py@6e55354 · GitHub
[go: up one dir, main page]

Skip to content < 8000 span style="width: 0%;" data-view-component="true" class="Progress-item progress-pjax-loader-bar left-0 top-0 color-bg-accent-emphasis">

Commit 6e55354

Browse files
committed
Merge tag '0.9.5' into debian
Release v0.9.5
2 parents ff65242 + c4c3fc3 commit 6e55354

File tree

13 files changed

+124
-59
lines changed

13 files changed

+124
-59
lines changed

AUTHORS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ Contributors
8080
- Marc Abramowitz (@msabramo)
8181

8282
- Adrian Moisey (@adrianmoisey)
83+
84+
- Lars Holm Nielsen (@larshankat)
85+

HISTORY.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
History/Changelog
22
-----------------
33

4+
0.9.5: 2016-02-15
5+
~~~~~~~~~~~~~~~~~
6+
7+
- Fix Validation Error stemming from ``Repository#create_status`` having
8+
poorly chosen default arguments and not removing ``None`` values from the
9+
body of the request.
10+
11+
0.9.4: 2015-04-17
12+
~~~~~~~~~~~~~~~~~
13+
14+
- In ``PullRequest#create_review_comment`` coerce the position argument to an
15+
integer instead of coercing it to a string. Reported by Paul Tagliamonte in
16+
#374.
17+
18+
- Backport support for the ``context`` parameter in
19+
``Repository#create_status``
20+
21+
- Add support for ``Repository.permissions`` attribute
22+
23+
- Backport of support for allowing ``Event``\ s to keep the same session as
24+
other objects.
25+
26+
- Skip objects that are ``None`` while iterating over them (see issues #304
27+
and #305) reported by Marc Abramowitz
28+
29+
- Fix URL regular expression for GitHub Enterprise instances by Marc
30+
Abramowitz
31+
432
0.9.3: 2014-11-04
533
~~~~~~~~~~~~~~~~~
634

github3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
__author__ = 'Ian Cordasco'
1515
__license__ = 'Modified BSD'
1616
__copyright__ = 'Copyright 2012-2014 Ian Cordasco'
17-
__version__ = '0.9.3'
17+
__version__ = '0.9.5'
1818
__version_info__ = tuple(int(i) for i in __version__.split('.'))
1919

2020
from .api import *

github3/events.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"""
99
from __future__ import unicode_literals
1010

11-
from .models import GitHubObject
11+
from .models import GitHubCore
1212

1313

14-
class Event(GitHubObject):
14+
class Event(GitHubCore):
1515

1616
"""The :class:`Event <Event>` object. It structures and handles the data
1717
returned by via the `Events <http://developer.github.com/v3/events>`_
@@ -29,8 +29,8 @@ class Event(GitHubObject):
2929
3030
"""
3131

32-
def __init__(self, event):
33-
super(Event, self).__init__(event)
32+
def __init__(self, event, session=None):
33+
super(Event, self).__init__(event, session)
3434
from .users import User
3535
from .orgs import Organization
3636
#: :class:`User <github3.users.User>` object representing the actor.
@@ -48,7 +48,7 @@ def __init__(self, event):
4848
handler = _payload_handlers.get(self.type, identity)
4949
#: Dictionary with the payload. Payload structure is defined by type_.
5050
# _type: http://developer.github.com/v3/events/types
51-
self.payload = handler(event.get('payload'))
51+
self.payload = handler(event.get('payload'), self)
5252
#: Return ``tuple(owner, repository_name)``
5353
self.repo = event.get('repo')
5454
if self.repo is not None:
@@ -74,94 +74,102 @@ def is_public(self):
7474
return self.public
7575

7676

77-
def _commitcomment(payload):
77+
def _commitcomment(payload, session):
7878
from .repos.comment import RepoComment
7979
if payload.get('comment'):
80-
payload['comment'] = RepoComment(payload['comment'], None)
80+
payload['comment'] = RepoComment(payload['comment'], session)
8181
return payload
8282

8383

84-
def _follow(payload):
84+
def _follow(payload, session):
8585
from .users import User
8686
if payload.get('target'):
87-
payload['target'] = User(payload['target'], None)
87+
payload['target'] = User(payload['target'], session)
8888
return payload
8989

9090

91-
def _forkev(payload):
91+
def _forkev(payload, session):
9292
from .repos import Repository
9393
if payload.get('forkee'):
94-
payload['forkee'] = Repository(payload['forkee'], None)
94+
payload['forkee'] = Repository(payload['forkee'], session)
9595
return payload
9696

9797

98-
def _gist(payload):
98+
def _gist(payload, session):
9999
from .gists import Gist
100100
if payload.get('gist'):
101-
payload['gist'] = Gist(payload['gist'], None)
101+
payload['gist'] = Gist(payload['gist'], session)
102102
return payload
103103

104104

105-
def _issuecomm(payload):
105+
def _issuecomm(payload, session):
106106
from .issues import Issue
107107
from .issues.comment import IssueComment
108108
if payload.get('issue'):
109-
payload['issue'] = Issue(payload['issue'], None)
109+
payload['issue'] = Issue(payload['issue'], session)
110110
if payload.get('comment'):
111-
payload['comment'] = IssueComment(payload['comment'], None)
111+
payload['comment'] = IssueComment(payload['comment'], session)
112112
return payload
113113

114114

115-
def _issueevent(payload):
115+
def _issueevent(payload, session):
116116
from .issues import Issue
117117
if payload.get('issue'):
118-
payload['issue'] = Issue(payload['issue'], None)
118+
payload['issue'] = Issue(payload['issue'], session)
119119
return payload
120120

121121

122-
def _member(payload):
122+
def _member(payload, session):
123123
from .users import User
124124
if payload.get('member'):
125-
payload['member'] = User(payload['member'], None)
125+
payload['member'] = User(payload['member'], session)
126126
return payload
127127

128128

129-
def _pullreqev(payload):
129+
def _pullreqev(payload, session):
130130
from .pulls import PullRequest
131131
if payload.get('pull_request'):
132-
payload['pull_request'] = PullRequest(payload['pull_request'], None)
132+
payload['pull_request'] = PullRequest(payload['pull_request'],
133+
session)
133134
return payload
134135

135136

136-
def _pullreqcomm(payload):
137-
from .pulls import ReviewComment
138-
if payload.get('comment'):
139-
payload['comment'] = ReviewComment(payload['comment'], None)
137+
def _pullreqcomm(payload, session):
138+
from .pulls import PullRequest, ReviewComment
139+
# Transform the Pull Request attribute
140+
pull = payload.get('pull_request')
141+
if pull:
142+
payload['pull_request'] = PullRequest(pull, session)
143+
144+
# Transform the Comment attribute
145+
comment = payload.get('comment')
146+
if comment:
147+
payload['comment'] = ReviewComment(comment, session)
140148
return payload
141149

142150

143-
def _release(payload):
151+
def _release(payload, session):
144152
from .repos.release import Release
145153
release = payload.get('release')
146154
if release:
147-
payload['release'] = Release(release)
155+
payload['release'] = Release(release, session)
148156
return payload
149157

150158

151-
def _team(payload):
159+
def _team(payload, session):
152160
from .orgs import Team
153161
from .repos import Repository
154162
from .users import User
155163
if payload.get('team'):
156-
payload['team'] = Team(payload['team'], None)
164+
payload['team'] = Team(payload['team'], session)
157165
if payload.get('repo'):
158-
payload['repo'] = Repository(payload['repo'], None)
166+
payload['repo'] = Repository(payload['repo'], session)
159167
if payload.get('sender'):
160-
payload['sender'] = User(payload['sender'], None)
168+
payload['sender'] = User(payload['sender'], session)
161169
return payload
162170

163171

164-
def identity(x):
172+
def identity(x, session):
165173
return x
166174

167175

@@ -177,7 +185,7 @@ def identity(x):
177185
'IssueCommentEvent': _issuecomm,
178186
'IssuesEvent': _issueevent,
179187
'MemberEvent': _member,
180-
'PublicEvent': lambda x: '',
188+
'PublicEvent': identity,
181189
'PullRequestEvent': _pullreqev,
182190
'PullRequestReviewCommentEvent': _pullreqcomm,
183191
'PushEvent': identity,

github3/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ def pubsubhubbub(self, mode, topic, callback, secret=''):
10001000
:returns: bool
10011001
"""
10021002
from re import match
1003-
m = match('https://[\w\d\-\.\:]+/\w+/[\w\._-]+/events/\w+', topic)
1003+
m = match('https?://[\w\d\-\.\:]+/\w+/[\w\._-]+/events/\w+', topic)
10041004
status = False
10051005
if mode and topic and callback and m:
10061006
data = [('hub.mode', mode), ('hub.topic', topic),
@@ -1478,7 +1478,7 @@ def zen(self):
14781478
class GitHubEnterprise(GitHub):
14791479
"""For GitHub Enterprise users, this object will act as the public API to
14801480
your instance. You must provide the URL to your instance upon
1481-
initializaiton and can provide the rest of the login details just like in
1481+
initialization and can provide the rest of the login details just like in
14821482
the :class:`GitHub <GitHub>` object.
14831483
14841484
There is no need to provide the end of the url (e.g., /api/v3/), that will

github3/issues/issue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, issue, session=None):
7777
self.number = issue.get('number')
7878
#: Dictionary URLs for the pull request (if they exist)
7979
self.pull_request = issue.get('pull_request')
80-
m = match('https://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)/\d+',
80+
m = match('https?://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)/\d+',
8181
self.html_url)
8282
#: Returns ('owner', 'repository') this issue was filed on.
8383
self.repository = m.groups()

github3/pulls.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __init__(self, pull, session=None):
183183
#: GitHub.com url for review comments (not a template)
184184
self.review_comments_url = pull.get('review_comments_url')
185185

186-
m = match('https://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)?/\d+',
186+
m = match('https?://[\w\d\-\.\:]+/(\S+)/(\S+)/(?:issues|pull)?/\d+',
187187
self.issue_url)
188188
#: Returns ('owner', 'repository') this issue was filed on.
189189
self.repository = m.groups()
@@ -233,7 +233,7 @@ def create_review_comment(self, body, commit_id, path, position):
233233
"""
234234
url = self._build_url('comments', base_url=self._api)
235235
data = {'body': body, 'commit_id': commit_id, 'path': path,
236-
'position': str(position)}
236+
'position': int(position)}
237237
json = self._json(self._post(url, data=data), 201)
238238
return ReviewComment(json, self) if json else None
239239

@@ -300,18 +300,18 @@ def iter_issue_comments(self, number=-1, etag=None):
300300
return self._iter(int(number), url, IssueComment, etag=etag)
301301

302302
@requires_auth
303-
def merge(self, commit_message=''):
303+
def merge(self, commit_message='', sha=None):
304304
"""Merge this pull request.
305305
306306
:param str commit_message: (optional), message to be used for the
307307
merge commit
308308
:returns: bool
309309
"""
310-
data = None
311-
if commit_message:
312-
data = dumps({'commit_message': commit_message})
310+
parameters = {'commit_message': commit_message}
311+
if sha:
312+
parameters['sha'] = sha
313313
url = self._build_url('merge', base_url=self._api)
314-
json = self._json(self._put(url, data=data), 200)
314+
json = self._json(self._put(url, data=dumps(parameters)), 200)
315315
self.merge_commit_sha = json['sha']
316316
return json['merged']
317317

github3/repos/repo.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def __init__(self, repo, session=None):
122122

123123
#: Is this repository private?
124124
self.private = repo.get('private')
125+
126+
#: Permissions for this repository
127+
self.permissions = repo.get('permissions')
128+
125129
#: ``datetime`` object representing the last time commits were pushed
126130
#: to the repository.
127131
self.pushed_at = self._strptime(repo.get('pushed_at'))
@@ -782,20 +786,26 @@ def create_release(self, tag_name, target_commitish=None, name=None,
782786
return Release(json, self)
783787

784788
@requires_auth
785-
def create_status(self, sha, state, target_url='', description=''):
789+
def create_status(self, sha, state, target_url=None, description=None,
790+
context='default'):
786791
"""Create a status object on a commit.
787792
788793
:param str sha: (required), SHA of the commit to create the status on
789794
:param str state: (required), state of the test; only the following
790795
are accepted: 'pending', 'success', 'error', 'failure'
791796
:param str target_url: (optional), URL to associate with this status.
792797
:param str description: (optional), short description of the status
798+
:param str context: (optional), A string label to differentiate this
799+
status from the status of other systems
800+
:returns: the status created if successful
801+
:rtype: :class:`~github3.repos.status.Status`
793802
"""
794-
json = {}
803+
json = None
795804
if sha and state:
796805
data = {'state': state, 'target_url': target_url,
797-
'description': description}
806+
'description': description, 'context': context}
798807
url = self._build_url('statuses', sha, base_url=self._api)
808+
self._remove_none(data)
799809
json = self._json(self._post(url, data=data), 201)
800810
return Status(json) if json else None
801811

github3/structs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def __iter__(self):
7979
json = json.items()
8080

8181
for i in json:
82+
if i is None: # Temporary fix for GitHub Enterprise and #304
83+
continue
8284
yield cls(i, self) if issubclass(cls, GitHubCore) else cls(i)
8385
self.count -= 1 if self.count > 0 else 0
8486
if self.count == 0:

0 commit comments

Comments
 (0)
0