Skip to content

Commit 90abf46

Browse files
Copilotzkoppert
andcommitted
feat: Integrate OptionalFileNotFoundError into main application code
Co-authored-by: zkoppert <[email protected]>
1 parent e7338d3 commit 90abf46

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

dependabot_file.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import github3
88
import ruamel.yaml
9+
from exceptions import OptionalFileNotFoundError, check_optional_file
910
from 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

evergreen.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import requests
1212
import ruamel.yaml
1313
from dependabot_file import build_dependabot_file
14+
from exceptions import OptionalFileNotFoundError, check_optional_file
1415

1516

1617
def 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

exceptions.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)