@@ -67,9 +67,9 @@ def getChanges(self, target_branch:str)->List[Detection]:
67
67
68
68
#Make a filename to content map
69
69
filepath_to_content_map = { obj .file_path :obj for (_ ,obj ) in self .director .name_to_content_map .items ()}
70
- updated_detections :List [Detection ] = []
71
- updated_macros :List [Macro ] = []
72
- updated_lookups :List [Lookup ] = []
70
+ updated_detections :set [Detection ] = set ()
71
+ updated_macros :set [Macro ] = set ()
72
+ updated_lookups :set [Lookup ] = set ()
73
73
74
74
for diff in all_diffs :
75
75
if type (diff ) == pygit2 .Patch :
@@ -80,14 +80,14 @@ def getChanges(self, target_branch:str)->List[Detection]:
80
80
if decoded_path .is_relative_to (self .config .path / "detections" ) and decoded_path .suffix == ".yml" :
81
81
detectionObject = filepath_to_content_map .get (decoded_path , None )
82
82
if isinstance (detectionObject , Detection ):
83
- updated_detections .append (detectionObject )
83
+ updated_detections .add (detectionObject )
84
84
else :
85
85
raise Exception (f"Error getting detection object for file { str (decoded_path )} " )
86
86
87
87
elif decoded_path .is_relative_to (self .config .path / "macros" ) and decoded_path .suffix == ".yml" :
88
88
macroObject = filepath_to_content_map .get (decoded_path , None )
89
89
if isinstance (macroObject , Macro ):
90
- updated_macros .append (macroObject )
90
+ updated_macros .add (macroObject )
91
91
else :
92
92
raise Exception (f"Error getting macro object for file { str (decoded_path )} " )
93
93
@@ -98,7 +98,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
98
98
updatedLookup = filepath_to_content_map .get (decoded_path , None )
99
99
if not isinstance (updatedLookup ,Lookup ):
100
100
raise Exception (f"Expected { decoded_path } to be type { type (Lookup )} , but instead if was { (type (updatedLookup ))} " )
101
- updated_lookups .append (updatedLookup )
101
+ updated_lookups .add (updatedLookup )
102
102
103
103
elif decoded_path .suffix == ".csv" :
104
104
# If the CSV was updated, we want to make sure that we
@@ -125,7 +125,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
125
125
if updatedLookup is not None and updatedLookup not in updated_lookups :
126
126
# It is possible that both the CSV and YML have been modified for the same lookup,
127
127
# and we do not want to add it twice.
128
- updated_lookups .append (updatedLookup )
128
+ updated_lookups .add (updatedLookup )
129
129
130
130
else :
131
131
pass
@@ -136,7 +136,7 @@ def getChanges(self, target_branch:str)->List[Detection]:
136
136
137
137
# If a detection has at least one dependency on changed content,
138
138
# then we must test it again
139
- changed_macros_and_lookups = updated_macros + updated_lookups
139
+ changed_macros_and_lookups : set [ SecurityContentObject ] = updated_macros . union ( updated_lookups )
140
140
141
141
for detection in self .director .detections :
142
142
if detection in updated_detections :
@@ -146,14 +146,14 @@ def getChanges(self, target_branch:str)->List[Detection]:
146
146
147
147
for obj in changed_macros_and_lookups :
148
148
if obj in detection .get_content_dependencies ():
149
- updated_detections .append (detection )
149
+ updated_detections .add (detection )
150
150
break
151
151
152
152
#Print out the names of all modified/new content
153
153
modifiedAndNewContentString = "\n - " .join (sorted ([d .name for d in updated_detections ]))
154
154
155
155
print (f"[{ len (updated_detections )} ] Pieces of modifed and new content (this may include experimental/deprecated/manual_test content):\n - { modifiedAndNewContentString } " )
156
- return updated_detections
156
+ return sorted ( list ( updated_detections ))
157
157
158
158
def getSelected (self , detectionFilenames : List [FilePath ]) -> List [Detection ]:
159
159
filepath_to_content_map : dict [FilePath , SecurityContentObject ] = {
0 commit comments