imbi-plugin-github 2.49.0__tar.gz → 2.50.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 (33) hide show
  1. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/PKG-INFO +2 -2
  2. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/pyproject.toml +2 -2
  3. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/commits.py +43 -44
  4. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/deployment.py +49 -0
  5. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_commits.py +27 -4
  6. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_deployment.py +41 -0
  7. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/.gitignore +0 -0
  8. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/README.md +0 -0
  9. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/moon.yml +0 -0
  10. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/README.md +0 -0
  11. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/__init__.py +0 -0
  12. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/_app_auth.py +0 -0
  13. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/_hosts.py +0 -0
  14. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/_repos.py +0 -0
  15. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/doctor.py +0 -0
  16. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/identity.py +0 -0
  17. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/lifecycle.py +0 -0
  18. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/plugin.py +0 -0
  19. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/public.py +0 -0
  20. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/pull_requests.py +0 -0
  21. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/py.typed +0 -0
  22. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/src/imbi/plugins/github/secret_provider.py +0 -0
  23. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/__init__.py +0 -0
  24. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_app_auth_scopes.py +0 -0
  25. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_doctor.py +0 -0
  26. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_hosts.py +0 -0
  27. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_identity.py +0 -0
  28. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_lifecycle.py +0 -0
  29. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_public.py +0 -0
  30. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_pull_requests.py +0 -0
  31. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_repos.py +0 -0
  32. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_secret_provider.py +0 -0
  33. {imbi_plugin_github-2.49.0 → imbi_plugin_github-2.50.0}/tests/test_secret_provider_live.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: imbi-plugin-github
3
- Version: 2.49.0
3
+ Version: 2.50.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.49.0
15
+ Requires-Dist: imbi-common[databases]==2.50.0
16
16
  Requires-Dist: pydantic>=2
17
17
  Requires-Dist: pyjwt[crypto]>=2.8
18
18
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "imbi-plugin-github"
3
- version = "2.49.0"
3
+ version = "2.50.0"
4
4
  description = "GitHub identity plugin for Imbi (github.com / GHEC / GHES)"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14"
@@ -18,7 +18,7 @@ classifiers = [
18
18
  ]
19
19
  dependencies = [
20
20
  "httpx>=0.27",
21
- "imbi-common[databases]==2.49.0",
21
+ "imbi-common[databases]==2.50.0",
22
22
  "pydantic>=2",
23
23
  "pyjwt[crypto]>=2.8",
24
24
  ]
@@ -599,8 +599,9 @@ async def _stored_pushed_at(
599
599
  rows = await clickhouse.query(
600
600
  'SELECT sha, min(pushed_at) AS pushed_at FROM commits '
601
601
  'WHERE project_id = {pid:String} '
602
- 'AND sha IN {shas:Array(String)} GROUP BY sha',
603
- {'pid': project_id, 'shas': wanted},
602
+ 'AND sha IN (SELECT id FROM shas) GROUP BY sha',
603
+ {'pid': project_id},
604
+ tables={'shas': wanted},
604
605
  )
605
606
  except Exception: # noqa: BLE001
606
607
  LOGGER.debug(
@@ -799,17 +800,21 @@ async def _fetch_default_branch(
799
800
  return str(meta.get('default_branch') or 'main')
800
801
 
801
802
 
802
- async def _fetch_all_commits(
803
- client: httpx.AsyncClient, branch: str, *, max_wait: float
803
+ async def _walk_commits(
804
+ client: httpx.AsyncClient,
805
+ params: dict[str, str],
806
+ max_pages: int,
807
+ truncated: str,
808
+ *,
809
+ max_wait: float,
804
810
  ) -> list[dict[str, typing.Any]]:
805
- """Walk every commit reachable from ``branch`` via Link pagination.
811
+ """Walk ``GET /commits`` with *params* via Link pagination.
806
812
 
807
- Capped at ``_MAX_HISTORY_PAGES`` (logged on truncation) so a very deep
808
- repo can't pin a one-shot backfill indefinitely.
813
+ Capped at *max_pages*; on truncation *truncated* is logged as a
814
+ warning with the page cap and the commit count.
809
815
  """
810
- params: dict[str, str] = {'sha': branch, 'per_page': '100'}
811
816
  out: list[dict[str, typing.Any]] = []
812
- for page in range(1, _MAX_HISTORY_PAGES + 1):
817
+ for page in range(1, max_pages + 1):
813
818
  resp = await _request(
814
819
  client, 'GET', '/commits', params=params, max_wait=max_wait
815
820
  )
@@ -832,16 +837,29 @@ async def _fetch_all_commits(
832
837
  if next_page is None:
833
838
  return out
834
839
  params['page'] = next_page
835
- if page == _MAX_HISTORY_PAGES:
836
- LOGGER.warning(
837
- 'github-commit-sync truncated history at %d pages (%d '
838
- 'commits); older commits will not be recorded',
839
- _MAX_HISTORY_PAGES,
840
- len(out),
841
- )
840
+ if page == max_pages:
841
+ LOGGER.warning(truncated, max_pages, len(out))
842
842
  return out
843
843
 
844
844
 
845
+ async def _fetch_all_commits(
846
+ client: httpx.AsyncClient, branch: str, *, max_wait: float
847
+ ) -> list[dict[str, typing.Any]]:
848
+ """Walk every commit reachable from ``branch`` via Link pagination.
849
+
850
+ Capped at ``_MAX_HISTORY_PAGES`` (logged on truncation) so a very deep
851
+ repo can't pin a one-shot backfill indefinitely.
852
+ """
853
+ return await _walk_commits(
854
+ client,
855
+ {'sha': branch, 'per_page': '100'},
856
+ _MAX_HISTORY_PAGES,
857
+ 'github-commit-sync truncated history at %d pages (%d '
858
+ 'commits); older commits will not be recorded',
859
+ max_wait=max_wait,
860
+ )
861
+
862
+
845
863
  async def _fetch_tag_ref(
846
864
  client: httpx.AsyncClient, name: str, *, max_wait: float
847
865
  ) -> tuple[str, str] | None:
@@ -886,34 +904,15 @@ async def _fetch_commits_since(
886
904
  :data:`_MAX_SINCE_PAGES` for the pathological case of a window wide
887
905
  enough to cover thousands of commits.
888
906
  """
889
- params: dict[str, str] = {
890
- 'sha': branch,
891
- 'since': since.isoformat(),
892
- 'per_page': '100',
893
- }
894
- out: list[dict[str, typing.Any]] = []
895
- for page in range(1, _MAX_SINCE_PAGES + 1):
896
- resp = await _request(
897
- client, 'GET', '/commits', params=params, max_wait=max_wait
898
- )
899
- resp.raise_for_status()
900
- out.extend(typing.cast('list[dict[str, typing.Any]]', resp.json()))
901
- next_url = _next_page_url(resp.headers.get('link'))
902
- if next_url is None:
903
- return out
904
- next_page = _query_param(next_url, 'page')
905
- if next_page is None:
906
- return out
907
- params['page'] = next_page
908
- if page == _MAX_SINCE_PAGES:
909
- LOGGER.warning(
910
- 'github-commit-sync truncated the since-window walk at %d '
911
- 'pages (%d commits); widen the stored history with a full '
912
- 'sync instead',
913
- _MAX_SINCE_PAGES,
914
- len(out),
915
- )
916
- return out
907
+ return await _walk_commits(
908
+ client,
909
+ {'sha': branch, 'since': since.isoformat(), 'per_page': '100'},
910
+ _MAX_SINCE_PAGES,
911
+ 'github-commit-sync truncated the since-window walk at %d '
912
+ 'pages (%d commits); widen the stored history with a full '
913
+ 'sync instead',
914
+ max_wait=max_wait,
915
+ )
917
916
 
918
917
 
919
918
  async def _publish_best_effort(
@@ -1936,6 +1936,55 @@ class GitHubDeployment(DeploymentCapability):
1936
1936
  else None,
1937
1937
  )
1938
1938
 
1939
+ async def find_deployments(
1940
+ self,
1941
+ ctx: PluginContext,
1942
+ credentials: dict[str, str],
1943
+ ref_or_sha: str,
1944
+ since: datetime.datetime,
1945
+ ) -> list[DeploymentRun]:
1946
+ """Find deployments via ``GET /deployments?environment=&ref=``.
1947
+
1948
+ GitHub lists them newest first, so one page of 100 holds every
1949
+ deployment of one ref and environment in the window the host
1950
+ asks about. Each match gets its status from
1951
+ :meth:`get_deployment_status`, with ``started_at`` set to when
1952
+ GitHub made the deployment.
1953
+ """
1954
+ if not ctx.environment:
1955
+ raise ValueError(
1956
+ 'find_deployments requires PluginContext.environment'
1957
+ )
1958
+ async with self._client(
1959
+ ctx, credentials, SCOPE_DEPLOYMENTS_READ
1960
+ ) as client:
1961
+ resp = await client.get(
1962
+ '/deployments',
1963
+ params={
1964
+ 'environment': ctx.environment,
1965
+ 'ref': ref_or_sha,
1966
+ 'per_page': '100',
1967
+ },
1968
+ )
1969
+ resp.raise_for_status()
1970
+ found = typing.cast(list[dict[str, typing.Any]], resp.json())
1971
+ matches = [
1972
+ (str(d['id']), created)
1973
+ for d in found
1974
+ if (created := _parse_iso(d.get('created_at'))) is not None
1975
+ and created >= since
1976
+ ]
1977
+ runs = await asyncio.gather(
1978
+ *(
1979
+ self.get_deployment_status(ctx, credentials, run_id)
1980
+ for run_id, _ in matches
1981
+ )
1982
+ )
1983
+ return [
1984
+ run.model_copy(update={'started_at': created})
1985
+ for run, (_, created) in zip(runs, matches, strict=True)
1986
+ ]
1987
+
1939
1988
  async def list_recent_deployments(
1940
1989
  self,
1941
1990
  ctx: PluginContext,
@@ -134,14 +134,15 @@ def _query_router(
134
134
  """
135
135
 
136
136
  async def _answer(
137
- sql: str, params: dict[str, typing.Any] | None = None
137
+ sql: str,
138
+ params: dict[str, typing.Any] | None = None,
139
+ tables: dict[str, list[str]] | None = None,
138
140
  ) -> list[dict[str, typing.Any]]:
139
- params = params or {}
140
141
  if 'min(pushed_at)' in sql:
141
142
  return [
142
143
  {'sha': sha, 'pushed_at': pushed_at}
143
144
  for sha, pushed_at in (stored or {}).items()
144
- if sha in params.get('shas', ())
145
+ if sha in (tables or {}).get('shas', ())
145
146
  ]
146
147
  if 'argMax(sha, pushed_at)' in sql:
147
148
  return [{'sha': last_known}] if last_known else []
@@ -457,7 +458,7 @@ class SyncCommitsTestCase(unittest.IsolatedAsyncioTestCase):
457
458
  lookup = next(
458
459
  c for c in query.await_args_list if 'min(pushed_at)' in c.args[0]
459
460
  )
460
- self.assertEqual([head], lookup.args[1]['shas'])
461
+ self.assertEqual([head], lookup.kwargs['tables']['shas'])
461
462
 
462
463
  @respx.mock
463
464
  async def test_only_new_commits_get_the_current_push_time(self) -> None:
@@ -2362,6 +2363,28 @@ class SyncNewCommitsTestCase(unittest.IsolatedAsyncioTestCase):
2362
2363
  self.assertEqual(since.isoformat(), params['since'])
2363
2364
  self.assertEqual('main', params['sha'])
2364
2365
 
2366
+ @respx.mock
2367
+ async def test_since_window_deep_page_404_keeps_read(self) -> None:
2368
+ """#686: GHES 404s a deep since-window page; keep what was read."""
2369
+ self._mock_default_branch()
2370
+ url = f'{self._REPO}/commits'
2371
+ respx.get(url).mock(
2372
+ side_effect=[
2373
+ httpx.Response(
2374
+ 200,
2375
+ json=[_commit('c' * 40)],
2376
+ headers={'link': f'<{url}?page=2>; rel="next"'},
2377
+ ),
2378
+ httpx.Response(404, json={'message': 'Not Found'}),
2379
+ ]
2380
+ )
2381
+ since = datetime.datetime(2026, 8, 4, 12, 0, tzinfo=datetime.UTC)
2382
+ with mock.patch(_QUERY, new=mock.AsyncMock(return_value=[])):
2383
+ with self.assertLogs(commits.LOGGER, level='WARNING') as cm:
2384
+ written, _ = await self._sync(since=since)
2385
+ self.assertEqual(1, written)
2386
+ self.assertTrue(any('page 2' in x for x in cm.output))
2387
+
2365
2388
  @respx.mock
2366
2389
  async def test_recent_page_when_no_sha_and_no_since(self) -> None:
2367
2390
  self._mock_default_branch()
@@ -1152,6 +1152,47 @@ class GetDeploymentStatusTestCase(unittest.IsolatedAsyncioTestCase):
1152
1152
  self.assertIsNone(run.completed_at)
1153
1153
 
1154
1154
 
1155
+ class FindDeploymentsTestCase(unittest.IsolatedAsyncioTestCase):
1156
+ @respx.mock
1157
+ async def test_keeps_deployments_made_since(self) -> None:
1158
+ listing = respx.get(
1159
+ 'https://api.github.com/repos/octo/demo/deployments',
1160
+ params={'environment': 'staging', 'ref': '1.2.0'},
1161
+ ).mock(
1162
+ return_value=httpx.Response(
1163
+ 200,
1164
+ json=[
1165
+ _deployment(2, '2026-01-01T00:05:00Z'),
1166
+ _deployment(1, '2026-01-01T00:00:00Z'),
1167
+ ],
1168
+ )
1169
+ )
1170
+ _statuses('success', 'success')
1171
+ runs = await GitHubDeployment().find_deployments(
1172
+ _ctx(environment='staging'),
1173
+ _CREDS,
1174
+ '1.2.0',
1175
+ datetime.datetime(2026, 1, 1, 0, 1, tzinfo=datetime.UTC),
1176
+ )
1177
+ self.assertTrue(listing.called)
1178
+ self.assertEqual(
1179
+ [(r.run_id, r.status, r.started_at) for r in runs],
1180
+ [
1181
+ (
1182
+ '2',
1183
+ 'success',
1184
+ datetime.datetime(2026, 1, 1, 0, 5, tzinfo=datetime.UTC),
1185
+ )
1186
+ ],
1187
+ )
1188
+
1189
+ async def test_needs_an_environment(self) -> None:
1190
+ with self.assertRaises(ValueError):
1191
+ await GitHubDeployment().find_deployments(
1192
+ _ctx(), _CREDS, '1.2.0', datetime.datetime.now(datetime.UTC)
1193
+ )
1194
+
1195
+
1155
1196
  class ListRecentDeploymentsTestCase(unittest.IsolatedAsyncioTestCase):
1156
1197
  @respx.mock
1157
1198
  async def test_app_credentials_mint_installation_token(self) -> None: