Conversation
…last one When multiple non-org-member usernames need to be removed from a CODEOWNERS file, the removal loop was replacing from the original content on each iteration. This meant only the last username's removal survived in the resulting PR. Initialize codeowners_file_contents_new with the decoded content and accumulate replacements so all removals are preserved. Fixes #380 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Zack Koppert <zkoppert@github.com>
1b90ed2 to
186600f
Compare
Replace bytes.replace() with re.sub() using a lookahead assertion (?=\s|$) so that removing @bob does not corrupt @bobsmith. The previous substring matching was a pre-existing issue, but the accumulation fix made it worse because corrupted content now persists across iterations instead of being overwritten. Also update the existing regression test to use the new regex pattern and add a dedicated test for the substring edge case. Closes #380 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Zack Koppert <zkoppert@github.com>
Collapse runs of multiple spaces/tabs to a single space and strip trailing whitespace from each line after usernames are removed. Without this, removing @bob from '@alice @bob @charlie' would leave a double space between @alice and @charlie. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Zack Koppert <zkoppert@github.com>
Change trailing whitespace pattern from [ \t]+$ to [ \t]+\r?$ so that spaces before \r\n are also stripped. Without this, Windows- style CRLF files would retain trailing spaces after username removal. Add dedicated CRLF test case to cover this edge case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Zack Koppert <zkoppert@github.com>
jmeridth
reviewed
Apr 7, 2026
Collaborator
jmeridth
left a comment
There was a problem hiding this comment.
Reviewed the PR — the core accumulation fix and substring matching fix are both correct and well-motivated. Two issues in the whitespace cleanup block worth addressing before merge.
Collaborator
Author
|
Great catches on both of those!! Addressing now. 🏃🏻 |
Address review feedback from jmeridth: 1. CRLF preservation: Change trailing whitespace regex from [\ \t]+\r?$ (which consumed \r) to [\t]+(?=\r?$) (lookahead preserves \r). 2. Scoped whitespace cleanup: Track which line indices had username removals via a changed_lines set, and only normalize whitespace on those lines. This prevents collapsing intentional alignment on unrelated CODEOWNERS lines. Also extract remove_username_from_content() and cleanup_whitespace() helper functions to reduce nesting depth in main() and make the logic directly testable. Add test_whitespace_cleanup_scoped_to_changed_lines to verify unrelated lines with intentional alignment are preserved. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Zack Koppert <zkoppert@github.com>
jmeridth
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Proposed Changes
Fixes the username removal loop in
main()so that removing multiple users from a CODEOWNERS file works correctly. Four issues are addressed:Accumulation bug (issue bug: only last username removal preserved when multiple users need removal from CODEOWNERS #380): The loop re-derived each removal from the original content, so only the last removal survived. Now initializes
codeowners_file_contents_new = codeowners_decodedbefore the loop and replaces from that accumulator each iteration.Substring matching bug (discovered during self-review):
bytes.replace(b"@bob", b"")corrupts@bobsmithintosmith. Replaced withre.sub()using a lookahead assertion(?=\s|$)so only exact handles are matched. The accumulation fix made this pre-existing issue worse because corrupted content now persists across iterations instead of being overwritten.Whitespace cleanup, scoped to changed lines (discovered during self-review, refined per review feedback): After removing a username, leftover double spaces and trailing whitespace are cleaned up. Uses
[ \t]{2,}to collapse horizontal whitespace and[ \t]+(?=\r?$)lookahead to strip trailing whitespace without consuming\rin CRLF files. Cleanup is scoped to only lines where a username was actually removed, preserving intentional alignment on unrelated lines.Extracted helper functions (per review feedback):
remove_username_from_content()andcleanup_whitespace()reduce nesting depth inmain()and make the removal/cleanup logic directly testable.Closes #380
Testing
test_multiple_username_removals_are_cumulative- verifies removing@aliceand@bobpreserves all removalstest_username_removal_does_not_corrupt_similar_names- verifies removing@bobleaves@bobsmithintacttest_username_removal_cleans_up_whitespace- verifies no double spaces left after removaltest_username_removal_handles_crlf_line_endings- verifies cleanup works with\r\nendings without consuming\rtest_whitespace_cleanup_scoped_to_changed_lines- verifies unrelated lines with intentional alignment are not modifiedmake lintclean (pylint 9.99/10, mypy, flake8, isort, black all pass)Readiness Checklist
Author/Contributor
make lintand fix any issues that you have introducedmake testand ensure you have test coverage for the lines you are introducing