imbi-plugin-github 2.59.0__tar.gz → 2.61.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.59.0 → imbi_plugin_github-2.61.0}/PKG-INFO +2 -2
  2. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/pyproject.toml +2 -2
  3. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/public.py +11 -11
  4. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_commits.py +10 -15
  5. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_lifecycle.py +12 -9
  6. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_public.py +22 -9
  7. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/.gitignore +0 -0
  8. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/README.md +0 -0
  9. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/moon.yml +0 -0
  10. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/README.md +0 -0
  11. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/__init__.py +0 -0
  12. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/_app_auth.py +0 -0
  13. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/_hosts.py +0 -0
  14. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/_repos.py +0 -0
  15. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/commits.py +0 -0
  16. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/deployment.py +0 -0
  17. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/doctor.py +0 -0
  18. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/identity.py +0 -0
  19. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/lifecycle.py +0 -0
  20. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/plugin.py +0 -0
  21. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/pull_requests.py +0 -0
  22. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/py.typed +0 -0
  23. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/src/imbi/plugins/github/secret_provider.py +0 -0
  24. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/__init__.py +0 -0
  25. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_app_auth_scopes.py +0 -0
  26. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_deployment.py +0 -0
  27. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_doctor.py +0 -0
  28. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_hosts.py +0 -0
  29. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_identity.py +0 -0
  30. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_pull_requests.py +0 -0
  31. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_repos.py +0 -0
  32. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.0}/tests/test_secret_provider.py +0 -0
  33. {imbi_plugin_github-2.59.0 → imbi_plugin_github-2.61.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.59.0
3
+ Version: 2.61.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.59.0
15
+ Requires-Dist: imbi-common[databases]==2.61.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.59.0"
3
+ version = "2.61.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.59.0",
21
+ "imbi-common[databases]==2.61.0",
22
22
  "pydantic>=2",
23
23
  "pyjwt[crypto]>=2.8",
24
24
  ]
@@ -22,10 +22,12 @@ class PublicRepository:
22
22
  """The :class:`~imbi.common.plugins.base.RepositoryReader` of a public
23
23
  ``github.com`` repository. It ignores ``ctx`` and ``credentials``."""
24
24
 
25
- # ponytail: 60 unauthenticated requests an hour per API pod IP; use
26
- # an org token if many public marketplaces sync often.
25
+ # ponytail: 60 unauthenticated API requests an hour per API pod IP
26
+ # for the refs; use an org token if many public marketplaces sync
27
+ # often.
27
28
  def __init__(self, owner: str, repo: str) -> None:
28
29
  self.base = f'https://api.github.com/repos/{owner}/{repo}'
30
+ self.raw = f'https://raw.githubusercontent.com/{owner}/{repo}'
29
31
 
30
32
  @classmethod
31
33
  def for_url(cls, url: str) -> PublicRepository | None:
@@ -37,21 +39,21 @@ class PublicRepository:
37
39
  return None
38
40
  return cls(*path.split('/'))
39
41
 
40
- async def _get(
41
- self, path: str, accept: str = 'application/vnd.github+json'
42
- ) -> httpx.Response:
42
+ async def _get(self, url: str) -> httpx.Response:
43
43
  # A renamed or moved repository answers 301 to /repositories/{id}.
44
44
  async with httpx.AsyncClient(
45
45
  timeout=30, follow_redirects=True
46
46
  ) as client:
47
47
  return await client.get(
48
- f'{self.base}{path}', headers={'Accept': accept}
48
+ url, headers={'Accept': 'application/vnd.github+json'}
49
49
  )
50
50
 
51
51
  async def resolve_committish(
52
52
  self, _ctx: object, _credentials: object, ref: str, /
53
53
  ) -> base.Ref:
54
- response = await self._get(f'/commits/{urllib.parse.quote(ref)}')
54
+ response = await self._get(
55
+ f'{self.base}/commits/{urllib.parse.quote(ref)}'
56
+ )
55
57
  response.raise_for_status()
56
58
  return base.Ref(name=ref, kind='branch', sha=response.json()['sha'])
57
59
 
@@ -64,7 +66,7 @@ class PublicRepository:
64
66
  ) -> list[base.Ref]:
65
67
  """Return the default branch only, whatever ``kind`` is."""
66
68
  del kind
67
- response = await self._get('')
69
+ response = await self._get(self.base)
68
70
  response.raise_for_status()
69
71
  branch = str(response.json()['default_branch'])
70
72
  ref = await self.resolve_committish(None, None, branch)
@@ -74,9 +76,7 @@ class PublicRepository:
74
76
  self, _ctx: object, _credentials: object, path: str, ref: str, /
75
77
  ) -> str | None:
76
78
  response = await self._get(
77
- f'/contents/{urllib.parse.quote(path)}?'
78
- f'{urllib.parse.urlencode({"ref": ref})}',
79
- 'application/vnd.github.raw+json',
79
+ f'{self.raw}/{urllib.parse.quote(ref)}/{urllib.parse.quote(path)}'
80
80
  )
81
81
  if response.status_code == 404:
82
82
  return None
@@ -2553,9 +2553,8 @@ class RequestTestCase(unittest.IsolatedAsyncioTestCase):
2553
2553
  httpx.Response(403, headers={'retry-after': '7'}),
2554
2554
  httpx.Response(200, json={'ok': True}),
2555
2555
  )
2556
- with mock.patch.object(
2557
- commits.asyncio, 'sleep', new=mock.AsyncMock()
2558
- ) as slept:
2556
+ slept = mock.AsyncMock()
2557
+ with mock.patch.object(commits, 'asyncio', wraps=asyncio, sleep=slept):
2559
2558
  resp = await commits._request(client, 'GET', '/x', max_wait=60.0)
2560
2559
  self.assertEqual(200, resp.status_code)
2561
2560
  slept.assert_awaited_once_with(7.0)
@@ -2573,9 +2572,8 @@ class RequestTestCase(unittest.IsolatedAsyncioTestCase):
2573
2572
  json={'ok': True},
2574
2573
  ),
2575
2574
  )
2576
- with mock.patch.object(
2577
- commits.asyncio, 'sleep', new=mock.AsyncMock()
2578
- ) as slept:
2575
+ slept = mock.AsyncMock()
2576
+ with mock.patch.object(commits, 'asyncio', wraps=asyncio, sleep=slept):
2579
2577
  resp = await commits._request(client, 'GET', '/x', max_wait=60.0)
2580
2578
  self.assertEqual(200, resp.status_code)
2581
2579
  slept.assert_awaited_once()
@@ -2593,9 +2591,8 @@ class RequestTestCase(unittest.IsolatedAsyncioTestCase):
2593
2591
  },
2594
2592
  ),
2595
2593
  )
2596
- with mock.patch.object(
2597
- commits.asyncio, 'sleep', new=mock.AsyncMock()
2598
- ) as slept:
2594
+ slept = mock.AsyncMock()
2595
+ with mock.patch.object(commits, 'asyncio', wraps=asyncio, sleep=slept):
2599
2596
  with self.assertRaises(PluginRateLimited) as caught:
2600
2597
  await commits._request(client, 'GET', '/x', max_wait=60.0)
2601
2598
  # Bails to the host without sleeping, carrying the resume time.
@@ -2607,9 +2604,8 @@ class RequestTestCase(unittest.IsolatedAsyncioTestCase):
2607
2604
  client = self._client(
2608
2605
  httpx.Response(429, headers={'retry-after': '1'})
2609
2606
  )
2610
- with mock.patch.object(
2611
- commits.asyncio, 'sleep', new=mock.AsyncMock()
2612
- ) as slept:
2607
+ slept = mock.AsyncMock()
2608
+ with mock.patch.object(commits, 'asyncio', wraps=asyncio, sleep=slept):
2613
2609
  with self.assertRaises(PluginRateLimited):
2614
2610
  await commits._request(client, 'GET', '/x', max_wait=60.0)
2615
2611
  self.assertEqual(commits._MAX_THROTTLE_RETRIES, slept.await_count)
@@ -2631,9 +2627,8 @@ class SyncCommitsThrottleTestCase(unittest.IsolatedAsyncioTestCase):
2631
2627
  httpx.Response(200, json={'commits': [_commit('1' * 40)]}),
2632
2628
  ]
2633
2629
  )
2634
- with mock.patch.object(
2635
- commits.asyncio, 'sleep', new=mock.AsyncMock()
2636
- ) as slept:
2630
+ slept = mock.AsyncMock()
2631
+ with mock.patch.object(commits, 'asyncio', wraps=asyncio, sleep=slept):
2637
2632
  with mock.patch(_INSERT, new=mock.AsyncMock()) as insert:
2638
2633
  await commits.sync_commits(
2639
2634
  ctx=_ctx(),
@@ -267,8 +267,9 @@ class ArchiveTestCase(unittest.IsolatedAsyncioTestCase):
267
267
 
268
268
  plugin = GitHubLifecycle()
269
269
  with unittest.mock.patch(
270
- 'imbi.plugins.github.lifecycle.asyncio.sleep'
271
- ) as sleep:
270
+ 'imbi.plugins.github.lifecycle.asyncio',
271
+ sleep=unittest.mock.AsyncMock(),
272
+ ) as asyncio_mod:
272
273
  result = await plugin.on_project_archived(
273
274
  _ctx(options={'archive_target_org': 'octo-archive'}),
274
275
  _CREDS,
@@ -277,7 +278,7 @@ class ArchiveTestCase(unittest.IsolatedAsyncioTestCase):
277
278
  self.assertEqual(result.status, 'ok')
278
279
  self.assertEqual(archive_route.calls.call_count, 3)
279
280
  # Two failed attempts → two backoff sleeps before success.
280
- self.assertEqual(sleep.await_count, 2)
281
+ self.assertEqual(asyncio_mod.sleep.await_count, 2)
281
282
 
282
283
  @respx.mock
283
284
  async def test_archive_transfer_exhausts_retries_on_persistent_404(
@@ -307,8 +308,9 @@ class ArchiveTestCase(unittest.IsolatedAsyncioTestCase):
307
308
 
308
309
  plugin = GitHubLifecycle()
309
310
  with unittest.mock.patch(
310
- 'imbi.plugins.github.lifecycle.asyncio.sleep'
311
- ) as sleep:
311
+ 'imbi.plugins.github.lifecycle.asyncio',
312
+ sleep=unittest.mock.AsyncMock(),
313
+ ) as asyncio_mod:
312
314
  with self.assertRaises(httpx.HTTPStatusError):
313
315
  await plugin.on_project_archived(
314
316
  _ctx(options={'archive_target_org': 'octo-archive'}),
@@ -317,7 +319,7 @@ class ArchiveTestCase(unittest.IsolatedAsyncioTestCase):
317
319
 
318
320
  # Three backoffs configured → four total attempts.
319
321
  self.assertEqual(archive_route.calls.call_count, 4)
320
- self.assertEqual(sleep.await_count, 3)
322
+ self.assertEqual(asyncio_mod.sleep.await_count, 3)
321
323
 
322
324
  @respx.mock
323
325
  async def test_archive_transfer_does_not_retry_non_404(self) -> None:
@@ -344,8 +346,9 @@ class ArchiveTestCase(unittest.IsolatedAsyncioTestCase):
344
346
 
345
347
  plugin = GitHubLifecycle()
346
348
  with unittest.mock.patch(
347
- 'imbi.plugins.github.lifecycle.asyncio.sleep'
348
- ) as sleep:
349
+ 'imbi.plugins.github.lifecycle.asyncio',
350
+ sleep=unittest.mock.AsyncMock(),
351
+ ) as asyncio_mod:
349
352
  with self.assertRaises(httpx.HTTPStatusError):
350
353
  await plugin.on_project_archived(
351
354
  _ctx(options={'archive_target_org': 'octo-archive'}),
@@ -353,7 +356,7 @@ class ArchiveTestCase(unittest.IsolatedAsyncioTestCase):
353
356
  )
354
357
 
355
358
  self.assertEqual(archive_route.calls.call_count, 1)
356
- self.assertEqual(sleep.await_count, 0)
359
+ self.assertEqual(asyncio_mod.sleep.await_count, 0)
357
360
 
358
361
  @respx.mock
359
362
  async def test_archive_transfer_when_already_archived(self) -> None:
@@ -9,6 +9,7 @@ from imbi.plugins.github import deployment, public
9
9
 
10
10
  SHA = 'a' * 40
11
11
  API = 'https://api.github.com/repos/anthropics/plugins'
12
+ RAW = 'https://raw.githubusercontent.com/anthropics/plugins'
12
13
 
13
14
 
14
15
  class PublicRepositoryTests(unittest.IsolatedAsyncioTestCase):
@@ -30,13 +31,10 @@ class PublicRepositoryTests(unittest.IsolatedAsyncioTestCase):
30
31
  async def test_reads_without_credentials(self) -> None:
31
32
  respx.get(API).respond(json={'default_branch': 'main'})
32
33
  commit = respx.get(f'{API}/commits/main').respond(json={'sha': SHA})
33
- respx.get(
34
- f'{API}/contents/.claude-plugin/marketplace.json',
35
- params={'ref': SHA},
34
+ file = respx.get(
35
+ f'{RAW}/{SHA}/.claude-plugin/marketplace.json'
36
36
  ).respond(text='{}')
37
- respx.get(f'{API}/contents/missing.json', params={'ref': SHA}).respond(
38
- 404
39
- )
37
+ respx.get(f'{RAW}/{SHA}/missing.json').respond(404)
40
38
  reader = public.PublicRepository('anthropics', 'plugins')
41
39
 
42
40
  refs = await reader.list_refs(None, {}, kind='default')
@@ -52,12 +50,13 @@ class PublicRepositoryTests(unittest.IsolatedAsyncioTestCase):
52
50
  '{}',
53
51
  )
54
52
  self.assertIsNone(await reader.get_file(None, {}, 'missing.json', SHA))
53
+ self.assertNotIn('authorization', file.calls.last.request.headers)
55
54
 
56
55
  @respx.mock
57
56
  async def test_get_file_encodes_the_ref(self) -> None:
58
- route = respx.get(
59
- f'{API}/contents/a.json', params={'ref': 'release&candidate'}
60
- ).respond(text='{}')
57
+ route = respx.get(f'{RAW}/release%26candidate/a.json').respond(
58
+ text='{}'
59
+ )
61
60
  reader = public.PublicRepository('anthropics', 'plugins')
62
61
  self.assertEqual(
63
62
  await reader.get_file(None, {}, 'a.json', 'release&candidate'),
@@ -65,6 +64,20 @@ class PublicRepositoryTests(unittest.IsolatedAsyncioTestCase):
65
64
  )
66
65
  self.assertTrue(route.called)
67
66
 
67
+ @respx.mock
68
+ async def test_get_file_encodes_the_path(self) -> None:
69
+ route = respx.get(f'{RAW}/{SHA}/my%20plugin/.mcp.json').respond(
70
+ text='{}'
71
+ )
72
+ reader = public.PublicRepository('anthropics', 'plugins')
73
+ self.assertEqual(
74
+ await reader.get_file(None, {}, 'my plugin/.mcp.json', SHA), '{}'
75
+ )
76
+ self.assertEqual(
77
+ route.calls.last.request.url.raw_path,
78
+ f'/anthropics/plugins/{SHA}/my%20plugin/.mcp.json'.encode(),
79
+ )
80
+
68
81
 
69
82
  class WebhookSignatureTests(unittest.TestCase):
70
83
  def test_signature_is_the_webhook_secret(self) -> None: