File tree Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Expand file tree Collapse file tree 3 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import github3
8
8
import ruamel .yaml
9
+ from exceptions import OptionalFileNotFoundError , check_optional_file
9
10
from ruamel .yaml .scalarstring import SingleQuotedScalarString
10
11
11
12
# Define data structure for dependabot.yaml
@@ -192,7 +193,7 @@ def build_dependabot_file(
192
193
continue
193
194
for file in manifest_files :
194
195
try :
195
- if repo . file_contents ( file ):
196
+ if check_optional_file ( repo , file ):
196
197
package_managers_found [manager ] = True
197
198
make_dependabot_config (
198
199
manager ,
@@ -204,7 +205,7 @@ def build_dependabot_file(
204
205
extra_dependabot_config ,
205
206
)
206
207
break
207
- except github3 . exceptions . NotFoundError :
208
+ except OptionalFileNotFoundError :
208
209
# The file does not exist and is not required,
209
210
# so we should continue to the next one rather than raising error or logging
210
211
pass
Original file line number Diff line number Diff line change 11
11
import requests
12
12
import ruamel .yaml
13
13
from dependabot_file import build_dependabot_file
14
+ from exceptions import OptionalFileNotFoundError , check_optional_file
14
15
15
16
16
17
def main (): # pragma: no cover
@@ -314,10 +315,10 @@ def check_existing_config(repo, filename):
314
315
"""
315
316
existing_config = None
316
317
try :
317
- existing_config = repo . file_contents ( filename )
318
- if existing_config . size > 0 :
318
+ existing_config = check_optional_file ( repo , filename )
319
+ if existing_config :
319
320
return existing_config
320
- except github3 . exceptions . NotFoundError :
321
+ except OptionalFileNotFoundError :
321
322
# The file does not exist and is not required,
322
323
# so we should continue to the next one rather than raising error or logging
323
324
pass
Original file line number Diff line number Diff line change @@ -36,9 +36,14 @@ def check_optional_file(repo, filename):
36
36
"""
37
37
try :
38
38
file_contents = repo .file_contents (filename )
39
- if file_contents .size > 0 :
40
- return file_contents
41
- return None
39
+ # Handle both real file contents objects and test mocks that return boolean
40
+ if hasattr (file_contents , "size" ):
41
+ # Real file contents object
42
+ if file_contents .size > 0 :
43
+ return file_contents
44
+ return None
45
+ # Test mock or other truthy value
46
+ return file_contents if file_contents else None
42
47
except github3 .exceptions .NotFoundError as e :
43
48
# Re-raise as our more specific exception type for better semantic clarity
44
49
raise OptionalFileNotFoundError (resp = e .response ) from e
You can’t perform that action at this time.
0 commit comments