Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: Fixed lint errors. #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github_deploy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
2 changes: 1 addition & 1 deletion github_deploy/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
64 changes: 64 additions & 0 deletions github_deploy/commands/_http_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import ssl
import certifi

import asyncclick as click

from github_deploy.commands._constants import REPOS_URL


async def get(*, session, url, headers=None, skip_missing=False):
ssl_context = ssl.create_default_context(cafile=certifi.where())

async with session.get(
url,
headers=headers,
timeout=70,
ssl_context=ssl_context,
raise_for_status=not skip_missing,
) as response:
if skip_missing and response.status == 404:
return {}

value = await response.json()
return value


async def put(*, session, url, data, headers=None):
ssl_context = ssl.create_default_context(cafile=certifi.where())

async with session.put(
url,
json=data,
headers=headers,
timeout=70,
ssl_context=ssl_context,
raise_for_status=True,
) as response:
value = await response.json()
return value


async def delete(*, session, url, data, headers=None):
ssl_context = ssl.create_default_context(cafile=certifi.where())

async with session.delete(
url,
json=data,
headers=headers,
timeout=70,
ssl_context=ssl_context,
raise_for_status=True,
) as response:
value = await response.json()
return value


async def list_repos(*, session, org, token):
headers = {
"Authorization": "token {token}".format(token=token),
"Accept": "application/vnd.github.v3+json",
}
url = REPOS_URL.format(org=org)
click.echo("Retrieving repos at {}".format(url))
response = await get(session=session, url=url, headers=headers)
return response
6 changes: 5 additions & 1 deletion github_deploy/commands/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ def get_repo(*, org, project):


def can_upload(*, repo, include_private):
return True if include_private and repo['private'] == True else not repo['private']
return (
True
if include_private and repo["private"] is True
else not repo["private"]
)
78 changes: 22 additions & 56 deletions github_deploy/commands/delete.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
import asyncio
import ssl

import aiohttp
import asyncclick as click
import certifi

from github_deploy.commands._constants import BASE_URL, REPOS_URL
from github_deploy.commands._constants import BASE_URL
from github_deploy.commands._http_utils import delete, get, list_repos
from github_deploy.commands._utils import get_repo


async def get(*, session, url, headers=None, skip_missing=False):
ssl_context = ssl.create_default_context(cafile=certifi.where())

async with session.get(
url,
headers=headers,
timeout=70,
ssl_context=ssl_context,
raise_for_status=not skip_missing,
) as response:
if skip_missing and response.status == 404:
return {}

value = await response.json()
return value


async def delete(*, session, url, data, headers=None):
ssl_context = ssl.create_default_context(cafile=certifi.where())

async with session.delete(
url,
json=data,
headers=headers,
timeout=70,
ssl_context=ssl_context,
raise_for_status=True,
) as response:
value = await response.json()
return value


async def delete_content(
*,
session,
Expand All @@ -63,7 +30,9 @@ async def delete_content(
url = BASE_URL.format(repo=repo, path=dest)

async with semaphore:
response = await delete(session=session, url=url, data=data, headers=headers)
response = await delete(
session=session, url=url, data=data, headers=headers
)

return response

Expand All @@ -74,15 +43,16 @@ async def check_exists(*, session, repo, dest, token, semaphore, skip_missing):

async with semaphore:
response = await get(
session=session, url=url, headers=headers, skip_missing=skip_missing
session=session,
url=url,
headers=headers,
skip_missing=skip_missing,
)

return response


async def handle_file_delete(
*, repo, dest, token, semaphore, session
):
async def handle_file_delete(*, repo, dest, token, semaphore, session):
check_exists_response = await check_exists(
session=session,
repo=repo,
Expand Down Expand Up @@ -114,7 +84,7 @@ async def handle_file_delete(
exists=exists,
current_sha=current_sha,
)

if delete_response:
return click.style(
"Successfully deleted contents at {repo}/{dest}".format(
Expand All @@ -124,25 +94,14 @@ async def handle_file_delete(
fg="green",
bold=True,
)

return click.style(
"No content found at {repo}/{dest}".format(repo=repo, dest=dest),
fg="blue",
bold=True,
)


async def list_repos(*, session, org, token):
headers = {
"Authorization": "token {token}".format(token=token),
"Accept": "application/vnd.github.v3+json",
}
url = REPOS_URL.format(org=org)
click.echo("Retrieving repos at {}".format(url))
response = await get(session=session, url=url, headers=headers)
return response


@click.command()
@click.option(
"--org",
Expand All @@ -154,7 +113,7 @@ async def list_repos(*, session, org, token):
prompt=click.style("Enter your personal access token", bold=True),
help="Personal Access token with read and write access to org.",
hide_input=True,
envvar='TOKEN',
envvar="TOKEN",
)
@click.option(
"--dest",
Expand All @@ -178,11 +137,18 @@ async def main(org, token, dest):
]
click.echo(
click.style(
"Found '{}' repositories non archived repositories".format(len(repos)),
"Found '{}' repositories non archived repositories".format(
len(repos)
),
fg="green",
)
)
click.echo(click.style('Deleting "{path}" for all repositories:'.format(path=dest), fg="blue"))
click.echo(
click.style(
'Deleting "{path}" for all repositories:'.format(path=dest),
fg="blue",
)
)
click.echo("\n".join(repos))

c = click.prompt(click.style("Continue? [YN] ", fg="blue"))
Expand Down
Loading