Repository navigation
fix(github-provider): preserve old_filename and content on renames - #2776
IsmaelMartinez merged 2 commits into
Conversation
GithubProvider._get_diff_files never set FilePatchInfo.old_filename for a renamed file, and looked up the base-commit content at the file's new path instead of its previous_filename. For a same-content rename that lookup 404s, the resulting empty original content makes load_large_diff render the whole file as an addition instead of a 0-line diff. Mirrors the old_filename handling already used by the GitLab, local-git and generic diff-parsing providers. Fixes The-PR-Agent#2775
PR Summary by QodoFix GitHub rename diffs by preserving old_filename and fetching base content by old path
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
…iew path too The non-incremental base-commit lookup already used old_filename after b40c237; the incremental-review lookup (last_seen_commit_sha) still used the file's new path, so a rename inside an incremental review window hits the same 404-swallowed-to-empty-string bug this PR exists to fix. Also splits the previous_filename guard into a named boolean and switches to double-quoted string literals to match the file's Ruff config.
|
Code review by qodo was updated up to the latest commit f90cca9 |
|
Merged, thanks! The rename path had been quietly showing whole files as new, so this is a good one to have caught. |
|
Thanks for the quick merge. Glad it was worth catching, that whole-file-as-new rendering would have been an easy one to miss. |
PR Type
Bug fix
Description
For a pure GitHub rename (status
renamed, identical content, so GitHub omits.patchand reports 0 additions/0 deletions),
GithubProvider._get_diff_filesdoes two thingswrong:
FilePatchInfo.old_filename, even though PyGithub'sFileobjectexposes
previous_filenamefor a rename. The GitLab, local-git and genericdiff-parsing providers all populate
old_filenamefrom the equivalent field; theGitHub provider was the one that dropped it.
(
_get_pr_file_content(file, merge_base_commit.sha)), which does not exist at thatcommit, since the file lived under the OLD path there. The 404 is swallowed by
get_pr_file_content's blanketexcept: return "", sooriginal_file_content_strends up empty and
load_large_diff("", <full new content>)renders every line of thefile as a
+addition instead of a 0-line diff.The fix computes
old_filenamefromfile.previous_filenamewhenfile.status == 'renamed', passes it through toFilePatchInfo, and uses it as the path for thebase-commit content lookup (mirroring
gitlab_provider.py'sold_path/new_pathsplit).
_get_pr_file_contentgained an optionalpathoverride for that purpose.This is the same mechanism
#1452fixed for the Azure DevOps provider and#2580/#2581fixed for the local-git provider; the GitHub provider was never covered.Verification
tests/unittest/test_github_provider_urls_and_diffs.py(
TestGetDiffFilesRename) drive the real_get_diff_files/FilePatchInfoconstruction with only the PyGithub network boundary faked. Two of the three fail on
unmodified
mainand pass on this branch; the third is a negative-case check(non-renamed files keep
old_filename is None) that passes on both.tests/unittestsuite: 1977 passed, 1 skipped, 1 xfailed, 0 failed (Docker,docker/Dockerfile --target test, same image and command as thebuild-and-testCI job).
_get_diff_filesfor a 40-line same-contentrename, confirming
old_filenameis preserved and the patch is a 0/0 diff instead of a40-line addition.
self.incremental.last_seen_commit_sha),which has the same shape but a rename mid-review is a different, unverified scenario;
left untouched.
verify_cmd:docker build -f docker/Dockerfile --target test -t pr-agent-test . && docker run --rm pr-agent-test python -m pytest tests/unittest -qFixes #2775