Skip to content

Commit

Permalink
Update output filenames and paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mshriver committed Sep 10, 2020
1 parent 0697b09 commit 16659f9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from pathlib import Path

from dynaconf import Dynaconf

settings = Dynaconf(
envvar_prefix="METRICS", settings_files=["settings.yaml", ".secrets.yaml"],
)

METRICS_DIR = Path()
METRICS_OUTPUT = METRICS_DIR.joinpath("metrics_output")
30 changes: 13 additions & 17 deletions scripts/gh_metrics.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# import json
# from collections import OrderedDict
from datetime import datetime
from pathlib import Path
from time import time

import click
from tabulate import tabulate

from config import METRICS_OUTPUT
from config import settings
from utils import file_io
from utils import metrics_calculators
Expand Down Expand Up @@ -48,14 +49,14 @@ def gather():


@gather.command(
"single_pr_metrics",
"pr-metrics",
help="Gather metrics about individual PRs for a GH repo (SatelliteQE/robottelo)",
)
@org_name_option
@repo_name_option
@output_prefix_option
@pr_count_option
def time_to_review(org, repo, file_output_prefix, pr_count):
def repo_pr_metrics(org, repo, file_output_prefix, pr_count):
for repo_name in repo:
pr_metrics, stat_metrics = metrics_calculators.single_pr_metrics(
organization=org, repository=repo_name, pr_count=pr_count
Expand All @@ -75,25 +76,25 @@ def time_to_review(org, repo, file_output_prefix, pr_count):
tabulate(stat_metrics, headers="keys", tablefmt="github", floatfmt=".1f")
)

pr_metrics_filename = (
pr_metrics_filename = METRICS_OUTPUT.joinpath(
f"{Path(file_output_prefix).stem}-"
f"{org}-"
f"{repo_name}-"
"pr_metrics-"
f"{int(time())}.html"
f"{datetime.now().isoformat(timespec='minutes')}.html"
)
click.echo(f"Writing PR metrics as HTML to {pr_metrics_filename}")
file_io.write_to_output(
pr_metrics_filename,
tabulate(pr_metrics, headers="keys", tablefmt="html", floatfmt=".1f"),
)

stat_metrics_filename = (
stat_metrics_filename = METRICS_OUTPUT.joinpath(
f"{Path(file_output_prefix).stem}-"
f"{org}-"
f"{repo_name}-"
"stat_metrics-"
f"{int(time())}.html"
f"{datetime.now().isoformat(timespec='minutes')}.html"
)
click.echo(f"Writing statistics metrics as HTML to {stat_metrics_filename}")
file_io.write_to_output(
Expand All @@ -102,7 +103,7 @@ def time_to_review(org, repo, file_output_prefix, pr_count):
)


@gather.command("reviewer_actions")
@gather.command("reviewer-actions")
@org_name_option
@repo_name_option
@output_prefix_option
Expand Down Expand Up @@ -130,33 +131,28 @@ def reviewer_actions(org, repo, file_output_prefix, pr_count):
click.echo("-" * len(header))
click.echo(tabulate(t2_metrics, headers="keys", tablefmt="github"))

tier1_metrics_filename = (
tier1_metrics_filename = METRICS_OUTPUT.joinpath(
f"{Path(file_output_prefix).stem}-"
f"{org}-"
f"{repo_name}-"
"tier1_reviewers-"
f"{int(time())}.html"
f"{datetime.now().isoformat(timespec='minutes')}.html"
)
click.echo(f"Writing PR metrics as HTML to {tier1_metrics_filename}")
file_io.write_to_output(
tier1_metrics_filename,
tabulate(t1_metrics, headers="keys", tablefmt="html"),
)

tier2_metrics_filename = (
tier2_metrics_filename = METRICS_OUTPUT.joinpath(
f"{Path(file_output_prefix).stem}-"
f"{org}-"
f"{repo_name}-"
"tier2_reviewers-"
f"{int(time())}.html"
f"{datetime.now().isoformat(timespec='minutes')}.html"
)
click.echo(f"Writing PR metrics as HTML to {tier2_metrics_filename}")
file_io.write_to_output(
tier2_metrics_filename,
tabulate(t2_metrics, headers="keys", tablefmt="html"),
)


# for debugging purposes
if __name__ == "__main__":
metrics = gather()
2 changes: 1 addition & 1 deletion utils/GQL_Queries/github_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def reviewer_teams(self):

sys.exit(1)

def pull_requests(self, count=100, block_count=100):
def pull_requests(self, count=100, block_count=50):
"""dictionary of PRWrapper instances, keyed on PR numbers
Args:
count (Int): total number of PRs fetched
Expand Down
7 changes: 4 additions & 3 deletions utils/file_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# module to handle file IO functions, to keep them out of the click command module
import json
from config import METRICS_OUTPUT


def write_to_output(output_filename, content):
with open(output_filename, "w") as output_file:
json.dump(content, output_file, indent=2)
"""output_filename should be a pathlib Path object"""
METRICS_OUTPUT.mkdir(parents=True, exist_ok=True)
output_filename.write_text(content)
6 changes: 4 additions & 2 deletions utils/metrics_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

EMPTY = "---"

DATE_FMT = "%y-%m-%d"

HEADER_H_COM = "Hours to Comment"
HEADER_H_T1 = "Hours to Tier1"
HEADER_H_T2 = "Hours to Tier2"
Expand Down Expand Up @@ -133,7 +135,7 @@ def reviewer_actions(organization, repository, pr_count=100):
for week, actions in t1_by_week.items():
t1_metrics.append(
{
"Week": f"{date.fromisocalendar(week[0], week[1], 1)} to "
"Week": f"{date.fromisocalendar(week[0], week[1], 1).strftime(DATE_FMT)} to "
f"{date.fromisocalendar(week[0], week[1], 7)}",
**actions,
}
Expand All @@ -142,7 +144,7 @@ def reviewer_actions(organization, repository, pr_count=100):
for week, actions in t2_by_week.items():
t2_metrics.append(
{
"Week": f"{date.fromisocalendar(week[0], week[1], 1)} to "
"Week": f"{date.fromisocalendar(week[0], week[1], 1).strftime(DATE_FMT)} to "
f"{date.fromisocalendar(week[0], week[1], 7)}",
**actions,
}
Expand Down

0 comments on commit 16659f9

Please sign in to comment.