Skip to content

Instantly share code, notes, and snippets.

@driazati
Created August 9, 2022 22:53
Show Gist options
  • Save driazati/80cd48e86c6548cd90a6b39be010b921 to your computer and use it in GitHub Desktop.
Save driazati/80cd48e86c6548cd90a6b39be010b921 to your computer and use it in GitHub Desktop.
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>")
@driazati
Copy link
Author

driazati commented Aug 9, 2022

Usage:

# get the script
curl -LO https://gist.github.com/driazati/80cd48e86c6548cd90a6b39be010b921/raw/b51d29fb3ea457f50ece1015c3535edb37a461ed/failure_summary.py

# use the dates for whatever week
python3 failure_summary.py --from 2022-08-01 --to 2022-08-07 > summary.md

# edit summary.md with the relevant info, copy-paste to GitHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment