Skip to content

Commit

Permalink
Fix changes not being detected as doc-only for added/deleted files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackenmen committed Jun 18, 2023
1 parent f5589e7 commit 38eb998
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/label_doconly_changes/base_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

class FileInfoDict(TypedDict):
filename: str
contents_before: str
contents_after: str
contents_before: str | None
contents_after: str | None


class HookInputDict(TypedDict):
Expand Down Expand Up @@ -73,7 +73,7 @@ class FileInfo:
__slots__ = ("filename", "contents_before", "contents_after")

def __init__(
self, filename: str, contents_before: str, contents_after: str
self, filename: str, contents_before: str | None, contents_after: str | None
) -> None:
self.filename = filename
self.contents_before = contents_before
Expand All @@ -82,11 +82,7 @@ def __init__(
@classmethod
def from_filename(cls, filename: str, *, base_ref: str) -> FileInfo:
contents_before = _get_file_from_ref(ref=base_ref, filename=filename)
if contents_before is None:
raise FileNotFoundError("only exists on the head branch.")
contents_after = _get_file_from_ref(ref="HEAD", filename=filename)
if contents_after is None:
raise FileNotFoundError("only exists on the base branch.")

return cls(filename, contents_before, contents_after)

Expand Down
6 changes: 6 additions & 0 deletions src/label_doconly_changes/hooks/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ class PythonHook(Hook):
def run(self, app: App, file_data: list[FileInfo]) -> HookOutputDict:
hook_output = HookOutput()
for file_info in file_data:
if file_info.contents_before is None:
hook_output.fail(file_info.filename, "only exists on the head branch.")
continue
if file_info.contents_after is None:
hook_output.fail(file_info.filename, "only exists on the base branch.")
continue
try:
analyzer = PythonAnalyzer(
file_info.contents_before, file_info.contents_after
Expand Down

0 comments on commit 38eb998

Please sign in to comment.