Debian Codegraph @

testing/web-platform/tests/tools/ci/check_for_updated_refs.py

raw
1 import json
2 import os
3 import re
4 import sys
5 from typing import IO, Container, Dict, Iterable, List, Optional
6
7 GIT_PUSH = re.compile(
8 r"^(?P<flag>.)\t(?P<from>[^\t:]*):(?P<to>[^\t:]*)\t(?P<summary>.*[^\)])(?: \((?P<reason>[^\)]*)\))?\n$"
9 )
10
11
12 def parse_push(fd: IO[str]) -> Iterable[Dict[str, Optional[str]]]:
13 for line in fd:
14 m = GIT_PUSH.match(line)
15 if m is not None:
16 yield m.groupdict()
17
18
19 def process_push(fd: IO[str], refs: Container[str]) -> List[str]:
20 updated_refs = []
21
22 for ref_status in parse_push(fd):
23 flag = ref_status["flag"]
24 if flag not in (" ", "+", "-", "*"):
25 continue
26
27 to = ref_status["to"]
28 assert to is not None
29 if to in refs:
30 updated_refs.append(to)
31
32 return updated_refs
33
34
35 def main() -> None:
36 git_push_output = os.environ["GIT_PUSH_OUTPUT"]
37 refs = json.loads(os.environ["REFS"])
38
39 with open(git_push_output, "r") as fd:
40 updated_refs = process_push(fd, refs)
41
42 json.dump(updated_refs, sys.stdout, indent=2)
43 sys.stdout.write("\n")
44
45
46 if __name__ == "__main__":
47 main()