forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerrit_changed_files_to_skipfile.py
executable file
·55 lines (46 loc) · 1.57 KB
/
gerrit_changed_files_to_skipfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------
"""
Converts Gerrit Review changed files list to CodeChecker skipfile.
"""
import argparse
import json
import re
def create_skipfile(files_changed, skipfile):
# File is likely to contain some garbage values at start,
# only the corresponding json should be parsed.
json_pattern = re.compile(r"^\{.*\}")
for line in files_changed.readlines():
if re.match(json_pattern, line):
for filename in json.loads(line):
if "/COMMIT_MSG" in filename:
continue
skipfile.write("+*/%s\n" % filename)
skipfile.write("-*\n")
def main():
parser = argparse.ArgumentParser(
description="Converts Gerrit Review changed files "
"json to CodeChecker skipfile."
)
parser.add_argument(
"files_changed",
type=argparse.FileType("r"),
help="Path of changed files json from Gerrit.",
)
parser.add_argument(
"skipfile",
nargs="?",
default="skipfile",
type=argparse.FileType("w"),
help="Path of the skipfile output. Default is ./skipfile.",
)
args = parser.parse_args()
create_skipfile(args.files_changed, args.skipfile)
if __name__ == "__main__":
main()