Skip to content

Commit cf54fe9

Browse files
authored
Merge pull request #36 from tj-python/feat/update-api-url-and-add-new-features
2 parents 043435d + 462164a commit cf54fe9

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

github_deploy/commands/_constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
REPOS_URL = "https://api.github.com/search/repositories?q=org:{org}"
1+
REPOS_URL = "https://api.github.com/users/{org}/repos"
22
FILE_CONTENTS_URL = "https://api.github.com/repos/{repo}/contents/{path}"

github_deploy/commands/_repo_utils.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import base64
22
import os
33

4-
import aiofiles
54
import asyncclick as click
6-
from aiofiles import os as aiofiles_os
5+
from aiofiles import os as aiofiles_os, open as aiofiles_open
76

87
from github_deploy.commands._constants import REPOS_URL, FILE_CONTENTS_URL
98
from github_deploy.commands._http_utils import get, delete, put
@@ -69,25 +68,44 @@ async def upload_content(
6968
current_content
7069
):
7170
async with semaphore:
72-
async with aiofiles.open(source, mode="rb") as f:
71+
async with aiofiles_open(source, mode="rb") as f:
7372
output = await f.read()
7473
base64_content = base64.b64encode(output).decode("ascii")
7574

7675
if current_content == base64_content:
77-
click.echo("Skipping: Contents are the same.")
76+
click.echo(
77+
click.style(
78+
f"Skipping {source} to {repo}/{dest}: No changes detected.",
79+
fg="yellow",
80+
bold=True,
81+
)
82+
)
7883
return
7984
else:
8085
if exists:
81-
click.echo("Storing backup of existing file...")
86+
click.echo(
87+
click.style(
88+
"Storing backup of existing file at {repo}/{path}...".format(
89+
repo=repo, path=dest
90+
),
91+
fg="cyan",
92+
),
93+
)
8294

8395
dirname, filename = os.path.split(f"{repo}/{dest}")
8496

8597
await aiofiles_os.makedirs(dirname, exist_ok=True)
8698

87-
async with aiofiles.open(f"{dirname}/{filename}", mode="wb") as f:
99+
async with aiofiles_open(f"{dirname}/{filename}", mode="wb") as f:
88100
await f.write(base64.b64decode(current_content))
89101
elif only_update:
90-
click.echo(f"Skipping: only updating existing files.")
102+
click.echo(
103+
click.style(
104+
f"Updates only: Skipped uploading {source} to {repo}/{dest}. File does not exist.",
105+
fg="yellow",
106+
bold=True,
107+
)
108+
)
91109
return
92110

93111
data = {
@@ -101,7 +119,13 @@ async def upload_content(
101119

102120
url = FILE_CONTENTS_URL.format(repo=repo, path=dest)
103121

104-
click.echo(f"Uploading {source} to {repo}/{dest}...")
122+
click.echo(
123+
click.style(
124+
f"Uploading {source} to {repo}/{dest}...",
125+
fg="green",
126+
bold=True,
127+
)
128+
)
105129

106130
async with semaphore:
107131
response = await put(

github_deploy/commands/delete.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def main(org, token, dest):
8787
response = await list_repos(org=org, token=token, session=session)
8888
repos = [
8989
get_repo(org=org, project=v["name"])
90-
for v in response["items"]
90+
for v in response
9191
if not v["archived"]
9292
]
9393
click.echo(

github_deploy/commands/upload.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def handle_file_upload(
2525

2626
if exists:
2727
if not overwrite:
28-
return click.style(
28+
click.style(
2929
"Skipped uploading {source} to {repo}/{path}: Found an existing copy.".format(
3030
source=source,
3131
repo=repo,
@@ -132,7 +132,7 @@ async def main(org, token, source, dest, overwrite, only_update, private):
132132
response = await list_repos(org=org, token=token, session=session)
133133
repos = [
134134
get_repo(org=org, project=r["name"])
135-
for r in response["items"]
135+
for r in response
136136
if not r["archived"]
137137
and can_upload(repo=r, include_private=private)
138138
]
@@ -156,15 +156,21 @@ async def main(org, token, source, dest, overwrite, only_update, private):
156156
fg="bright_red",
157157
)
158158
)
159-
deploy_msg = (
160-
'Deploying "{source}" to "{path}" for all repositories'.format(
161-
source=source, path=dest
162-
)
163-
if overwrite
164-
else 'Deploying "{source}" to repositories that don\'t already have contents at "{path}"'.format(
159+
160+
if overwrite:
161+
if only_update:
162+
deploy_msg = "Updating '{source}' for existing files located at '{dest}'".format(
163+
source=source, dest=dest
164+
)
165+
else:
166+
deploy_msg = "Overwriting '{dest}' with '{source}'".format(
167+
source=source, dest=dest
168+
)
169+
else:
170+
deploy_msg = "Deploying '{source}' to repositories that don\'t already have contents at '{path}'".format(
165171
source=source, path=dest
166172
)
167-
)
173+
168174
click.echo(click.style(deploy_msg, fg="blue"))
169175
c = click.prompt(click.style("Continue? [YN] ", fg="blue"))
170176

0 commit comments

Comments
 (0)