Skip to content

Commit 93014c0

Browse files
committed
Added support for uploading to only public repositories.
1 parent e31629b commit 93014c0

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

github_deploy/commands/_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
def get_repo(*, org, project):
22
return "{org}/{project}".format(project=project, org=org)
3+
4+
5+
def can_upload(*, repo, include_private):
6+
return True if include_private and repo['private'] == True else not repo['private']

github_deploy/commands/upload.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import certifi
99

1010
from github_deploy.commands._constants import BASE_URL, REPOS_URL
11-
from github_deploy.commands._utils import get_repo
11+
from github_deploy.commands._utils import get_repo, can_upload
1212

1313

1414
async def get(*, session, url, headers=None, skip_missing=False):
@@ -199,7 +199,13 @@ async def list_repos(*, session, org, token):
199199
help="Overwrite existing files.",
200200
default=False,
201201
)
202-
async def main(org, token, source, dest, overwrite):
202+
@click.option(
203+
"--private/--no-private",
204+
prompt=click.style("Should we Include private repositories", bold=True),
205+
help="Upload files to private repositories.",
206+
default=True,
207+
)
208+
async def main(org, token, source, dest, overwrite, private):
203209
"""Upload a file to all repositories owned by an organization/user."""
204210
# create instance of Semaphore: max concurrent requests.
205211
semaphore = asyncio.Semaphore(1000)
@@ -209,13 +215,14 @@ async def main(org, token, source, dest, overwrite):
209215
async with aiohttp.ClientSession() as session:
210216
response = await list_repos(org=org, token=token, session=session)
211217
repos = [
212-
get_repo(org=org, project=v["name"])
213-
for v in response["items"]
214-
if not v["archived"]
218+
get_repo(org=org, project=r["name"])
219+
for r in response["items"]
220+
if not r["archived"] and can_upload(repo=r, include_private=private)
215221
]
222+
repo_type = 'public and private' if private else 'public'
216223
click.echo(
217224
click.style(
218-
"Found '{}' repositories non archived repositories:".format(len(repos)),
225+
"Found '{}' repositories non archived {} repositories:".format(len(repos), repo_type),
219226
fg="green",
220227
)
221228
)

github_deploy/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66

77
class GithubDeploy(click.MultiCommand):
8-
8+
99
def list_commands(self, ctx):
1010
rv = []
1111
for filename in os.listdir(plugin_folder):
1212
if filename.endswith('.py') and not filename.startswith('__init__') and not filename.startswith('_'):
1313
rv.append(filename[:-3])
1414
rv.sort()
1515
return rv
16-
16+
1717
def get_command(self, ctx, name):
1818
ns = {}
1919
fn = os.path.join(plugin_folder, name + '.py')

0 commit comments

Comments
 (0)