tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

summarize-tgdiff.py (1465B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import argparse
      6 import json
      7 import pathlib
      8 
      9 
     10 def filter_changes(line):
     11    # Skip diff headers
     12    if line.startswith("---") or line.startswith("+++"):
     13        return False
     14 
     15    # Only count lines that changed
     16    return line.startswith("-") or line.startswith("+")
     17 
     18 
     19 def run():
     20    parser = argparse.ArgumentParser(
     21        description="Classify output of taskgraph for CI analsyis"
     22    )
     23    parser.add_argument(
     24        "path",
     25        type=pathlib.Path,
     26        help="Folder containing all the TXT files from taskgraph target.",
     27    )
     28    parser.add_argument(
     29        "threshold",
     30        type=int,
     31        help="Minimum number of lines to trigger a warning on taskgraph output.",
     32    )
     33    args = parser.parse_args()
     34 
     35    out = {"files": {}, "status": "OK", "threshold": args.threshold}
     36    for path in args.path.glob("*.txt"):
     37        with path.open() as f:
     38            nb = len(list(filter(filter_changes, f.readlines())))
     39 
     40        out["files"][path.stem] = {
     41            "nb": nb,
     42            "status": "WARNING" if nb >= args.threshold else "OK",
     43        }
     44 
     45        if nb >= args.threshold:
     46            out["status"] = "WARNING"
     47 
     48    (args.path / "summary.json").write_text(json.dumps(out, sort_keys=True, indent=4))
     49 
     50 
     51 if __name__ == "__main__":
     52    run()