← Back to team overview

sts-sponsors team mailing list archive

Re: [Merge] ~alexsander-souza/maas-kpi/+git/maas-kpi:collect_github_stats into maas-kpi:master

 

Review: Needs Information

one question (and a suggestion) inline

Diff comments:

> diff --git a/maaskpi/github.py b/maaskpi/github.py
> new file mode 100644
> index 0000000..31b075e
> --- /dev/null
> +++ b/maaskpi/github.py
> @@ -0,0 +1,70 @@
> +from pathlib import Path
> +
> +from github import Github
> +from influxdb import SeriesHelper
> +
> +from .base import Collector
> +
> +ORG_CANONICAL = "canonical"
> +ORG_MAAS = "maas"
> +
> +
> +class OpenBugsSeries(SeriesHelper):
> +    class Meta:
> +        series_name = "maas.open_bugs"
> +        fields = ["bug", "pr"]
> +        tags = ["project"]
> +        autocommit = False
> +
> +
> +class BugsCollector(Collector):
> +    """Collect metrics about bugs against a GH project.
> +
> +    It collects the number of open bugs.
> +
> +    TODO use labels to identify 'triaged' bugs
> +
> +    """
> +
> +    def __init__(self):
> +        super().__init__()
> +        self.parser.add_argument(
> +            "-g",
> +            "--gh-credentials",
> +            default="github.creds",
> +            nargs="?",
> +            help="Path to the file containing GH API token",

isn't this required?

> +        )
> +
> +    def run_collect(self, args):
> +        token = Path(args.gh_credentials).read_text().rstrip()
> +        gh = Github(token)
> +        return self.collect(gh)
> +
> +    def _collect_bugs(self, record_series, gh, org, project_label):
> +        self.log(f"Tasks for {project_label}:")
> +        counts = dict.fromkeys(record_series.Meta.fields, 0)
> +        repo = gh.get_organization(org).get_repo(project_label)
> +
> +        for issue in repo.get_issues(state="open"):
> +            kind = "pr" if issue.pull_request else "bug"

we could simply use a Counter here:

counts = Counter("pr" if issue.pull_request else "bug")
record_series(**counts, project=project_label)

> +            counts[kind] += 1
> +            self.log(f"{project_label} | {issue.title} | {kind}")
> +        # influx mutates state in the class via the constructor
> +        record_series(**counts, project=project_label)
> +
> +    def collect(self, gh):
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_CANONICAL, "packer-maas")
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_CANONICAL, "maas-loki-alert-rules")
> +        self._collect_bugs(
> +            OpenBugsSeries, gh, ORG_CANONICAL, "maas-prometheus-alert-rules"
> +        )
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_MAAS, "maas-ansible-playbook")
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_MAAS, "terraform-provider-maas")
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_MAAS, "ansible-collection")
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_MAAS, "python-libmaas")
> +        self._collect_bugs(OpenBugsSeries, gh, ORG_MAAS, "gomaasclient")
> +        yield OpenBugsSeries
> +
> +
> +run = BugsCollector().run


-- 
https://code.launchpad.net/~alexsander-souza/maas-kpi/+git/maas-kpi/+merge/443706
Your team MAAS Committers is subscribed to branch maas-kpi:master.



Follow ups

References