osgithub 0.6.0__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.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osgithub
3
- Version: 0.6.0
3
+ Version: 0.8.0
4
4
  Home-page: https://github.com/opensafely-core/osgithub
5
5
  Author: OpenSAFELY
6
6
  Author-email: tech@opensafely.org
7
7
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
8
- Requires-Python: >=3.9
8
+ Requires-Python: >=3.10
9
9
  License-File: LICENSE
10
10
  Requires-Dist: requests
11
11
  Requires-Dist: requests-cache
@@ -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
- '*/pulls': 60, # expire requests to get pull requests after 60 secs
133
- '*/branches': 60 * 5, # expire requests to get branches after 5 mins
134
- '*/commits': 30, # expire requests to get commits after 30 secs
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, timezone
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
- dt = datetime.strptime(last_commit_date, "%Y-%m-%dT%H:%M:%SZ")
371
- # we know GitHub is giving us a UTC timezone because the string ends in
372
- # Z, but Python's strptime can't consume that with it's %Z operator so
373
- # we're matching it literally and then setting the timezone to UTC.
374
- return dt.replace(tzinfo=timezone.utc)
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
  """
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osgithub
3
- Version: 0.6.0
3
+ Version: 0.8.0
4
4
  Home-page: https://github.com/opensafely-core/osgithub
5
5
  Author: OpenSAFELY
6
6
  Author-email: tech@opensafely.org
7
7
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
8
- Requires-Python: >=3.9
8
+ Requires-Python: >=3.10
9
9
  License-File: LICENSE
10
10
  Requires-Dist: requests
11
11
  Requires-Dist: requests-cache
@@ -17,6 +17,7 @@ markers = [
17
17
  ]
18
18
 
19
19
  [tool.ruff]
20
+ target-version = "py310"
20
21
  line-length = 88
21
22
  exclude = [
22
23
  ".direnv",
@@ -13,7 +13,7 @@ setup(
13
13
  url="https://github.com/opensafely-core/osgithub",
14
14
  author="OpenSAFELY",
15
15
  author_email="tech@opensafely.org",
16
- python_requires=">=3.9",
16
+ python_requires=">=3.10",
17
17
  install_requires=["requests", "requests-cache", "furl"],
18
18
  entry_points={},
19
19
  include_package_data=True,
@@ -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=dict(state=state, page=1, per_page=30),
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=dict(state="open", page=1, per_page=30),
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=dict(state="open", page=i, per_page=30),
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=dict(state="open", page=3, per_page=30),
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=dict(ref="main"),
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=dict(sha="main", path="test-folder/test-file.html", per_page=1),
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=dict(sha="main", path="test-folder/test-file.html", per_page=1),
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=dict(ref="main"),
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=dict(ref="main"),
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=dict(ref="main"),
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=dict(ref="main"),
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=dict(sha="main", path="test-folder/test-file.html", per_page=1),
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=dict(ref="main"),
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=dict(ref="main"),
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=dict(sha="main", path="test-folder/test-file.html", per_page=1),
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