15
15
import services .path as path_service
16
16
from codecov .db import sync_to_async
17
17
from core .models import Commit
18
+ from codecov_auth .models import Owner
18
19
from graphql_api .actions .commits import commit_status , commit_uploads
19
20
from graphql_api .actions .comparison import validate_commit_comparison
20
21
from graphql_api .actions .path_contents import sort_path_contents
44
45
from services .bundle_analysis import BundleAnalysisComparison , BundleAnalysisReport
45
46
from services .comparison import Comparison , ComparisonReport
46
47
from services .components import Component
47
- from services .path import ReportPaths
48
+ from services .path import Dir , File , ReportPaths
48
49
from services .profiling import CriticalFile , ProfilingSummary
49
50
from services .yaml import (
50
51
YamlStates ,
@@ -146,23 +147,19 @@ def resolve_critical_files(commit: Commit, info, **kwargs) -> List[CriticalFile]
146
147
return profiling_summary .critical_files
147
148
148
149
149
- @sentry_sdk .trace
150
- @commit_bindable .field ("pathContents" )
151
- @sync_to_async
152
- def resolve_path_contents (commit : Commit , info , path : str = None , filters = None ):
153
- """
154
- The file directory tree is a list of all the files and directories
155
- extracted from the commit report of the latest, head commit.
156
- The is resolver results in a list that represent the tree with files
157
- and nested directories.
158
- """
159
- current_owner = info .context ["request" ].current_owner
160
-
150
+ def get_sorted_path_contents (
151
+ current_owner : Owner ,
152
+ commit : Commit ,
153
+ path : str | None = None ,
154
+ filters : dict | None = None ,
155
+ ) -> (
156
+ list [File | Dir ] | MissingHeadReport | MissingCoverage | UnknownFlags | UnknownPath
157
+ ):
161
158
# TODO: Might need to add reports here filtered by flags in the future
162
- commit_report = report_service .build_report_from_commit (
159
+ report = report_service .build_report_from_commit (
163
160
commit , report_class = ReadOnlyReport
164
161
)
165
- if not commit_report :
162
+ if not report :
166
163
return MissingHeadReport ()
167
164
168
165
if filters is None :
@@ -189,9 +186,9 @@ def resolve_path_contents(commit: Commit, info, path: str = None, filters=None):
189
186
190
187
for component in filtered_components :
191
188
component_paths .extend (component .paths )
192
- if commit_report .flags :
189
+ if report .flags :
193
190
component_flags .extend (
194
- component .get_matching_flags (commit_report .flags .keys ())
191
+ component .get_matching_flags (report .flags .keys ())
195
192
)
196
193
197
194
if component_flags :
@@ -200,11 +197,11 @@ def resolve_path_contents(commit: Commit, info, path: str = None, filters=None):
200
197
else :
201
198
flags_filter = component_flags
202
199
203
- if flags_filter and not commit_report .flags :
200
+ if flags_filter and not report .flags :
204
201
return UnknownFlags (f"No coverage with chosen flags: { flags_filter } " )
205
202
206
203
report_paths = ReportPaths (
207
- report = commit_report ,
204
+ report = report ,
208
205
path = path ,
209
206
search_term = search_value ,
210
207
filter_flags = flags_filter ,
@@ -214,32 +211,33 @@ def resolve_path_contents(commit: Commit, info, path: str = None, filters=None):
214
211
if len (report_paths .paths ) == 0 :
215
212
# we do not know about this path
216
213
217
- if path_service .provider_path_exists (path , commit , current_owner ) is False :
214
+ if (
215
+ not path
216
+ or path_service .provider_path_exists (path , commit , current_owner ) is False
217
+ ):
218
218
# file doesn't exist
219
219
return UnknownPath (f"path does not exist: { path } " )
220
220
221
221
# we're just missing coverage for the file
222
222
return MissingCoverage (f"missing coverage for path: { path } " )
223
223
224
+ items : list [File | Dir ]
224
225
if search_value or display_type == PathContentDisplayType .LIST :
225
226
items = report_paths .full_filelist ()
226
227
else :
227
228
items = report_paths .single_directory ()
228
- return { "results" : sort_path_contents (items , filters )}
229
+ return sort_path_contents (items , filters )
229
230
230
231
231
- @commit_bindable .field ("deprecatedPathContents" )
232
+ @sentry_sdk .trace
233
+ @commit_bindable .field ("pathContents" )
232
234
@sync_to_async
233
- def resolve_deprecated_path_contents (
235
+ def resolve_path_contents (
234
236
commit : Commit ,
235
- info ,
236
- path : str = None ,
237
- filters = None ,
238
- first = None ,
239
- after = None ,
240
- last = None ,
241
- before = None ,
242
- ):
237
+ info : GraphQLResolveInfo ,
238
+ path : str | None = None ,
239
+ filters : dict | None = None ,
240
+ ) -> Any :
243
241
"""
244
242
The file directory tree is a list of all the files and directories
245
243
extracted from the commit report of the latest, head commit.
@@ -248,80 +246,43 @@ def resolve_deprecated_path_contents(
248
246
"""
249
247
current_owner = info .context ["request" ].current_owner
250
248
251
- # TODO: Might need to add reports here filtered by flags in the future
252
- commit_report = report_service .build_report_from_commit (
253
- commit , report_class = ReadOnlyReport
254
- )
255
- if not commit_report :
256
- return MissingHeadReport ()
249
+ contents = get_sorted_path_contents (current_owner , commit , path , filters )
250
+ if isinstance (contents , list ):
251
+ return {"results" : contents }
252
+ return contents
257
253
258
- if filters is None :
259
- filters = {}
260
- search_value = filters .get ("search_value" )
261
- display_type = filters .get ("display_type" )
262
-
263
- flags_filter = filters .get ("flags" , [])
264
- component_filter = filters .get ("components" , [])
265
-
266
- component_paths = []
267
- component_flags = []
268
-
269
- if component_filter :
270
- all_components = components_service .commit_components (commit , current_owner )
271
- filtered_components = components_service .filter_components_by_name_or_id (
272
- all_components , component_filter
273
- )
274
254
275
- if not filtered_components :
276
- return MissingCoverage (
277
- f"missing coverage for report with components: { component_filter } "
278
- )
279
-
280
- for component in filtered_components :
281
- component_paths .extend (component .paths )
282
- if commit_report .flags :
283
- component_flags .extend (
284
- component .get_matching_flags (commit_report .flags .keys ())
285
- )
286
-
287
- if component_flags :
288
- if flags_filter :
289
- flags_filter = list (set (flags_filter ) & set (component_flags ))
290
- else :
291
- flags_filter = component_flags
292
-
293
- if flags_filter and not commit_report .flags :
294
- return UnknownFlags (f"No coverage with chosen flags: { flags_filter } " )
295
-
296
- report_paths = ReportPaths (
297
- report = commit_report ,
298
- path = path ,
299
- search_term = search_value ,
300
- filter_flags = flags_filter ,
301
- filter_paths = component_paths ,
302
- )
303
-
304
- if len (report_paths .paths ) == 0 :
305
- # we do not know about this path
306
-
307
- if path_service .provider_path_exists (path , commit , current_owner ) is False :
308
- # file doesn't exist
309
- return UnknownPath (f"path does not exist: { path } " )
310
-
311
- # we're just missing coverage for the file
312
- return MissingCoverage (f"missing coverage for path: { path } " )
313
-
314
- if search_value or display_type == PathContentDisplayType .LIST :
315
- items = report_paths .full_filelist ()
316
- else :
317
- items = report_paths .single_directory ()
318
-
319
- sorted_items = sort_path_contents (items , filters )
255
+ @commit_bindable .field ("deprecatedPathContents" )
256
+ @sync_to_async
257
+ def resolve_deprecated_path_contents (
258
+ commit : Commit ,
259
+ info : GraphQLResolveInfo ,
260
+ path : str | None = None ,
261
+ filters : dict | None = None ,
262
+ first : Any = None ,
263
+ after : Any = None ,
264
+ last : Any = None ,
265
+ before : Any = None ,
266
+ ) -> Any :
267
+ """
268
+ The file directory tree is a list of all the files and directories
269
+ extracted from the commit report of the latest, head commit.
270
+ The is resolver results in a list that represent the tree with files
271
+ and nested directories.
272
+ """
273
+ current_owner = info .context ["request" ].current_owner
320
274
321
- kwargs = {"first" : first , "after" : after , "last" : last , "before" : before }
275
+ contents = get_sorted_path_contents (current_owner , commit , path , filters )
276
+ if not isinstance (contents , list ):
277
+ return contents
322
278
323
279
return queryset_to_connection_sync (
324
- sorted_items , ordering_direction = OrderingDirection .ASC , ** kwargs
280
+ contents ,
281
+ ordering_direction = OrderingDirection .ASC ,
282
+ first = first ,
283
+ last = last ,
284
+ before = before ,
285
+ after = after ,
325
286
)
326
287
327
288
0 commit comments