osgithub 0.7.1__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {osgithub-0.7.1 → osgithub-0.8.0}/PKG-INFO +1 -1
- {osgithub-0.7.1 → osgithub-0.8.0}/README.md +4 -3
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub/github.py +6 -6
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub.egg-info/PKG-INFO +1 -1
- {osgithub-0.7.1 → osgithub-0.8.0}/pyproject.toml +1 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/tests/test_github.py +31 -15
- {osgithub-0.7.1 → osgithub-0.8.0}/LICENSE +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub/__init__.py +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub.egg-info/SOURCES.txt +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub.egg-info/dependency_links.txt +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub.egg-info/requires.txt +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/osgithub.egg-info/top_level.txt +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/setup.cfg +0 -0
- {osgithub-0.7.1 → osgithub-0.8.0}/setup.py +0 -0
|
@@ -16,6 +16,7 @@ Set the following environment variables:
|
|
|
16
16
|
|
|
17
17
|
```py
|
|
18
18
|
from github_api_cache import GithubClient
|
|
19
|
+
|
|
19
20
|
# Use the default token, if one is set in the environment.
|
|
20
21
|
client = GithubClient()
|
|
21
22
|
```
|
|
@@ -129,9 +130,9 @@ Set expiry on specific url patterns (falls back to `expire_after` if no match fo
|
|
|
129
130
|
|
|
130
131
|
```py
|
|
131
132
|
urls_expire_after = {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
"*/pulls": 60, # expire requests to get pull requests after 60 secs
|
|
134
|
+
"*/branches": 60 * 5, # expire requests to get branches after 5 mins
|
|
135
|
+
"*/commits": 30, # expire requests to get commits after 30 secs
|
|
135
136
|
}
|
|
136
137
|
client = GithubClient(urls_expire_after=urls_expire_after)
|
|
137
138
|
```
|
|
@@ -13,7 +13,7 @@ Optionally uses requests caching to avoid repeated calls to the API.
|
|
|
13
13
|
|
|
14
14
|
import json
|
|
15
15
|
from base64 import b64decode
|
|
16
|
-
from datetime import datetime
|
|
16
|
+
from datetime import datetime
|
|
17
17
|
from os import environ
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
|
|
@@ -367,11 +367,11 @@ class GithubRepo:
|
|
|
367
367
|
"""
|
|
368
368
|
commits = self.get_commits_for_file(path, ref, number_of_commits=1)
|
|
369
369
|
last_commit_date = commits[0]["commit"]["committer"]["date"]
|
|
370
|
-
|
|
371
|
-
#
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
370
|
+
# GitHub returns UTC timestamps with a trailing Z; normalize it to an
|
|
371
|
+
# explicit UTC offset so strptime can create an aware datetime with %z.
|
|
372
|
+
return datetime.strptime(
|
|
373
|
+
last_commit_date.replace("Z", "+00:00"), "%Y-%m-%dT%H:%M:%S%z"
|
|
374
|
+
)
|
|
375
375
|
|
|
376
376
|
def get_readme(self, tag="main"):
|
|
377
377
|
"""
|
|
@@ -121,7 +121,7 @@ def test_github_repo_get_pull_requests(httpretty, state):
|
|
|
121
121
|
register_uri(
|
|
122
122
|
httpretty,
|
|
123
123
|
"repos/test/foo/pulls",
|
|
124
|
-
queryparams=
|
|
124
|
+
queryparams={"state": state, "page": 1, "per_page": 30},
|
|
125
125
|
body=pull_requests[state],
|
|
126
126
|
)
|
|
127
127
|
pulls = repo.get_pull_requests(state)
|
|
@@ -146,7 +146,7 @@ def test_github_repo_get_open_pull_request_count(httpretty):
|
|
|
146
146
|
register_uri(
|
|
147
147
|
httpretty,
|
|
148
148
|
"repos/test/foo/pulls",
|
|
149
|
-
queryparams=
|
|
149
|
+
queryparams={"state": "open", "page": 1, "per_page": 30},
|
|
150
150
|
body=pull_requests,
|
|
151
151
|
)
|
|
152
152
|
assert repo.open_pull_request_count == 2
|
|
@@ -195,7 +195,7 @@ def test_github_repo_get_multipage_pull_request_count(httpretty):
|
|
|
195
195
|
register_uri(
|
|
196
196
|
httpretty,
|
|
197
197
|
"repos/test/foo/pulls",
|
|
198
|
-
queryparams=
|
|
198
|
+
queryparams={"state": "open", "page": i, "per_page": 30},
|
|
199
199
|
body=pull_requests,
|
|
200
200
|
)
|
|
201
201
|
last_page_pull_requests = [
|
|
@@ -209,7 +209,7 @@ def test_github_repo_get_multipage_pull_request_count(httpretty):
|
|
|
209
209
|
register_uri(
|
|
210
210
|
httpretty,
|
|
211
211
|
"repos/test/foo/pulls",
|
|
212
|
-
queryparams=
|
|
212
|
+
queryparams={"state": "open", "page": 3, "per_page": 30},
|
|
213
213
|
body=last_page_pull_requests,
|
|
214
214
|
)
|
|
215
215
|
|
|
@@ -242,7 +242,7 @@ def test_github_repo_get_contents_single_file(httpretty):
|
|
|
242
242
|
register_uri(
|
|
243
243
|
httpretty,
|
|
244
244
|
"repos/test/foo/contents/test-folder/test-file.html",
|
|
245
|
-
queryparams=
|
|
245
|
+
queryparams={"ref": "main"},
|
|
246
246
|
body=reponse_json,
|
|
247
247
|
)
|
|
248
248
|
|
|
@@ -250,7 +250,11 @@ def test_github_repo_get_contents_single_file(httpretty):
|
|
|
250
250
|
register_uri(
|
|
251
251
|
httpretty,
|
|
252
252
|
"repos/test/foo/commits",
|
|
253
|
-
queryparams=
|
|
253
|
+
queryparams={
|
|
254
|
+
"sha": "main",
|
|
255
|
+
"path": "test-folder/test-file.html",
|
|
256
|
+
"per_page": 1,
|
|
257
|
+
},
|
|
254
258
|
body=commits_response,
|
|
255
259
|
)
|
|
256
260
|
|
|
@@ -280,7 +284,11 @@ def test_github_repo_get_last_updated(httpretty):
|
|
|
280
284
|
register_uri(
|
|
281
285
|
httpretty,
|
|
282
286
|
"repos/test/foo/commits",
|
|
283
|
-
queryparams=
|
|
287
|
+
queryparams={
|
|
288
|
+
"sha": "main",
|
|
289
|
+
"path": "test-folder/test-file.html",
|
|
290
|
+
"per_page": 1,
|
|
291
|
+
},
|
|
284
292
|
body=commits_response,
|
|
285
293
|
)
|
|
286
294
|
|
|
@@ -327,7 +335,7 @@ def test_github_repo_get_contents_exceptions(
|
|
|
327
335
|
register_uri(
|
|
328
336
|
httpretty,
|
|
329
337
|
"repos/test/foo/contents/test-folder/test-file.html",
|
|
330
|
-
queryparams=
|
|
338
|
+
queryparams={"ref": "main"},
|
|
331
339
|
status=status_code,
|
|
332
340
|
body=body,
|
|
333
341
|
)
|
|
@@ -368,7 +376,7 @@ def test_github_repo_matching_file_from_parent_contents(
|
|
|
368
376
|
register_uri(
|
|
369
377
|
httpretty,
|
|
370
378
|
"repos/test/foo/contents/test-folder",
|
|
371
|
-
queryparams=
|
|
379
|
+
queryparams={"ref": "main"},
|
|
372
380
|
body=response_json,
|
|
373
381
|
)
|
|
374
382
|
|
|
@@ -401,7 +409,7 @@ def test_github_repo_get_contents_folder(httpretty):
|
|
|
401
409
|
register_uri(
|
|
402
410
|
httpretty,
|
|
403
411
|
"repos/test/foo/contents/test-folder",
|
|
404
|
-
queryparams=
|
|
412
|
+
queryparams={"ref": "main"},
|
|
405
413
|
body=response_json,
|
|
406
414
|
)
|
|
407
415
|
contents = repo.get_contents("test-folder", ref="main")
|
|
@@ -443,7 +451,7 @@ def test_github_repo_get_contents_from_git_blob(httpretty):
|
|
|
443
451
|
register_uri(
|
|
444
452
|
httpretty,
|
|
445
453
|
"repos/test/foo/contents/test-folder",
|
|
446
|
-
queryparams=
|
|
454
|
+
queryparams={"ref": "main"},
|
|
447
455
|
body=response_json,
|
|
448
456
|
)
|
|
449
457
|
|
|
@@ -463,7 +471,11 @@ def test_github_repo_get_contents_from_git_blob(httpretty):
|
|
|
463
471
|
register_uri(
|
|
464
472
|
httpretty,
|
|
465
473
|
"repos/test/foo/commits",
|
|
466
|
-
queryparams=
|
|
474
|
+
queryparams={
|
|
475
|
+
"sha": "main",
|
|
476
|
+
"path": "test-folder/test-file.html",
|
|
477
|
+
"per_page": 1,
|
|
478
|
+
},
|
|
467
479
|
body=commits_response,
|
|
468
480
|
)
|
|
469
481
|
|
|
@@ -499,7 +511,7 @@ def test_github_repo_get_contents_too_large_file(httpretty):
|
|
|
499
511
|
httpretty,
|
|
500
512
|
"repos/test/foo/contents/test-folder/test-file.html",
|
|
501
513
|
status=200,
|
|
502
|
-
queryparams=
|
|
514
|
+
queryparams={"ref": "main"},
|
|
503
515
|
body={
|
|
504
516
|
"name": "test-file.html",
|
|
505
517
|
"path": "test-folder/test-file.html",
|
|
@@ -515,7 +527,7 @@ def test_github_repo_get_contents_too_large_file(httpretty):
|
|
|
515
527
|
httpretty,
|
|
516
528
|
"repos/test/foo/contents/test-folder",
|
|
517
529
|
status=200,
|
|
518
|
-
queryparams=
|
|
530
|
+
queryparams={"ref": "main"},
|
|
519
531
|
body=[
|
|
520
532
|
{
|
|
521
533
|
"name": "test-file.html",
|
|
@@ -547,7 +559,11 @@ def test_github_repo_get_contents_too_large_file(httpretty):
|
|
|
547
559
|
register_uri(
|
|
548
560
|
httpretty,
|
|
549
561
|
"repos/test/foo/commits",
|
|
550
|
-
queryparams=
|
|
562
|
+
queryparams={
|
|
563
|
+
"sha": "main",
|
|
564
|
+
"path": "test-folder/test-file.html",
|
|
565
|
+
"per_page": 1,
|
|
566
|
+
},
|
|
551
567
|
body=commits_response,
|
|
552
568
|
)
|
|
553
569
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|