8000 Make license attribute in response optional · pythonthings/github3.py@08b1488 · GitHub
[go: up one dir, main page]

Skip to content

Commit 08b1488

Browse files
committed
Make license attribute in response optional
Github Enterprise instances <= 2.12.7 do not include the license attribute in responses for repository data. Allow this to be not set and include a note in the documentation that the corresponding attr may be set to None. Partially fixes sigmavirus24#794
1 parent bf44c16 commit 08b1488

File tree

3 files changed

+355
-1
lines changed

3 files changed

+355
-1
lines changed

github3/repos/repo.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,14 @@ class Repository(_Repository):
23602360
23612361
.. attribute:: original_license
23622362
2363+
.. note::
2364+
2365+
When used with a Github Enterprise instance <= 2.12.7, this
2366+
attribute will not be returned. To handle these situations
2367+
sensitively, the attribute will be set to ``None``.
2368+
Repositories may still have a license associated with them
2369+
in these cases.
2370+
23632371
This is the :class:`~github3.license.ShortLicense` returned as part of
23642372
the repository. To retrieve the most recent license, see the
23652373
:meth:`~github3.repos.repo.Repository.license` method.
@@ -2447,7 +2455,7 @@ def _update_attributes(self, repo):
24472455
self.has_wiki = repo['has_wiki']
24482456
self.homepage = repo['homepage']
24492457
self.language = repo['language']
2450-
self.original_license = repo['license']
2458+
self.original_license = repo.get('license', None)
24512459
if self.original_license is not None:
24522460
self.original_license = licenses.ShortLicense(
24532461
self.original_license, self

tests/unit/json/repo_2_12_example

Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
{
2+
"id": 1296269,
3+
"owner": {
4+
"login": "octocat",
5+
"id": 1,
6+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
7+
"gravatar_id": "",
8+
"url": "https://api.github.com/users/octocat",
9+
"html_url": "https://github.com/octocat",
10+
"followers_url": "https://api.github.com/users/octocat/followers",
11+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
12+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
13+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
14+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
15+
"organizations_url": "https://api.github.com/users/octocat/orgs",
16+
"repos_url": "https://api.github.com/users/octocat/repos",
17+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
18+
"received_events_url": "https://api.github.com/users/octocat/received_events",
19+
"type": "User",
20+
"site_admin": false
21+
},
22+
"name": "Hello-World",
23+
"full_name": "octocat/Hello-World",
24+
"description": "This your first repo!",
25+
"private": false,
26+
"fork": false,
27+
"url": "https://api.github.com/repos/octocat/Hello-World",
28+
"html_url": "https://github.com/octocat/Hello-World",
29+
"archive_url": "http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
30+
"assignees_url": "http://api.github.com/repos/octocat/Hello-World/assignees{/user}",
31+
"blobs_url": "http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}",
32+
"branches_url": "http://api.github.com/repos/octocat/Hello-World/branches{/branch}",
33+
"clone_url": "https://github.com/octocat/Hello-World.git",
34+
"collaborators_url": "http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}",
35+
"comments_url": "http://api.github.com/repos/octocat/Hello-World/comments{/number}",
36+
"commits_url": "http://api.github.com/repos/octocat/Hello-World/commits{/sha}",
37+
"compare_url": "http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}",
38+
"contents_url": "http://api.github.com/repos/octocat/Hello-World/contents/{+path}",
39+
"contributors_url": "http://api.github.com/repos/octocat/Hello-World/contributors",
40+
"deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments",
41+
"downloads_url": "http://api.github.com/repos/octocat/Hello-World/downloads",
42+
"events_url": "http://api.github.com/repos/octocat/Hello-World/events",
43+
"forks_url": "http://api.github.com/repos/octocat/Hello-World/forks",
44+
"git_commits_url": "http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}",
45+
"git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}",
46+
"git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}",
47+
"git_url": "git:github.com/octocat/Hello-World.git",
48+
"hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks",
49+
"issue_comment_url": "http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}",
50+
"issue_events_url": "http://api.github.com/repos/octocat/Hello-World/issues/events{/number}",
51+
"issues_url": "http://api.github.com/repos/octocat/Hello-World/issues{/number}",
52+
"keys_url": "http://api.github.com/repos/octocat/Hello-World/keys{/key_id}",
53+
"labels_url": "http://api.github.com/repos/octocat/Hello-World/labels{/name}",
54+
"languages_url": "http://api.github.com/repos/octocat/Hello-World/languages",
55+
"merges_url": "http://api.github.com/repos/octocat/Hello-World/merges",
56+
"milestones_url": "http://api.github.com/repos/octocat/Hello-World/milestones{/number}",
57+
"mirror_url": "git:git.example.com/octocat/Hello-World",
58+
"notifications_url": "http://api.github.com/repos/octocat/Hello-World/notifications{?since, all, participating}",
59+
"pulls_url": "http://api.github.com/repos/octocat/Hello-World/pulls{/number}",
60+
"releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}",
61+
"ssh_url": "git@github.com:octocat/Hello-World.git",
62+
"stargazers_url": "http://api.github.com/repos/octocat/Hello-World/stargazers",
63+
"statuses_url": "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}",
64+
"subscribers_url": "http://api.github.com/repos/octocat/Hello-World/subscribers",
65+
"subscription_url": "http://api.github.com/repos/octocat/Hello-World/subscription",
66+
"svn_url": "https://svn.github.com/octocat/Hello-World",
67+
"tags_url": "http://api.github.com/repos/octocat/Hello-World/tags",
68+
"teams_url": "http://api.github.com/repos/octocat/Hello-World/teams",
69+
"trees_url": "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}",
70+
"homepage": "https://github.com",
71+
"language": null,
72+
"forks_count": 9,
73+
"stargazers_count": 80,
74+
"watchers_count": 80,
75+
"size": 108,
76+
"default_branch": "master",
77+
"open_issues_count": 0,
78+
"topics": [
79+
"octocat",
80+
"atom",
81+
"electron",
82+
"API"
83+
],
84+
"has_issues": true,
85+
"has_wiki": true,
86+
"has_pages": false,
87+
"has_projects": false,
88+
"has_downloads": true,
89+
"archived": false,
90+
"pushed_at": "2011-01-26T19:06:43Z",
91+
"created_at": "2011-01-26T19:01:12Z",
92+
"updated_at": "2011-01-26T19:14:43Z",
93+
"permissions": {
94+
"admin": false,
95+
"push": false,
96+
"pull": true
97+
},
98+
"allow_rebase_merge": true,
99+
"allow_squash_merge": true,
100+
"allow_merge_commit": true,
101+
"subscribers_count": 42,
102+
"network_count": 0,
103+
"organization": {
104+
"login": "octocat",
105+
"id": 1,
106+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
107+
"gravatar_id": "",
108+
"url": "https://api.github.com/users/octocat",
109+
"html_url": "https://github.com/octocat",
110+
"followers_url": "https://api.github.com/users/octocat/followers",
111+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
112+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
113+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
114+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
115+
"organizations_url": "https://api.github.com/users/octocat/orgs",
116+
"repos_url": "https://api.github.com/users/octocat/repos",
117+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
118+
"received_events_url": "https://api.github.com/users/octocat/received_events",
119+
"type": "Organization",
120+
"site_admin": false
121+
},
122+
"parent": {
123+
"id": 1296269,
124+
"owner": {
125+
"login": "octocat",
126+
"id": 1,
127+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
128+
"gravatar_id": "",
129+
"url": "https://api.github.com/users/octocat",
130+
"html_url": "https://github.com/octocat",
131+
"followers_url": "https://api.github.com/users/octocat/followers",
132+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
133+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
134+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
135+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
136+
"organizations_url": "https://api.github.com/users/octocat/orgs",
137+
"repos_url": "https://api.github.com/users/octocat/repos",
138+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
139+
"received_events_url": "https://api.github.com/users/octocat/received_events",
140+
"type": "User",
141+
"site_admin": false
142+
},
143+
"name": "Hello-World",
144+
"full_name": "octocat/Hello-World",
145+
"description": "This your first repo!",
146+
"private": false,
147+
"fork": false,
148+
"url": "https://api.github.com/repos/octocat/Hello-World",
149+
"html_url": "https://github.com/octocat/Hello-World",
150+
"archive_url": "http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
151+
"assignees_url": "http://api.github.com/repos/octocat/Hello-World/assignees{/user}",
152+
"blobs_url": "http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}",
153+
"branches_url": "http://api.github.com/repos/octocat/Hello-World/branches{/branch}",
154+
"clone_url": "https://github.com/octocat/Hello-World.git",
155+
"collaborators_url": "http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}",
156+
"comments_url": "http://api.github.com/repos/octocat/Hello-World/comments{/number}",
157+
"commits_url": "http://api.github.com/repos/octocat/Hello-World/commits{/sha}",
158+
"compare_url": "http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}",
159+
"contents_url": "http://api.github.com/repos/octocat/Hello-World/contents/{+path}",
160+
"contributors_url": "http://api.github.com/repos/octocat/Hello-World/contributors",
161+
"deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments",
162+
"downloads_url": "http://api.github.com/repos/octocat/Hello-World/downloads",
163+
"events_url": "http://api.github.com/repos/octocat/Hello-World/events",
164+
"forks_url": "http://api.github.com/repos/octocat/Hello-World/forks",
165+
"git_commits_url": "http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}",
166+
"git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}",
167+
"git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}",
168+
"git_url": "git:github.com/octocat/Hello-World.git",
169+
"hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks",
170+
"issue_comment_url": "http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}",
171+
"issue_events_url": "http://api.github.com/repos/octocat/Hello-World/issues/events{/number}",
172+
"issues_url": "http://api.github.com/repos/octocat/Hello-World/issues{/number}",
173+
"keys_url": "http://api.github.com/repos/octocat/Hello-World/keys{/key_id}",
174+
"labels_url": "http://api.github.com/repos/octocat/Hello-World/labels{/name}",
175+
"languages_url": "http://api.github.com/repos/octocat/Hello-World/languages",
176+
"merges_url": "http://api.github.com/repos/octocat/Hello-World/merges",
177+
"milestones_url": "http://api.github.com/repos/octocat/Hello-World/milestones{/number}",
178+
"mirror_url": "git:git.example.com/octocat/Hello-World",
179+
"notifications_url": "http://api.github.com/repos/octocat/Hello-World/notifications{?since, all, participating}",
180+
"pulls_url": "http://api.github.com/repos/octocat/Hello-World/pulls{/number}",
181+
"releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}",
182+
"ssh_url": "git@github.com:octocat/Hello-World.git",
183+
"stargazers_url": "http://api.github.com/repos/octocat/Hello-World/stargazers",
184+
"statuses_url": "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}",
185+
"subscribers_url": "http://api.github.com/repos/octocat/Hello-World/subscribers",
186+
"subscription_url": "http://api.github.com/repos/octocat/Hello-World/subscription",
187+
"svn_url": "https://svn.github.com/octocat/Hello-World",
188+
"tags_url": "http://api.github.com/repos/octocat/Hello-World/tags",
189+
"teams_url": "http://api.github.com/repos/octocat/Hello-World/teams",
190+
"trees_url": "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}",
191+
"homepage": "https://github.com",
192+
"language": null,
193+
"forks_count": 9,
194+
"stargazers_count": 80,
195+
"watchers_count": 80,
196+
"size": 108,
197+
"default_branch": "master",
198+
"open_issues_count": 0,
199+
"topics": [
200+
"octocat",
201+
"atom",
202+
"electron",
203+
"API"
204+
],
205+
"has_issues": true,
206+
"has_wiki": true,
207+
"has_pages": false,
208+
"has_projects": false,
209+
"has_downloads": true,
210+
"archived": false,
211+
"pushed_at": "2011-01-26T19:06:43Z",
212+
"created_at": "2011-01-26T19:01:12Z",
213+
"updated_at": "2011-01-26T19:14:43Z",
214+
"permissions": {
215+
"admin": false,
216+
"push": false,
217+
"pull": true
218+
},
219+
"allow_rebase_merge": true,
220+
"allow_squash_merge": true,
221+
"allow_merge_commit": true,
222+
"subscribers_count": 42,
223+
"network_count": 0
224+
},
225+
"source": {
226+
"id": 1296269,
227+
"owner": {
228+
"login": "octocat",
229+
"id": 1,
230+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
231+
"gravatar_id": "",
232+
"url": "https://api.github.com/users/octocat",
233+
"html_url": "https://github.com/octocat",
234+
"followers_url": "https://api.github.com/users/octocat/followers",
235+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
236+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
237+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
238+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
239+
"organizations_url": "https://api.github.com/users/octocat/orgs",
240+
"repos_url": "https://api.github.com/users/octocat/repos",
241+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
242+
"received_events_url": "https://api.github.com/users/octocat/received_events",
243+
"type": "User",
244+
"site_admin": false
245+
},
246+
"name": "Hello-World",
247+
"full_name": "octocat/Hello-World",
248+
"description": "This your first repo!",
249+
"private": false,
250+
"fork": false,
251+
"url": "https://api.github.com/repos/octocat/Hello-World",
252+
"html_url": "https://github.com/octocat/Hello-World",
253+
"archive_url": "http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
254+
"assignees_url": "http://api.github.com/repos/octocat/Hello-World/assignees{/user}",
255+
"blobs_url": "http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}",
256+
"branches_url": "http://api.github.com/repos/octocat/Hello-World/branches{/branch}",
257+
"clone_url": "https://github.com/octocat/Hello-World.git",
258+
"collaborators_url": "http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}",
259+
"comments_url": "http://api.github.com/repos/octocat/Hello-World/comments{/number}",
260+
"commits_url": "http://api.github.com/repos/octocat/Hello-World/commits{/sha}",
261+
"compare_url": "http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}",
262+
"contents_url": "http://api.github.com/repos/octocat/Hello-World/contents/{+path}",
263+
"contributors_url": "http://api.github.com/repos/octocat/Hello-World/contributors",
264+
"deployments_url": "http://api.github.com/repos/octocat/Hello-World/deployments",
265+
"downloads_url": "http://api.github.com/repos/octocat/Hello-World/downloads",
266+
"events_url": "http://api.github.com/repos/octocat/Hello-World/events",
267+
"forks_url": "http://api.github.com/repos/octocat/Hello-World/forks",
268+
"git_commits_url": "http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}",
269+
"git_refs_url": "http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}",
270+
"git_tags_url": "http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}",
271+
"git_url": "git:github.com/octocat/Hello-World.git",
272+
"hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks",
273+
"issue_comment_url": "http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}",
274+
"issue_events_url": "http://api.github.com/repos/octocat/Hello-World/issues/events{/number}",
275+
"issues_url": "http://api.github.com/repos/octocat/Hello-World/issues{/number}",
276+
"keys_url": "http://api.github.com/repos/octocat/Hello-World/keys{/key_id}",
277+
"labels_url": "http://api.github.com/repos/octocat/Hello-World/labels{/name}",
278+
"languages_url": "http://api.github.com/repos/octocat/Hello-World/languages",
279+
"merges_url": "http://api.github.com/repos/octocat/Hello-World/merges",
280+
"milestones_url": "http://api.github.com/repos/octocat/Hello-World/milestones{/number}",
281+
"mirror_url": "git:git.example.com/octocat/Hello-World",
282+
"notifications_url": "http://api.github.com/repos/octocat/Hello-World/notifications{?since, all, participating}",
283+
"pulls_url": "http://api.github.com/repos/octocat/Hello-World/pulls{/number}",
284+
"releases_url": "http://api.github.com/repos/octocat/Hello-World/releases{/id}",
285+
"ssh_url": "git@github.com:octocat/Hello-World.git",
286+
"stargazers_url": "http://api.github.com/repos/octocat/Hello-World/stargazers",
287+
"statuses_url": "http://api.github.com/repos/octocat/Hello-World/statuses/{sha}",
288+
"subscribers_url": "http://api.github.com/repos/octocat/Hello-World/subscribers",
289+
"subscription_url": "http://api.github.com/repos/octocat/Hello-World/subscription",
290+
"svn_url": "https://svn.github.com/octocat/Hello-World",
291+
"tags_url": "http://api.github.com/repos/octocat/Hello-World/tags",
292+
"teams_url": "http://api.github.com/repos/octocat/Hello-World/teams",
293+
"trees_url": "http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}",
294+
"homepage": "https://github.com",
295+
"language": null,
296+
"forks_count": 9,
297+
"stargazers_count": 80,
298+
"watchers_count": 80,
299+
"size": 108,
300+
"default_branch": "master",
301+
"open_issues_count": 0,
302+
"topics": [
303+
"octocat",
304+
"atom",
305+
"electron",
306+
"API"
307+
],
308+
"has_issues": true,
309+
"has_wiki": true,
310+
"has_pages": false,
311+
"has_projects": false,
312+
"has_downloads": true,
313+
"archived": false,
314+
"pushed_at": "2011-01-26T19:06:43Z",
315+
"created_at": "2011-01-26T19:01:12Z",
316+
"updated_at": "2011-01-26T19:14:43Z",
317+
"permissions": {
318+
"admin": false,
319+
"push": false,
320+
"pull": true
321+
},
322+
"allow_rebase_merge": true,
323+
"allow_squash_merge": true,
324+
"allow_merge_commit": true,
325+
"subscribers_count": 42,
326+
"network_count": 0
327+
}
328+
}

tests/unit/test_repos_repo.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
get_repo_example_data = helper.create_example_data_helper(
4040
'repo_example'
4141
)
42+
get_repo_2_12_example_data = helper.create_example_data_helper(
43+
'repo_2_12_example'
44+
)
4245
get_comment_example_data = helper.create_example_data_helper(
4346
'comment_example'
4447
)
@@ -64,6 +67,7 @@
6467
create_file_contents_example_data = create_file_contents_example_data()
6568
hook_example_data = get_hook_example_data()
6669
repo_example_data = get_repo_example_data()
70+
repo_2_12_example_data = get_repo_2_12_example_data()
6771

6872

6973
class TestRepository(helper.UnitHelper):
@@ -1950,3 +1954,17 @@ def test_patch(self):
19501954
def test_str(self):
19511955
"""Show that instance string is formatted correctly."""
19521956
assert str(self.instance).startswith('<Comparison')
1957+
1958+
1959+
class TestRepositoryCompatibility_2_12(helper.UnitIteratorHelper):
1960+
1961+
"""Unit tests for Repository from Github Enterprise 2.12"""
1962+
1963+
described_class = Repository
1964+
example_data = repo_2_12_example_data
1965+
1966+
def test_repository(self):
1967+
44B0 """
1968+
Test the ability to retrieve a Repository with older releases
1969+
"""
1970+
assert isinstance(self.instance, Repository)

0 commit comments

Comments
 (0)
0