8000 Make patch attribute in response optional · staticdev/github4.py@0550bf3 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit 0550bf3

Browse files
committed
Make patch attribute in response optional
When requesting files from a pull request which adds a large file (e.g. more than 3000 lines) there can be the case that the response of GitGub doesn't contain the patch in the response. In this case we have to default to None. Resolves: sigmavirus24#816
1 parent 2425b4a commit 0550bf3

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

github3/pulls.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ class PullFile(models.GitHubCore):
136136
137137
The patch generated by this
138138
139+
.. note::
140+
141+
If the patch is larger than a specific size it may be missing
142+
from GitHub's response. The attribute will be set to ``None``
143+
in this case.
144+
139145
.. attribute:: raw_ur 8000 l
140146
141147
The API resource to view the raw diff of this file
@@ -158,7 +164,7 @@ def _update_attributes(self, pfile):
158164
self.changes_count = pfile['changes']
159165
self.blob_url = pfile['blob_url']
160166
self.raw_url = pfile['raw_url']
161-
self.patch = pfile['patch']
167+
self.patch = pfile.get('patch')
162168
self.contents_url = pfile['contents_url']
163169

164170
def _repr(self):
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"sha": "bbcd538c8e72b8c175046e27cc8f907076331401",
3+
"filename": "file1.txt",
4+
"status": "added",
5+
"additions": 103,
6+
"deletions": 21,
7+
"changes": 124,
8+
"blob_url": "https://github.com/octocat/Hello-World/blob/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
9+
"raw_url": "https://github.com/octocat/Hello-World/raw/6dcb09b5b57875f334f61aebed695e2e4193db5e/file1.txt",
10+
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e"
11+
}

tests/unit/test_pulls.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,21 @@ def test_contents(self):
286286
self.session.get.assert_called_once_with(
287287
self.example_data['contents_url']
288288
)
289+
290+
291+
class TestPullFilePatch(helper.UnitHelper):
292+
"""Unit tests for the PullFile class with empty patch."""
293+
294+
described_class = pulls.PullFile
295+
get_pull_file_patch_example_data = helper.create_example_data_helper(
296+
'pull_file_patch_example'
297+
)
298+
example_data = get_pull_file_patch_example_data()
299+
300+
def test_contents(self):
301+
"""Verify the request made to fetch a pull request file contents."""
302+
self.instance.contents()
303+
304+
self.session.get.assert_called_once_with(
305+
self.example_data['contents_url']
306+
)

0 commit comments

Comments
 (0)
0