@@ -103,17 +103,33 @@ def modules(
103
103
.filter (Asset .id == self .asset .id )
104
104
)
105
105
106
- # Apply additional filter if pr_changed_files is provided
107
- if pr_changed_files :
108
- # Normalize pr_changed_files to have './' prefix for relative paths
109
- normalized_files = {
110
- f"./{ file } " if not file .startswith ("./" ) else file
111
- for file in pr_changed_files
112
- }
113
- query = query .filter (Module .name .in_ (normalized_files ))
114
-
115
- modules = query .all ()
116
- return [ModuleReport (self .db_path , module ) for module in modules ]
106
+ if pr_changed_files is None :
107
+ return [ModuleReport (self .db_path , module ) for module in query ]
108
+
109
+ """
110
+ Apply filter on modules where the module name has to be part of the PR's changed file list.
111
+ However we can't simply do a simple equality match because the module names we store is relative
112
+ to the root of the app while the PR's file path is relative to the root of the repo. So we will
113
+ need to check that any of the PR's file lists ends with any of the modules for the given asset.
114
+ For example,
115
+ PR changed files: ["abc/def.ts", "ghi/jkl.ts"],
116
+ modules: ["def.ts", "mno.ts"]
117
+ -> ["def.ts"]
118
+ """
119
+ normalized_changed_files = [
120
+ os .path .normpath (path [2 :] if path .startswith ("./" ) else path )
121
+ for path in pr_changed_files
122
+ ]
123
+ filtered_modules = set ()
124
+ for file in normalized_changed_files :
125
+ for module in query :
126
+ normalized_module = os .path .normpath (
127
+ module .name [1 :] if file .startswith ("." ) else module .name
128
+ )
129
+ if file .endswith (normalized_module ):
130
+ filtered_modules .add (module )
131
+
132
+ return [ModuleReport (self .db_path , module ) for module in filtered_modules ]
117
133
118
134
def routes (self ) -> Optional [List [str ]]:
119
135
plugin_name = self .bundle_info .get ("plugin_name" )
0 commit comments