Skip to content

Commit f963db2

Browse files
authored
Merge pull request sigmavirus24#817 from tobiashenkel/fix-empty-patch
Make patch attribute in response optional
2 parents 8a0d314 + 31242a5 commit f963db2

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-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_url
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,12 @@ def test_contents(self):
286286
self.session.get.assert_called_once_with(
287287
self.example_data['contents_url']
288288
)
289+
290+
291+
class TestPullFilePatch(TestPullFile):
292+
"""Unit tests for the PullFile class with empty patch."""
293+
294+
get_pull_file_patch_example_data = helper.create_example_data_helper(
295+
'pull_file_missing_patch_example'
296+
)
297+
example_data = get_pull_file_patch_example_data()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy