Skip to content

Commit

Permalink
Merge pull request #42 from Malwarebytes/list_output
Browse files Browse the repository at this point in the history
Improve the output of the repository listing
  • Loading branch information
jboursier-mwb authored Oct 22, 2022
2 parents 514340a + ab40ce8 commit b19e580
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

try:
import click
import json
from typing import Dict, Any
from datetime import datetime
except ImportError:
Expand Down Expand Up @@ -162,6 +163,7 @@ def repositories_cli() -> None:
),
default="human",
)
@click.argument("output", type=click.File("w"))
@click.option(
"-t",
"--token",
Expand All @@ -181,6 +183,7 @@ def repositories_list(
archived: bool,
disabled: bool,
format: str,
output: Any,
organization: str,
token: str,
) -> None:
Expand All @@ -198,19 +201,23 @@ def repositories_list(

if "human" == format:
for r in res:
output.write(r + "\n")
click.echo(r)
elif "ghas" == format:
repos = []
for r in res:
repos.append(r.to_ghas())
output.write(json.dumps([{"login": organization, "repos": repos}]) + "\n")
click.echo([{"login": organization, "repos": repos}])
elif "json" == format:
repos = []
for r in res:
repos.append(r.to_json())
output.write(json.dumps(repos) + "\n")
click.echo(repos)
elif "list" == format:
for r in res:
output.write(r.name + "\n")
click.echo(r.name)


Expand Down
2 changes: 2 additions & 0 deletions src/ghas_cli/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#!/usr/bin/env python3

from typing import Any, Dict
from datetime import datetime
import time


Expand Down Expand Up @@ -30,6 +31,7 @@ def check_rate_limit(response: Any) -> bool:
print(
f"Rate limit reached: {response.headers['x-ratelimit-remaining']}/{response.headers['x-ratelimit-limit']} - {reset_time}"
)
time.sleep(reset_time)
return True

if response.status_code == 403:
Expand Down
31 changes: 16 additions & 15 deletions src/ghas_cli/utils/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,31 +181,32 @@ def get_org_repositories(

repo = Repository()
repo.load_json(r, token=token)
# repo.load_json(r, token=None)

if language != "" and repo.main_language != language:
# print(
# f"{repo.name} ignored because of language: {language} vs. {repo.main_language}"
# )
print(
f"{repo.name} ignored because of language: {language} vs. {repo.main_language}"
)
continue
if default_branch != "" and repo.default_branch != default_branch:
# print(
# f"{repo.name} ignored because of default branch: {default_branch} vs. {repo.default_branch}"
# )
print(
f"{repo.name} ignored because of default branch: {default_branch} vs. {repo.default_branch}"
)
continue
if license != "" and repo.license != license:
# print(
# f"{repo.name} ignored because of license: {license} vs. {repo.license}"
# )
print(
f"{repo.name} ignored because of license: {license} vs. {repo.license}"
)
continue
if repo.archived != archived:
# print(
# f"{repo.name} ignored because of archived: {archived} vs. {repo.archived}"
# )
print(
f"{repo.name} ignored because of archived: {archived} vs. {repo.archived}"
)
continue
if repo.disabled != disabled:
# print(
# f"{repo.name} ignored because of license: {archived} vs. {repo.archived}"
# )
print(
f"{repo.name} ignored because of license: {archived} vs. {repo.archived}"
)
continue

repos_list.append(repo)
Expand Down

0 comments on commit b19e580

Please sign in to comment.