Skip to content

Commit cf1c9f3

Browse files
committed
Filter updated control files
Signed-off-by: Sophia Wang <huiwang@redhat.com>
1 parent 5a1b243 commit cf1c9f3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

content_test_filtering.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python3
2-
import logging
2+
import json, logging
33
from sys import stderr
44
from ctf import cli, diff_analysis, connect_to_labels, ContentTests, DiffLogging
55
from ctf.diff import git_wrapper
@@ -30,7 +30,7 @@
3030
changed_files = git_wrapper.git_diff_files(options.base_branch,
3131
new_branch=options.branch,
3232
pr_number=options.pr_number)
33-
33+
controls_files = []
3434
# Analyze each file separately and make set of tests for each one
3535
while True:
3636
if not changed_files: # Finish when all files are analysed
@@ -43,6 +43,10 @@
4343
if file_record["filepath"].startswith(".github"):
4444
continue
4545

46+
# Filter the updated control files
47+
if "controls/" in file_record["filepath"]:
48+
controls_files.append(file_record["filepath"])
49+
4650
try:
4751
diff_structure = diff_analysis.analyse_file(file_record)
4852
except diff_analysis.UnknownAnalysisFileType:
@@ -55,11 +59,19 @@
5559
already_analysed.append(file_record["filepath"])
5660
# If change affected any other file -> analyse it
5761
changed_files.extend(diff_structure.affected_files)
58-
5962
list_of_tests = connect_to_labels.get_labels(tests, options.output)
6063
if options.output == "json":
6164
logs.print_json(list_of_tests)
6265
else:
6366
logs.print_all_logs(list_of_tests, output_format=options.output_format)
64-
67+
# Save the updated controls to a file for syncing OSCAL catalog
68+
logger.debug(f"The updated controls: {controls_files}")
69+
if options.output == "json":
70+
controls_updates = {"controls": controls_files}
71+
try:
72+
with open('controls_updates.json', 'w', encoding='utf-8') as file:
73+
json.dump(controls_updates, file, ensure_ascii=False, indent=4)
74+
logger.debug("Controls saved to controls_updates.json successfully.")
75+
except Exception as e:
76+
logger.error(f"Error saving controls updates: {e}")
6577
logger.debug("Finished")

0 commit comments

Comments
 (0)