Created
August 9, 2022 22:53
-
-
Save driazati/80cd48e86c6548cd90a6b39be010b921 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
import re | |
import argparse | |
from datetime import datetime, timedelta | |
from pathlib import Path | |
def sh(cmd): | |
print(cmd) | |
subprocess.run(cmd, shell=True, check=True) | |
if __name__ == "__main__": | |
main = Path("main.json") | |
if not main.exists(): | |
sh( | |
"curl -LO https://raw.githubusercontent.com/driazati/tvm-hud/data/public/statuses/apache/tvm/main.json" | |
) | |
with open(main) as f: | |
data = json.load(f) | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--from", dest="from_time", required=True) | |
parser.add_argument("--to", dest="to_time", required=True) | |
args = parser.parse_args() | |
from_time = datetime.fromisoformat(args.from_time) | |
to_time = datetime.fromisoformat(args.to_time) + timedelta(days=1) | |
failures = [] | |
for item in data: | |
sha = item["sha"] | |
date = item["date"] | |
date = datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ") | |
if date < from_time or date > to_time: | |
continue | |
body = item["headline"] + item["body"] | |
m = re.search(r"\(#(\d+)\)", body) | |
pr = None | |
if m and len(m.groups()) > 0: | |
pr = m.groups()[0] | |
for job in item["jobs"]: | |
if job["status"] in {"pending", "neutral", "success"}: | |
continue | |
if not job["name"].startswith("tvm-ci") and not job["name"].startswith( | |
"CI /" | |
): | |
continue | |
failures.append( | |
( | |
f"{sha} from #{pr}" if pr else sha, | |
job["name"], | |
job["url"], | |
) | |
) | |
if len(failures) == 0: | |
print("No failures in specified date range") | |
else: | |
print( | |
f"Summary for {from_time.strftime('%Y-%m-%d')} to {to_time.strftime('%Y-%m-%d')}\n" | |
) | |
print("|Run|Commit|Mitigation|") | |
print("|--|--|--|") | |
for sha, name, job_url in failures: | |
items = ["", f"[{name}]({job_url})", sha, "<fill this out>", ""] | |
print("|".join(items)) | |
print("\n\n<sub>Generated by https://gist.github.com/driazati/80cd48e86c6548cd90a6b39be010b921</sub>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: