github-rest-api 0.41.0__tar.gz → 0.42.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.
Files changed (43) hide show
  1. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/PKG-INFO +1 -1
  2. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/github.py +35 -9
  3. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/pyproject.toml +1 -1
  4. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/uv.lock +1 -1
  5. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.devcontainer/devcontainer.json +0 -0
  6. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.github/workflows/create_pr_to_main.yaml +0 -0
  7. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.github/workflows/lint.yaml +0 -0
  8. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.github/workflows/release.yaml +0 -0
  9. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.github/workflows/remove_branch.yaml +0 -0
  10. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.github/workflows/test.yaml +0 -0
  11. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/.gitignore +0 -0
  12. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/GEMINI.md +0 -0
  13. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/README.md +0 -0
  14. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/__init__.py +0 -0
  15. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/__init__.py +0 -0
  16. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/cargo/__init__.py +0 -0
  17. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/cargo/benchmark.py +0 -0
  18. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/cargo/profiling.py +0 -0
  19. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/cargo/utils.py +0 -0
  20. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/container/__init__.py +0 -0
  21. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/container/build_container_images.py +0 -0
  22. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/container/config_container.py +0 -0
  23. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/container/update_version_containerfile.py +0 -0
  24. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/__init__.py +0 -0
  25. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/add_github_repo.py +0 -0
  26. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/create_pull_request.py +0 -0
  27. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/release_on_github.py +0 -0
  28. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/remove_branch.py +0 -0
  29. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/workflows/create_pr_dev_to_main.yaml +0 -0
  30. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/workflows/create_pr_to_dev.yaml +0 -0
  31. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/workflows/create_pr_to_main.yaml +0 -0
  32. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/workflows/python/lint.yaml +0 -0
  33. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/workflows/python/test.yaml +0 -0
  34. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/github/workflows/remove_branch.yaml +0 -0
  35. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/scripts/utils.py +0 -0
  36. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/github_rest_api/utils.py +0 -0
  37. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/memory/MEMORY.md +0 -0
  38. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/memory/feedback_test_runner.md +0 -0
  39. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/tests/__init__.py +0 -0
  40. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/tests/test_build_container_images.py +0 -0
  41. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/tests/test_github.py +0 -0
  42. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/tests/test_release_on_github.py +0 -0
  43. {github_rest_api-0.41.0 → github_rest_api-0.42.0}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: github-rest-api
3
- Version: 0.41.0
3
+ Version: 0.42.0
4
4
  Summary: Simple wrapper of GitHub REST APIs.
5
5
  Author-email: Ben Du <longendu@yahoo.com>
6
6
  Classifier: Programming Language :: Python :: 3 :: Only
@@ -132,8 +132,19 @@ class GitHub:
132
132
  return resp
133
133
 
134
134
  def _extract_all(
135
- self, url: str, params: dict[str, Any] | None = None, n: int = 0
135
+ self,
136
+ url: str,
137
+ params: dict[str, Any] | None = None,
138
+ n: int = 0,
139
+ key: str | None = None,
136
140
  ) -> list[dict[str, Any]]:
141
+ """Collect all paginated items from a GitHub REST API endpoint.
142
+ :param url: The endpoint URL to request.
143
+ :param params: Query parameters forwarded to each request.
144
+ :param n: The maximum number of items to return (0 means all).
145
+ :param key: The key under which the list is nested in the response.
146
+ Defaults to None for endpoints that return a plain JSON array.
147
+ """
137
148
  params = params.copy() if params else {}
138
149
  if "per_page" not in params:
139
150
  params["per_page"] = min(100, n) if n > 0 else 100
@@ -143,10 +154,11 @@ class GitHub:
143
154
  resp = self._get(url=url, params=params.copy())
144
155
  resp.raise_for_status()
145
156
  data = resp.json()
146
- res.extend(data)
157
+ items = data if key is None else data[key]
158
+ res.extend(items)
147
159
  if n and len(res) >= n:
148
160
  return res[:n]
149
- if len(data) < params["per_page"]:
161
+ if len(items) < params["per_page"]:
150
162
  return res
151
163
  params["page"] += 1
152
164
 
@@ -315,6 +327,10 @@ class Repository(GitHub):
315
327
  """
316
328
  return self.delete_ref(ref=f"heads/{branch}")
317
329
 
330
+ def get_secrets(self, n: int = 0) -> list[dict[str, Any]]:
331
+ """List secrets in this repository."""
332
+ return self._extract_all(url=self._url_secrets, n=n, key="secrets")
333
+
318
334
  def delete_secret(self, name: str) -> requests.Response:
319
335
  """Delete a secret from this repository.
320
336
  :param name: The name of the secret to delete.
@@ -328,15 +344,18 @@ class Repository(GitHub):
328
344
  return self._get(url=f"{self._url_secrets}/public-key").json()
329
345
 
330
346
  def create_or_update_secret(
331
- self, name: str, value: str, public_key: dict[str, Any]
347
+ self, name: str, value: str, public_key: dict[str, Any] | None = None
332
348
  ) -> requests.Response:
333
349
  """Create or update a secret in this repository.
334
350
  :param name: The name of the secret.
335
351
  :param value: The plaintext value of the secret.
336
352
  :param public_key: A public key (as returned by `get_secret_public_key`)
337
- to encrypt the secret with. Fetch it once and reuse it to avoid a
338
- redundant request when creating or updating multiple secrets.
353
+ to encrypt the secret with. If not provided, it is fetched
354
+ automatically. Fetch it once and reuse it to avoid a redundant
355
+ request when creating or updating multiple secrets.
339
356
  """
357
+ if public_key is None:
358
+ public_key = self.get_secret_public_key()
340
359
  return self._put(
341
360
  url=f"{self._url_secrets}/{name}",
342
361
  json={
@@ -494,6 +513,10 @@ class Organization(Owner):
494
513
  self._url_create_repo = self._url_repos
495
514
  self._url_secrets = f"{self._url_owner}/actions/secrets"
496
515
 
516
+ def get_secrets(self, n: int = 0) -> list[dict[str, Any]]:
517
+ """List secrets in this organization."""
518
+ return self._extract_all(url=self._url_secrets, n=n, key="secrets")
519
+
497
520
  def delete_secret(self, name: str) -> requests.Response:
498
521
  """Delete an organization secret.
499
522
  :param name: The name of the secret to delete.
@@ -510,7 +533,7 @@ class Organization(Owner):
510
533
  self,
511
534
  name: str,
512
535
  value: str,
513
- public_key: dict[str, Any],
536
+ public_key: dict[str, Any] | None = None,
514
537
  visibility: SecretVisibility = SecretVisibility.ALL,
515
538
  selected_repository_ids: Sequence[int] = (),
516
539
  ) -> requests.Response:
@@ -518,8 +541,9 @@ class Organization(Owner):
518
541
  :param name: The name of the secret.
519
542
  :param value: The plaintext value of the secret.
520
543
  :param public_key: A public key (as returned by `get_secret_public_key`)
521
- to encrypt the secret with. Fetch it once and reuse it to avoid a
522
- redundant request when creating or updating multiple secrets.
544
+ to encrypt the secret with. If not provided, it is fetched
545
+ automatically. Fetch it once and reuse it to avoid a redundant
546
+ request when creating or updating multiple secrets.
523
547
  :param visibility: Which repositories can access the secret
524
548
  (all, private, or selected).
525
549
  :param selected_repository_ids: Repository IDs that can access the secret
@@ -529,6 +553,8 @@ class Organization(Owner):
529
553
  raise ValueError(
530
554
  "`selected_repository_ids` can only be provided when `visibility` is 'selected'."
531
555
  )
556
+ if public_key is None:
557
+ public_key = self.get_secret_public_key()
532
558
  json: dict[str, Any] = {
533
559
  "encrypted_value": _encrypt_secret(public_key["key"], value),
534
560
  "key_id": public_key["key_id"],
@@ -4,7 +4,7 @@ requires = [ "hatchling" ]
4
4
 
5
5
  [project]
6
6
  name = "github-rest-api"
7
- version = "0.41.0"
7
+ version = "0.42.0"
8
8
  description = "Simple wrapper of GitHub REST APIs."
9
9
  readme = "README.md"
10
10
  authors = [ { name = "Ben Du", email = "longendu@yahoo.com" } ]
@@ -223,7 +223,7 @@ wheels = [
223
223
 
224
224
  [[package]]
225
225
  name = "github-rest-api"
226
- version = "0.40.0"
226
+ version = "0.41.0"
227
227
  source = { editable = "." }
228
228
  dependencies = [
229
229
  { name = "dulwich" },