ClickHouse/utils/test_history/test-history

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.4 KiB
Plaintext
Raw Normal View History

2020-10-02 16:54:07 +00:00
#!/usr/bin/env python3
2020-01-23 12:29:08 +00:00
# -*- coding: utf-8 -*-
# Note: should work with python 2 and 3
2020-10-02 16:54:07 +00:00
2024-09-27 10:19:39 +00:00
import argparse
2020-01-23 12:29:08 +00:00
import datetime
2024-09-27 10:19:39 +00:00
import sys
2020-01-23 12:29:08 +00:00
import tabulate
2024-09-27 10:19:39 +00:00
from github import Github
2020-01-23 12:29:08 +00:00
from termcolor import colored
COLORMAP = {
2023-03-23 15:33:23 +00:00
"success": colored("success", "green"),
"failure": colored("failure", "red"),
"error": colored("error", "red"),
"pending": colored("pending", "yellow"),
"not run": colored("not run", "white"),
2020-01-23 12:29:08 +00:00
}
2023-03-23 15:33:23 +00:00
2020-01-23 12:29:08 +00:00
def _filter_statuses(statuses):
"""
Squash statuses to latest state
1. context="first", state="success", update_time=1
2. context="second", state="success", update_time=2
3. context="first", stat="failure", update_time=3
=========>
1. context="second", state="success"
2. context="first", stat="failure"
"""
filt = {}
for status in sorted(statuses, key=lambda x: x.updated_at):
filt[status.context] = status
2020-10-02 16:54:07 +00:00
return list(filt.values())
2020-01-23 12:29:08 +00:00
def get_filtered_statuses(commit):
return _filter_statuses(commit.get_statuses())
def get_commits(repo, since):
return sorted(repo.get_commits(since=since), key=lambda x: x.commit.author.date)
def process_one_commit(commit):
commit_statuses = get_filtered_statuses(commit)
# very dirty, but don't require additional dependencies
commit_modified = commit.commit.author.date + datetime.timedelta(hours=3)
commit_sha = commit.sha
checks_result = {}
for commit_status in commit_statuses:
state = commit_status.state
check_name = commit_status.context
checks_result[check_name] = state
return commit_sha, commit_modified, checks_result
if __name__ == "__main__":
three_days_ago = datetime.datetime.now() - datetime.timedelta(days=3)
parser = argparse.ArgumentParser("ClickHouse commits history parser")
parser.add_argument("--token", required=True)
parser.add_argument("--since", default=three_days_ago.strftime("%Y-%m-%d %H:%M:%S"))
parser.add_argument("--substr", default="Functional stateful")
args = parser.parse_args()
date_since = datetime.datetime.strptime(args.since, "%Y-%m-%d %H:%M:%S")
gh = Github(args.token)
2023-03-23 15:33:23 +00:00
repo = gh.get_repo("ClickHouse/ClickHouse")
2020-01-23 12:29:08 +00:00
commits = get_commits(repo, date_since)
longest_header = []
all_data = []
for num, commit in enumerate(commits):
commit_sha, commit_modified, check_results = process_one_commit(commit)
2020-10-02 16:54:07 +00:00
mapped_keys = [key for key in list(check_results.keys()) if args.substr in key]
2020-01-23 12:29:08 +00:00
if len(mapped_keys) > len(longest_header):
longest_header = mapped_keys
all_data.append((commit_modified, commit_sha, check_results))
if (num + 1) % 10 == 0:
print("Processed", num + 1, "commits")
longest_header = ["Date", "SHA"] + longest_header
result_data = []
for row in all_data:
current_result = [row[0].strftime("%Y-%m-%d %H:%M:%S"), row[1][0:7]]
for check_name in longest_header[2:]:
if check_name in row[2]:
check_result = row[2][check_name]
else:
check_result = "not run"
if sys.stdout.isatty():
current_result.append(COLORMAP[check_result])
else:
current_result.append(check_result)
result_data.append(current_result)
if sys.stdout.isatty():
2023-03-23 15:33:23 +00:00
longest_header = [colored(h, "white", attrs=["bold"]) for h in longest_header]
2020-01-23 12:29:08 +00:00
print(tabulate.tabulate(result_data, headers=longest_header, tablefmt="grid"))