Exemplo n.º 1
0
class BuildStatus(BaseMetric):
    name = 'build_status'
    description = "Build Status"

    def __init__(self):
        BaseMetric.__init__(self)
        self.gh = GithubApi()
        self.influxdb = InfluxDBApi()

    def _retrieve_data(self):
        self.status = []
        for repo in self.gh.repos():
            self.logger.debug(
                "Retrieving build status for: repo {} - branch {}".format(
                    repo, self.base))
            for status in repo.iter_statuses(self.base):
                if status.created_at <= DateUtils.one_week_ago():
                    break
                self.status.append(status)

    def _compute(self):
        self.results = {
            'success':
            len(list(ifilter(lambda s: s.state == "success", self.status))),
            'failure':
            len(list(ifilter(lambda s: s.state == "failure", self.status)))
        }

    def _write_results(self):
        BuildStatusSeriesHelper(base=self.base, **self.results)
        BuildStatusSeriesHelper.commit(self.influxdb.client)
Exemplo n.º 2
0
class BuildStatus(BaseMetric):
    name = 'build_status'
    description = "Build Status"

    def __init__(self):
        BaseMetric.__init__(self)
        self.gh = GithubApi()
        self.influxdb = InfluxDBApi()

    def _retrieve_data(self):
        self.status = []
        for repo in self.gh.repos():
            self.logger.debug("Retrieving build status for: repo {} - branch {}".format(repo, self.base))
            for status in repo.iter_statuses(self.base):
                if status.created_at <= DateUtils.one_week_ago():
                    break
                self.status.append(status)

    def _compute(self):
        self.results = {'success': len(list(ifilter(lambda s: s.state == "success", self.status))),
                        'failure': len(list(ifilter(lambda s: s.state == "failure", self.status)))
                        }

    def _write_results(self):
        BuildStatusSeriesHelper(base=self.base, **self.results)
        BuildStatusSeriesHelper.commit(self.influxdb.client)
Exemplo n.º 3
0
class PullRequestStats(BaseMetric):
    name = "pr_stats"
    description = "Pull Requests Stats"
    DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"

    def __init__(self):
        BaseMetric.__init__(self)
        self.gh = GithubApi()
        self.influxdb = InfluxDBApi()

    def _retrieve_data(self):
        self.closed_pull_requests = []
        self.open_pull_requests = []
        for repo in self.gh.repos():
            for pr in repo.iter_pulls(state="all", base=self.base):
                if pr.state == "closed" and pr.closed_at > DateUtils.one_week_ago():
                    self.closed_pull_requests.append(repo.pull_request(pr.number))
                elif pr.state == "open" and pr.created_at <= DateUtils.one_week_ago():
                    self.open_pull_requests.append(repo.pull_request(pr.number))

    def _compute(self):
        self.results = {"closed": {}, "open": {}}
        pr_age = map(lambda pr: (pr.closed_at - pr.created_at).seconds, self.closed_pull_requests)
        self.results["closed"]["age"] = {"max": max(pr_age), "min": min(pr_age), "avg": mean(pr_age)}
        self.results["closed"]["commits"] = {
            "pr_count": len(pr_age),
            "commits_count": 0,
            "additions": 0,
            "deletions": 0,
            "biggest": 0,
        }
        for p in self.closed_pull_requests:
            for c in p.iter_commits():
                commit = self.gh.commit(p.repository[1], c.sha)
                if DateUtils.parse(commit.commit.author["date"], self.DATE_FORMAT) > DateUtils.one_week_ago():
                    self.results["closed"]["commits"]["commits_count"] += 1
                    self.results["closed"]["commits"]["additions"] += commit.additions
                    self.results["closed"]["commits"]["deletions"] += commit.deletions
                    self.results["closed"]["commits"]["biggest"] = max(
                        self.results["closed"]["commits"]["biggest"], commit.additions + commit.deletions
                    )

        self.results["open"] = self.open_pull_requests

    def _write_results(self):
        PullRequestAgeSeriesHelper(base=self.base, **self.results["closed"]["age"])
        PullRequestCommitsSeriesHelper(base=self.base, **self.results["closed"]["commits"])
        PullRequestAgeSeriesHelper.commit(self.influxdb.client)
        PullRequestCommitsSeriesHelper.commit(self.influxdb.client)
class CommitsLastWeek(BaseMetric):
    name = 'commits_last_week'
    description = "Commits Last week"

    def __init__(self):
        BaseMetric.__init__(self)
        self.gh = GithubApi()
        self.influxdb = InfluxDBApi()

    def _retrieve_data(self):

        self.commits = []

        for repo in self.gh.repos():
            self.logger.debug(
                "Retrieving commit info for: repo {} - branch {}".format(
                    repo, self.base))
            try:
                for commit in repo.iter_commits(
                        self.base,
                        since=DateUtils.one_week_ago() + timedelta(days=1)):
                    self.commits.append(self.gh.commit(repo.name, commit.sha))
            except:
                self.logger.debug("{0} is empty in {1}".format(
                    repo, self.base))

    def _compute(self):
        self.results = {
            'commits': len(self.commits),
            'additions': 0,
            'deletions': 0,
            'biggest': 0
        }
        for c in self.commits:
            self.results['additions'] += c.additions
            self.results['deletions'] += c.deletions
            self.results['biggest'] = max(self.results['biggest'],
                                          c.additions + c.deletions)

    def _write_results(self):
        CommitsLastWeekSeriesHelper(base=self.base, **self.results)
        CommitsLastWeekSeriesHelper.commit(self.influxdb.client)
Exemplo n.º 5
0
class CommitsLastWeek(BaseMetric):
    name = 'commits_last_week'
    description = "Commits Last week"

    def __init__(self):
        BaseMetric.__init__(self)
        self.gh = GithubApi()
        self.influxdb = InfluxDBApi()

    def _retrieve_data(self):

        self.commits = []

        for repo in self.gh.repos():
            self.logger.debug("Retrieving commit info for: repo {} - branch {}".format(repo, self.base))
            try:
                for commit in repo.iter_commits(self.base, since=DateUtils.one_week_ago() + timedelta(days=1)):
                    self.commits.append(self.gh.commit(repo.name, commit.sha))
            except:
                self.logger.debug("{0} is empty in {1}".format(repo, self.base))

    def _compute(self):
        self.results = {
            'commits': len(self.commits),
            'additions': 0,
            'deletions': 0,
            'biggest': 0
        }
        for c in self.commits:
            self.results['additions'] += c.additions
            self.results['deletions'] += c.deletions
            self.results['biggest'] = max(self.results['biggest'], c.additions + c.deletions)

    def _write_results(self):
        CommitsLastWeekSeriesHelper(base=self.base, **self.results)
        CommitsLastWeekSeriesHelper.commit(self.influxdb.client)
Exemplo n.º 6
0
class PullRequestStats(BaseMetric):
    name = "pr_stats"
    description = "Pull Requests Stats"
    DATE_FORMAT = '%Y-%m-%dT%H:%M:%SZ'

    def __init__(self):
        BaseMetric.__init__(self)
        self.gh = GithubApi()
        self.influxdb = InfluxDBApi()

    def _retrieve_data(self):
        self.closed_pull_requests = []
        self.open_pull_requests = []
        for repo in self.gh.repos():
            for pr in repo.iter_pulls(state="all", base=self.base):
                if pr.state == "closed" and pr.closed_at > DateUtils.one_week_ago(
                ):
                    self.closed_pull_requests.append(
                        repo.pull_request(pr.number))
                elif pr.state == "open" and pr.created_at <= DateUtils.one_week_ago(
                ):
                    self.open_pull_requests.append(repo.pull_request(
                        pr.number))

    def _compute(self):
        self.results = {'closed': {}, 'open': {}}
        pr_age = map(lambda pr: (pr.closed_at - pr.created_at).seconds,
                     self.closed_pull_requests)
        self.results['closed']['age'] = {
            'max': max(pr_age),
            'min': min(pr_age),
            'avg': mean(pr_age)
        }
        self.results['closed']['commits'] = {
            'pr_count': len(pr_age),
            'commits_count': 0,
            'additions': 0,
            'deletions': 0,
            'biggest': 0
        }
        for p in self.closed_pull_requests:
            for c in p.iter_commits():
                commit = self.gh.commit(p.repository[1], c.sha)
                if DateUtils.parse(
                        commit.commit.author['date'],
                        self.DATE_FORMAT) > DateUtils.one_week_ago():
                    self.results['closed']['commits']['commits_count'] += 1
                    self.results['closed']['commits'][
                        'additions'] += commit.additions
                    self.results['closed']['commits'][
                        'deletions'] += commit.deletions
                    self.results['closed']['commits']['biggest'] = max(
                        self.results['closed']['commits']['biggest'],
                        commit.additions + commit.deletions)

        self.results['open'] = self.open_pull_requests

    def _write_results(self):
        PullRequestAgeSeriesHelper(base=self.base,
                                   **self.results['closed']['age'])
        PullRequestCommitsSeriesHelper(base=self.base,
                                       **self.results['closed']['commits'])
        PullRequestAgeSeriesHelper.commit(self.influxdb.client)
        PullRequestCommitsSeriesHelper.commit(self.influxdb.client)