Skip to content

Commit

Permalink
Move GitHub subcommand down into the github module
Browse files Browse the repository at this point in the history
We're about to add more commands so we don't want to have them all in
the same cli.py.  This moves us to having a cli.py for each sub command,
which is then registered in the top level cli.py.
  • Loading branch information
ghickman committed Nov 2, 2023
1 parent c396bda commit bd4d8f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
32 changes: 2 additions & 30 deletions metrics/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import click

from .github import commands as github_commands
from .github.cli import github
from .logs import setup_logging


Expand All @@ -15,32 +15,4 @@ def cli(ctx, debug):
ctx.obj["DEBUG"] = debug


@cli.group()
@click.option("--token", required=True, envvar="GITHUB_TOKEN")
@click.pass_context
def github(ctx, token):
ctx.ensure_object(dict)

ctx.obj["TOKEN"] = token


@github.command()
@click.argument("org")
@click.argument("date", type=click.DateTime())
@click.option("--days-threshold", type=int)
@click.pass_context
def pr_queue(ctx, org, date, days_threshold):
date = date.date()

github_commands.pr_queue(org, date, days_threshold)


@github.command()
@click.argument("org")
@click.argument("date", type=click.DateTime())
@click.option("--days", default=7, type=int)
@click.pass_context
def pr_throughput(ctx, org, date, days):
date = date.date()

github_commands.pr_throughput(org, date, days)
cli.add_command(github)
30 changes: 24 additions & 6 deletions metrics/github/commands.py → metrics/github/cli.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
from datetime import timedelta

import click
import structlog

from .. import influxdb, timescaledb # noqa: F401
from .. import influxdb
from . import api
from .prs import process_prs


log = structlog.get_logger()
writer = influxdb.write
# writer = timescaledb.write


log = structlog.get_logger()
@click.group()
@click.option("--token", required=True, envvar="GITHUB_TOKEN")
@click.pass_context
def github(ctx, token):
ctx.ensure_object(dict)

ctx.obj["TOKEN"] = token


def pr_queue(org, date, days_threshold=None):
@github.command()
@click.argument("org")
@click.argument("date", type=click.DateTime())
@click.option("--days-threshold", type=int)
@click.pass_context
def pr_queue(ctx, org, date, days_threshold):
"""The number of PRs open on the given date"""
date = date.date()
prs = api.prs_open_on_date(org, date)

if days_threshold is not None:
Expand All @@ -32,10 +45,15 @@ def pr_queue(org, date, days_threshold=None):
process_prs(writer, f"queue{suffix}", prs, date)


def pr_throughput(org, date, days):
@github.command()
@click.argument("org")
@click.argument("date", type=click.DateTime())
@click.option("--days", default=7, type=int)
@click.pass_context
def pr_throughput(ctx, org, date, days):
"""PRs opened in the last number of days given"""
end = date.date()
start = date - timedelta(days=days)
end = date

prs = api.prs_opened_in_the_last_N_days(org, start, end)

Expand Down

0 comments on commit bd4d8f1

Please sign in to comment.