-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reintroduce create_skipfile.py script for gerrit
The script was removed in c1626bb but for the usecase where the user does not want to analyze all the source files in the review it is needed.
- Loading branch information
Gyorgy Orban
committed
Nov 5, 2020
1 parent
d1604bb
commit 11ca1e0
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ------------------------------------------------------------------------- | ||
# | ||
# 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() |