added number of reviewed commits
This commit is contained in:
parent
a2973f0f79
commit
1c53d6ee86
1 changed files with 21 additions and 5 deletions
|
@ -18,6 +18,7 @@ from time import timezone
|
||||||
import git
|
import git
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from google.cloud import monitoring_v3
|
from google.cloud import monitoring_v3
|
||||||
|
import re
|
||||||
|
|
||||||
from datetime import tzinfo
|
from datetime import tzinfo
|
||||||
|
|
||||||
|
@ -26,30 +27,42 @@ GCP_PROJECT_ID = 'llvm-premerge-checks'
|
||||||
class RepoStats:
|
class RepoStats:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.commits = 0 # type: int
|
self.commits = 0 # type: int
|
||||||
self.reverts = 0 # type: int
|
self.reverts = 0 # type: int
|
||||||
|
self.reviewed = 0 # type: int
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def percent_reverted(self) -> float:
|
def percent_reverted(self) -> float:
|
||||||
return 100.0 * self.reverts / self.commits
|
return 100.0 * self.reverts / self.commits
|
||||||
|
|
||||||
|
@property
|
||||||
|
def percent_reviewed(self) -> float:
|
||||||
|
return 100.0 * self.reviewed / (self.commits - self.reverts)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "\n".join([
|
return "\n".join([
|
||||||
"commits: {}".format(self.commits),
|
"commits: {}".format(self.commits),
|
||||||
"reverts: {}".format(self.reverts),
|
"reverts: {}".format(self.reverts),
|
||||||
|
"reviewed: {}".format(self.reviewed),
|
||||||
"percent reverted: {:0.1f}".format(self.percent_reverted),
|
"percent reverted: {:0.1f}".format(self.percent_reverted),
|
||||||
|
"percent reviewed: {:0.1f}".format(self.percent_reviewed),
|
||||||
])
|
])
|
||||||
|
|
||||||
def get_reverts_per_day(repo_path: str, max_age: datetime.datetime) -> RepoStats:
|
def get_reverts_per_day(repo_path: str, max_age: datetime.datetime) -> RepoStats:
|
||||||
stats = RepoStats()
|
stats = RepoStats()
|
||||||
repo = git.Repo(repo_path)
|
repo = git.Repo(repo_path)
|
||||||
repo.git.fetch()
|
repo.git.fetch()
|
||||||
|
diff_regex = re.compile(r'^Differential Revision: https:\/\/reviews\.llvm\.org\/(.*)$', re.MULTILINE)
|
||||||
|
|
||||||
for commit in repo.iter_commits('master'):
|
for commit in repo.iter_commits('master'):
|
||||||
if commit.committed_datetime < max_age:
|
if commit.committed_datetime < max_age:
|
||||||
break
|
break
|
||||||
stats.commits += 1
|
stats.commits += 1
|
||||||
if commit.summary.startswith('Revert'):
|
if commit.message.startswith('Revert'):
|
||||||
stats.reverts += 1
|
stats.reverts += 1
|
||||||
|
if diff_regex.search(commit.message) is not None:
|
||||||
|
stats.reviewed += 1
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +75,8 @@ def gcp_write_data(project_id: str, stats: RepoStats, now:datetime.datetime):
|
||||||
["reverts", stats.reverts],
|
["reverts", stats.reverts],
|
||||||
["commits", stats.commits],
|
["commits", stats.commits],
|
||||||
["percent_reverted", stats.percent_reverted],
|
["percent_reverted", stats.percent_reverted],
|
||||||
|
["reviewed", stats.reviewed],
|
||||||
|
["percent_reviewed", stats.percent_reviewed],
|
||||||
]:
|
]:
|
||||||
series = monitoring_v3.types.TimeSeries()
|
series = monitoring_v3.types.TimeSeries()
|
||||||
series.metric.type = 'custom.googleapis.com/repository_{}'.format(desc_type)
|
series.metric.type = 'custom.googleapis.com/repository_{}'.format(desc_type)
|
||||||
|
@ -78,4 +93,5 @@ if __name__ == '__main__':
|
||||||
# TODO: make path configurable
|
# TODO: make path configurable
|
||||||
stats = get_reverts_per_day('~/git/llvm-project', max_age)
|
stats = get_reverts_per_day('~/git/llvm-project', max_age)
|
||||||
print(stats)
|
print(stats)
|
||||||
|
# TODO: add `dryrun` parameter
|
||||||
gcp_write_data(GCP_PROJECT_ID, stats, now)
|
gcp_write_data(GCP_PROJECT_ID, stats, now)
|
Loading…
Add table
Reference in a new issue