imbi-plugin-github 2.47.0__py3-none-any.whl → 2.49.0__py3-none-any.whl

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.
@@ -813,6 +813,16 @@ async def _fetch_all_commits(
813
813
  resp = await _request(
814
814
  client, 'GET', '/commits', params=params, max_wait=max_wait
815
815
  )
816
+ # GHES 404s a deep page it just linked to as ``next``. Keep the
817
+ # history read so far rather than drop the whole sync.
818
+ if resp.status_code == 404 and page > 1:
819
+ LOGGER.warning(
820
+ 'github-commit-sync got 404 for commits page %d (%d '
821
+ 'commits read); older commits will not be recorded',
822
+ page,
823
+ len(out),
824
+ )
825
+ return out
816
826
  resp.raise_for_status()
817
827
  out.extend(typing.cast('list[dict[str, typing.Any]]', resp.json()))
818
828
  next_url = _next_page_url(resp.headers.get('link'))
@@ -1067,12 +1067,48 @@ class GitHubDeployment(DeploymentCapability):
1067
1067
  async with self._client(
1068
1068
  ctx, credentials, SCOPE_CONTENTS_READ
1069
1069
  ) as client:
1070
- resp = await client.get(
1071
- f'/commits/{urllib.parse.quote(committish, safe="")}'
1070
+ # ``HEAD`` resolves to the default branch's head commit; the
1071
+ # ``sha`` media type answers with the bare sha.
1072
+ async def _head() -> httpx.Response | None:
1073
+ try:
1074
+ return await client.get(
1075
+ '/commits/HEAD',
1076
+ headers={'Accept': 'application/vnd.github.sha'},
1077
+ )
1078
+ except httpx.HTTPError:
1079
+ # Head detection is optional; keep the resolved commit.
1080
+ return None
1081
+
1082
+ resp, head = await asyncio.gather(
1083
+ client.get(
1084
+ f'/commits/{urllib.parse.quote(committish, safe="")}'
1085
+ ),
1086
+ _head(),
1072
1087
  )
1073
1088
  resp.raise_for_status()
1074
1089
  payload = typing.cast(dict[str, typing.Any], resp.json())
1075
- return _commit_from_payload(payload)
1090
+ commit = _commit_from_payload(payload)
1091
+ if (
1092
+ head is not None
1093
+ and head.status_code == 200
1094
+ and head.text.strip() == commit.sha
1095
+ ):
1096
+ commit = commit.model_copy(update={'is_head': True})
1097
+ host = self._resolve_host(ctx)
1098
+ owner, repo = self._owner_repo(ctx)
1099
+ if _checks_disabled(credentials, host, owner, repo):
1100
+ return commit
1101
+ # A separate checks-scoped token: an App without ``checks: read``
1102
+ # (a ``422`` on mint) still resolves, with ``ci_status`` unknown.
1103
+ try:
1104
+ async with self._client(
1105
+ ctx, credentials, SCOPE_CHECKS_READ
1106
+ ) as client:
1107
+ return await self._hydrate_check_status(
1108
+ client, credentials, host, owner, repo, commit
1109
+ )
1110
+ except httpx.HTTPError:
1111
+ return commit
1076
1112
 
1077
1113
  # -- Compare ------------------------------------------------------------
1078
1114
 
@@ -554,6 +554,47 @@ class GitHubLifecycle(LifecycleCapability):
554
554
  display=identifier,
555
555
  )
556
556
 
557
+ async def check_archive_access(
558
+ self,
559
+ ctx: PluginContext,
560
+ credentials: dict[str, str],
561
+ ) -> str | None:
562
+ """Refuse when the caller is not an admin of the repository.
563
+
564
+ GitHub answers an archive or unarchive ``PATCH`` from a non-admin
565
+ with ``403``. The repo payload carries the caller's
566
+ ``permissions`` for a user token; when it is absent (an App
567
+ installation token), allow the request. GitHub answers ``404``
568
+ for a private repository the caller cannot see, so refuse that
569
+ too, but only for a linked repo: a project-type fallback guess
570
+ carries no authority, so its ``404`` does not block.
571
+ """
572
+ host = self._resolve_host(ctx)
573
+ target = resolve_repository_target(
574
+ ctx, host, 'GitHub lifecycle plugin'
575
+ )
576
+ owner, repo = target.owner, target.repo
577
+ async with self._client(ctx, credentials) as client:
578
+ current = await self._get_repo_or_none(client, owner, repo)
579
+ if current is None:
580
+ if target.source != 'link':
581
+ return None
582
+ return (
583
+ f'The GitHub repository {owner}/{repo} is not accessible '
584
+ 'with your GitHub identity, so this project cannot be '
585
+ 'archived or restored'
586
+ )
587
+ perms = typing.cast(
588
+ dict[str, object] | None, current.get('permissions')
589
+ )
590
+ if perms is not None and not perms.get('admin'):
591
+ return (
592
+ 'You need admin access to the GitHub repository '
593
+ f'{current.get("full_name") or f"{owner}/{repo}"} '
594
+ 'to archive or restore this project'
595
+ )
596
+ return None
597
+
557
598
  async def on_project_archived(
558
599
  self,
559
600
  ctx: PluginContext,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: imbi-plugin-github
3
- Version: 2.47.0
3
+ Version: 2.49.0
4
4
  Summary: GitHub identity plugin for Imbi (github.com / GHEC / GHES)
5
5
  Author-email: "Gavin M. Roy" <gavinr@aweber.com>
6
6
  License-Expression: BSD-3-Clause
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.14
13
13
  Requires-Python: >=3.14
14
14
  Requires-Dist: httpx>=0.27
15
- Requires-Dist: imbi-common[databases]==2.47.0
15
+ Requires-Dist: imbi-common[databases]==2.49.0
16
16
  Requires-Dist: pydantic>=2
17
17
  Requires-Dist: pyjwt[crypto]>=2.8
18
18
  Description-Content-Type: text/markdown
@@ -3,16 +3,16 @@ imbi/plugins/github/__init__.py,sha256=L_5_kr22VkjJob6SVLVzCkIvnWddxi54GIrM2cNs2
3
3
  imbi/plugins/github/_app_auth.py,sha256=qr3azBExZSI0vDIIKMKV8nSllJNKCJLKBXV86lIp9jE,19015
4
4
  imbi/plugins/github/_hosts.py,sha256=sYuE3f7934125VZ6GGTqm8t3sVa3m0DNt3jL9Hb8nM0,4014
5
5
  imbi/plugins/github/_repos.py,sha256=BeSwrpzQnFBtlUGW-eP7v6_gAcSaSkqObq-vhj5wcYA,6575
6
- imbi/plugins/github/commits.py,sha256=wHs_NUl4cmhfvD3WrnOCmqaaJS-Eku-E-lOMh6Cb8IU,71882
7
- imbi/plugins/github/deployment.py,sha256=bC5qMvbO-N0f5DTNo7ObyZIUtN4cl8uyjHgpp57W5_Y,111242
6
+ imbi/plugins/github/commits.py,sha256=hS7m9Ia_WgmQUoapPONtU1xzFS0ip0H9SJlPNTVsvX0,72319
7
+ imbi/plugins/github/deployment.py,sha256=ZZI53-G2cMGSKlhFoZ4fB_D-hDtVYakE2p8hMuNc-kU,112722
8
8
  imbi/plugins/github/doctor.py,sha256=sIps9YyDFLva7JHyKJU0IkKSW8tiI-PArC0s1ytxv3w,33177
9
9
  imbi/plugins/github/identity.py,sha256=9t_e-_jUbQ1iL0Vb6vaK2d7bT1ki6pw9aWwc4ics6gI,10354
10
- imbi/plugins/github/lifecycle.py,sha256=KJSzB36zFqetQBY5HNXLsRGRoIwGhrBJ-I1mA8G9H_Q,37711
10
+ imbi/plugins/github/lifecycle.py,sha256=wxcsZJ9-cELzb8nmh7x-jwmJx3vQ_kj9-5uWCchYkyA,39451
11
11
  imbi/plugins/github/plugin.py,sha256=LDFCqj6e2jfF9io3U7cC0eVOUAxw1ENvFS-0AWOMuDc,16073
12
12
  imbi/plugins/github/public.py,sha256=GZnTLbj_Gl5sHWuRqFuajnoO2xPudNQumAt4h_uJpYw,3114
13
13
  imbi/plugins/github/pull_requests.py,sha256=DH9CnJoCpY5Ats5sZ_ktLvy54kBwK9g_-CDMlAIOq7Y,32553
14
14
  imbi/plugins/github/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  imbi/plugins/github/secret_provider.py,sha256=6o8-RK22CqoJxeLYFP_sm976anIR_2XR0FAGCfNrnkg,29447
16
- imbi_plugin_github-2.47.0.dist-info/METADATA,sha256=qMwJ18uHG1anxx2pzVF1wbGj6xVnMBs8I1vCYb2kRqU,8977
17
- imbi_plugin_github-2.47.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
18
- imbi_plugin_github-2.47.0.dist-info/RECORD,,
16
+ imbi_plugin_github-2.49.0.dist-info/METADATA,sha256=qmFimkg4HmMlsEJmX2F7VvpAKtBd8vz_h8XXAeaSbSw,8977
17
+ imbi_plugin_github-2.49.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
18
+ imbi_plugin_github-2.49.0.dist-info/RECORD,,