8000 Add support for getting patches and diffs · palfrey/github3.py@12afbbe · GitHub
[go: up one dir, main page]

Skip to content

Commit 12afbbe

Browse files
committed
1 parent 5c27132 commit 12afbbe

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

github3/pulls.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ def close(self):
169169
"""
170170
return self.update(self.title, self.body, 'closed')
171171

172+
def diff(self):
173+
"""Return the diff"""
174+
resp = self._get(self._api,
175+
headers={'Accept': 'application/vnd.github.diff'})
176+
return resp.content if self._boolean(resp, 200, 404) else None
177+
172178
def is_mergeable(self):
173179
"""Checks to see if the pull request can be merged by GitHub.
174180
@@ -257,6 +263,12 @@ def merge(self, commit_message=''):
257263
self.merge_commit_sha = resp['merge_commit_sha']
258264
return resp.json['merged']
259265

266+
def patch(self):
267+
"""Return the patch"""
268+
resp = self._get(self._api,
269+
headers={'Accept': 'application/vnd.github.patch'})
270+
return resp.content if self._boolean(resp, 200, 404) else None
271+
260272
@requires_auth
261273
def reopen(self):
262274
"""Re-open a closed Pull Request.

github3/repos.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,15 +1648,27 @@ def __init__(self, commit, session=None):
16481648
def __repr__(self):
16491649
return '<Repository Commit [{0}]>'.format(self.sha[:7])
16501650

1651+
def diff(self):
1652+
"""Return the diff"""
1653+
resp = self._get(self._api,
1654+
headers={'Accept': 'application/vnd.github.diff'})
1655+
return resp.content if self._boolean(resp, 200, 404) else None
16511656

1652-
class Comparison(GitHubObject):
1657+
def patch(self):
1658+
"""Return the patch"""
1659+
resp = self._get(self._api,
1660+
headers={'Accept': 'application/vnd.github.patch'})
1661+
return resp.content if self._boolean(resp, 200, 404) else None
1662+
1663+
1664+
class Comparison(GitHubCore):
16531665
"""The :class:`Comparison <Comparison>` object. This encapsulates the
16541666
information returned by GitHub comparing two commit objects in a
16551667
repository."""
16561668

16571669
def __init__(self, compare):
16581670
super(Comparison, self).__init__(compare)
1659-
self._api = compare.get('api', '')
1671+
self._api = compare.get('url', '')
16601672
#: URL to view the comparison at GitHub
16611673
self.html_url = compare.get('html_url')
16621674
#: Permanent link to this comparison.
@@ -1684,6 +1696,18 @@ def __init__(self, compare):
16841696
def __repr__(self):
16851697
return '<Comparison of {0} commits>'.format(self.total_commits)
16861698

1699+
def diff(self):
1700+
"""Return the diff"""
1701+
resp = self._get(self._api,
1702+
headers={'Accept': 'application/vnd.github.diff'})
1703+
return resp.content if self._boolean(resp, 200, 404) else None
1704+
1705+
def patch(self):
1706+
"""Return the patch"""
1707+
resp = self._get(self._api,
1708+
headers={'Accept': 'application/vnd.github.patch'})
1709+
return resp.content if self._boolean(resp, 200, 404) else None
1710+
16871711

16881712
class Status(GitHubObject):
16891713
"""The :class:`Status <Status>` object. This represents information from

0 commit comments

Comments
 (0)
0