Skip to content

Commit 7cdca71

Browse files
authored
Merge pull request #1086 from pettermk/main
Add function for getting repos for github app
2 parents 8ec8f0a + 1ec840b commit 7cdca71

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,5 @@ Contributors
214214
- Greg Gilbert (@greggilbert)
215215

216216
- Philipp Heil (@zkdev)
217+
218+
- Petter Kvalvaag (@pettermk)

src/github3/github.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,35 @@ def app_installation_for_user(self, user):
383383
)
384384
return self._instance_or_null(apps.Installation, json)
385385

386+
@decorators.requires_app_installation_auth
387+
def app_installation_repos(self, number=-1, etag=None):
388+
"""Retrieve repositories accessible by app installation.
389+
390+
.. versionadded:: 3.2.1
391+
392+
.. seealso::
393+
394+
`List repositories accessible to the app installation`_
395+
API Documentation
396+
397+
:returns:
398+
The repositories accessible to the app installation
399+
:rtype:
400+
:class:`~github3.repos.repo.ShortRepository`
401+
402+
.. _List repositories accessible to the app installation:
403+
https://docs.github.com/en/rest/apps/installations#list-repositories-accessible-to-the-app-installation
404+
"""
405+
url = self._build_url("installation", "repositories")
406+
return self._iter(
407+
count=int(number),
408+
url=url,
409+
cls=repo.ShortRepository,
410+
params=None,
411+
etag=etag,
412+
list_key="repositories",
413+
)
414+
386415
@decorators.requires_app_bearer_auth
387416
def authenticated_app(self):
388417
"""Retrieve information about the current app.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"response": {"url": "https://api.github.com/installation/repositories?per_page=100", "status": {"code": 200, "message": "OK"}, "body": {"base64_string": "H4sIAAAAAAAAA9Way27rNhCGX8XQtnYk+ZKTCChO+wTdpJsWhUHLtEVEEgWKcuAIeffOkLpZoWyLchfdnGPL/D+OSA45/JG/S4ftneDFX7+ufM+fOylJqBM4yXmR0o+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XfgE9/jvF+nunQBv5SDK86gV/dZKAoOxUEnCGBZhL0vu6+vUP5uuyyC8iCc0g7pAWws5+4RP4Ft0TviQFymMLTz8IBJKTThR20d1VeAEKaQT4Ei+1XnqBFIUeGmDJ+0e0Hn4wd5ZtxFGkTf3MH2dajtKmBC8MlJ0VzyjadVXJyB9k8JoO79fRK++7OmBFLHc6qIXDSCSS3URzahI4A3gmIdgSqe6kup3wTVSh4zbh/789TXXrtLmxX9+fVk3phLGspURw4L4wlJSvs8qO6t7X93iu6VUNwM5ej/+j5elv3m2NJUq9RRTqRPPjat4p+U4Y6kzMpUfhWM3ylrqISaZSw1rmr3UYB5oMLXMrjcFozXeYmpQo02mRqkOLuj8npsyXl3BRWm0DzKaOrFcuFQQVWU1/dEx3+DpAyynzlprE/nScvpd+U3QFxfnmeQzNJNnmPewMGf8oJb3SP/J2KveMO+xr77Lx/tPBsZ0/8kAfZj/ZGCP958MEGv/ycB6hP9kwFr6TwbSVP/JgJzkPxl4o/0nAwO2pin+0wDR3n8aAFr6TwO0Cf6TgTjRfzIQJ/hPBto0/8kA7HpYeLaM9J8MxA6iBd7vPw0TFQOQY8wiA61vFEHWQB1+v6VlQGLi9bG1v3OXa2Bgmvyh8f6TAfwo/8mAnug/GYnKvprmPxm4Vv6TgfMg/8lAtvSfDKQp/pMBN9V/MiAf5T8Z0P+J/2ToZ5L/ZOBN9Z8MyOv+E5pPC3/z5i2DtResVib/ab3w/cVy/eatAv812KyxTc9/2mATz0cby/8ReMtb/tP3OG/6T4OSW/7ToDC/6j99l8Frt/6TdnW0A+V7r/9XD2qjL3RgHvU9KPildtCsPKjqryCGTKh//gUm1zlH3CQAAA==", "encoding": "utf-8", "string": ""}, "headers": {"X-GitHub-Request-Id": "AA6C:551F:22CC15E:2BFE670:589E3E01", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "X-Content-Type-Options": "nosniff", "Cache-Control": "private, max-age=60, s-maxage=60", "X-RateLimit-Reset": "1486769170", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Date": "Fri, 10 Feb 2017 22:26:10 GMT", "Content-Type": "application/json; charset=utf-8", "Transfer-Encoding": "chunked", "X-XSS-Protection": "1; mode=block", "Content-Security-Policy": "default-src 'none'", "X-Served-By": "9e60649f02cd840ee8baa9960690f79f", "ETag": "W/\"76db007ba542433cdc6420dc03a50839\"", "Server": "GitHub.com", "X-Frame-Options": "deny", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "Access-Control-Allow-Origin": "*", "Status": "200 OK", "Content-Encoding": "gzip", "X-RateLimit-Limit": "5000", "X-RateLimit-Remaining": "4999", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP"}}, "request": {"method": "GET", "uri": "https://api.github.com/installation/repositories?per_page=100", "body": {"encoding": "utf-8", "string": ""}, "headers": {"Content-Type": "application/json", "Accept": "application/vnd.github.v3.full+json", "Connection": "keep-alive", "Accept-Encoding": "gzip, deflate", "Authorization": "Basic <BASIC_AUTH>", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8"}}, "recorded_at": "2017-02-10T22:26:10"}], "recorded_with": "betamax/0.8.0"}

tests/integration/test_github.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ def test_authenticated_app(self):
6868

6969
assert isinstance(app, github3.apps.App)
7070

71+
def test_app_installation_repos(self):
72+
"""Validate an app can retrieve its repositories."""
73+
cassette_name = self.cassette_name("app_installation_repos")
74+
with self.recorder.use_cassette(cassette_name):
75+
self.app_installation_login()
76+
77+
for r in self.gh.app_installation_repos(number=100):
78+
assert isinstance(r, github3.repos.ShortRepository)
79+
7180
def test_authorize(self):
7281
"""Test the ability to create an authorization."""
7382
from ..conftest import credentials

0 commit comments

Comments
 (0)