|
1 | 1 | import asyncio |
2 | | -import ssl |
3 | 2 |
|
4 | 3 | import aiohttp |
5 | 4 | import asyncclick as click |
6 | | -import certifi |
7 | 5 |
|
8 | | -from github_deploy.commands._constants import BASE_URL, REPOS_URL |
| 6 | +from github_deploy.commands._constants import BASE_URL |
| 7 | +from github_deploy.commands._http_utils import delete, get, list_repos |
9 | 8 | from github_deploy.commands._utils import get_repo |
10 | 9 |
|
11 | 10 |
|
12 | | -async def get(*, session, url, headers=None, skip_missing=False): |
13 | | - ssl_context = ssl.create_default_context(cafile=certifi.where()) |
14 | | - |
15 | | - async with session.get( |
16 | | - url, |
17 | | - headers=headers, |
18 | | - timeout=70, |
19 | | - ssl_context=ssl_context, |
20 | | - raise_for_status=not skip_missing, |
21 | | - ) as response: |
22 | | - if skip_missing and response.status == 404: |
23 | | - return {} |
24 | | - |
25 | | - value = await response.json() |
26 | | - return value |
27 | | - |
28 | | - |
29 | | -async def delete(*, session, url, data, headers=None): |
30 | | - ssl_context = ssl.create_default_context(cafile=certifi.where()) |
31 | | - |
32 | | - async with session.delete( |
33 | | - url, |
34 | | - json=data, |
35 | | - headers=headers, |
36 | | - timeout=70, |
37 | | - ssl_context=ssl_context, |
38 | | - raise_for_status=True, |
39 | | - ) as response: |
40 | | - value = await response.json() |
41 | | - return value |
42 | | - |
43 | | - |
44 | 11 | async def delete_content( |
45 | 12 | *, |
46 | 13 | session, |
@@ -135,17 +102,6 @@ async def handle_file_delete(*, repo, dest, token, semaphore, session): |
135 | 102 | ) |
136 | 103 |
|
137 | 104 |
|
138 | | -async def list_repos(*, session, org, token): |
139 | | - headers = { |
140 | | - "Authorization": "token {token}".format(token=token), |
141 | | - "Accept": "application/vnd.github.v3+json", |
142 | | - } |
143 | | - url = REPOS_URL.format(org=org) |
144 | | - click.echo("Retrieving repos at {}".format(url)) |
145 | | - response = await get(session=session, url=url, headers=headers) |
146 | | - return response |
147 | | - |
148 | | - |
149 | 105 | @click.command() |
150 | 106 | @click.option( |
151 | 107 | "--org", |
|
0 commit comments