Skip to content

Commit

Permalink
Set default to no CSV headers
Browse files Browse the repository at this point in the history
For automation, we upload to S3 for Athena injestion. Headers are not
wanted for that use case.
  • Loading branch information
Hal Wine committed Sep 26, 2020
1 parent e5d455d commit b06ae74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 8 additions & 2 deletions github/branches/retrieve_github_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ def parse_args():
ap.add_argument(
"--verbose", "-v", help="Increase verbosity", action="count", default=0
)
# Default to no headers for common automation case of generating for
# AWS Athena
ap.add_argument(
"--headers", help="Add column headers to csv output", action="store_true"
)
ap.add_argument(
"repo", nargs="+", help='Repository full name, such as "login/repo".'
)
Expand Down Expand Up @@ -409,7 +414,7 @@ def get_connection(base_url: str, token: str) -> Any:
return endpoint


def main(*args: List[str]) -> int:
def main() -> int:
# hack to support doctests
if "pytest" in sys.modules:
return
Expand All @@ -419,7 +424,8 @@ def main(*args: List[str]) -> int:
else:
csv_out = csv.writer(sys.stdout)
endpoint = get_connection(args.graphql_endpoint, args.token)
csv_out.writerow(RepoBranchProtections.csv_header())
if args.headers:
csv_out.writerow(RepoBranchProtections.csv_header())
for repo in args.repo:
row_data = get_repo_branch_protections(endpoint, repo)
csv_output(row_data, csv_writer=csv_out)
Expand Down
16 changes: 11 additions & 5 deletions github/orgs/retrieve_github_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def csv_output(data, csv_writer) -> None:
csv_writer.writerow(data.csv_row())


def parse_args(*args):
def parse_args():
import argparse

ap = argparse.ArgumentParser(description="GitHub Agile Dashboard")
Expand All @@ -140,11 +140,16 @@ def parse_args(*args):
ap.add_argument(
"--verbose", "-v", help="Increase verbosity", action="count", default=0
)
# Default to no headers for common automation case of generating for
# AWS Athena
ap.add_argument(
"--headers", help="Add column headers to csv output", action="store_true"
)
ap.add_argument(
"orgs", nargs="*", help='Organization slug name, such as "mozilla".'
)

args = ap.parse_args(args)
args = ap.parse_args()

endpoint_loglevel = max(10, 40 - ((args.verbose - 3) * 10))
logfmt = "%(levelname)s: %(message)s"
Expand Down Expand Up @@ -268,17 +273,18 @@ def get_connection(base_url: str, token: Optional[str]) -> Any:
return endpoint


def main(*args) -> int:
def main() -> int:
# hack to support doctests
if "pytest" in sys.modules:
return
args = parse_args(*args)
args = parse_args()
if args.output:
csv_out = csv.writer(open(args.output, "w"))
else:
csv_out = csv.writer(sys.stdout)
endpoint = get_connection(args.graphql_endpoint, args.token)
csv_out.writerow(OrgInfo.csv_header())
if args.headers:
csv_out.writerow(OrgInfo.csv_header())
for row in get_all_org_data(endpoint, args.orgs):
csv_output(row, csv_writer=csv_out)

Expand Down
2 changes: 1 addition & 1 deletion github/vscode-debug-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from github.branches import retrieve_github_data as branch_retrieve_github_data

# org will get metadata orgs if none supplied
# org_retrieve_github_data.main()
org_retrieve_github_data.main()

# branch does not have default, so pass along current command line
# N.B. since that will also happen in pytest's doctest mode, that
Expand Down

0 comments on commit b06ae74

Please sign in to comment.