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 66
77import github3
88import ruamel .yaml
9+ from exceptions import OptionalFileNotFoundError , check_optional_file
910from ruamel .yaml .scalarstring import SingleQuotedScalarString
1011
1112# Define data structure for dependabot.yaml
@@ -192,7 +193,7 @@ def build_dependabot_file(
192193 continue
193194 for file in manifest_files :
194195 try :
195- if repo . file_contents ( file ):
196+ if check_optional_file ( repo , file ):
196197 package_managers_found [manager ] = True
197198 make_dependabot_config (
198199 manager ,
@@ -204,7 +205,7 @@ def build_dependabot_file(
204205 extra_dependabot_config ,
205206 )
206207 break
207- except github3 . exceptions . NotFoundError :
208+ except OptionalFileNotFoundError :
208209 # The file does not exist and is not required,
209210 # so we should continue to the next one rather than raising error or logging
210211 pass
Original file line number Diff line number Diff line change 1111import requests
1212import ruamel .yaml
1313from dependabot_file import build_dependabot_file
14+ from exceptions import OptionalFileNotFoundError , check_optional_file
1415
1516
1617def main (): # pragma: no cover
@@ -314,10 +315,10 @@ def check_existing_config(repo, filename):
314315 """
315316 existing_config = None
316317 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 :
319320 return existing_config
320- except github3 . exceptions . NotFoundError :
321+ except OptionalFileNotFoundError :
321322 # The file does not exist and is not required,
322323 # so we should continue to the next one rather than raising error or logging
323324 pass
Original file line number Diff line number Diff line change @@ -36,9 +36,14 @@ def check_optional_file(repo, filename):
3636 """
3737 try :
3838 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
4247 except github3 .exceptions .NotFoundError as e :
4348 # Re-raise as our more specific exception type for better semantic clarity
4449 raise OptionalFileNotFoundError (resp = e .response ) from e
You can’t perform that action at this time.
0 commit comments