-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_external_changes.py
More file actions
executable file
·40 lines (29 loc) · 1 KB
/
check_external_changes.py
File metadata and controls
executable file
·40 lines (29 loc) · 1 KB
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
#!/usr/bin/env python3
import fnmatch
import json
import os
import sys
from pathlib import Path
def main():
EXTERNAL_CONTRIB_BLACKLIST_PATH = os.environ['EXTERNAL_CONTRIB_BLACKLIST_PATH']
blacklisted_patterns = [
pattern for line in Path(EXTERNAL_CONTRIB_BLACKLIST_PATH).read_text().splitlines()
if (pattern := line.split("#")[0].strip()) != ""
]
with open(os.environ['CHANGED_FILES_JSON_PATH'], 'r') as f:
changed_files = json.load(f)
print(f"Changed files: {changed_files}")
print(f"Blacklisted patterns: {blacklisted_patterns}")
if blacklisted_patterns == []:
print("No blacklisted patterns found.")
sys.exit(0)
violations = [
file for pattern in blacklisted_patterns for file in changed_files
if fnmatch.fnmatch(file, pattern)
]
if len(violations) > 0:
print(f"No changes allowed to files: {violations}")
sys.exit(1)
print("All changed files pass conditions.")
if __name__ == "__main__":
main()