Skip to content

fix: parse omitted hunk counts in find_line_number_of_relevant_line_in_file - #2699

Merged
IsmaelMartinez merged 3 commits into
The-PR-Agent:mainfrom
dwin-gharibi:fix/line-number-lookup-omitted-count
Aug 20, 2026
Merged

IsmaelMartinez merged 3 commits into
The-PR-Agent:mainfrom
dwin-gharibi:fix/line-number-lookup-omitted-count

Conversation

@dwin-gharibi

Copy link
Copy Markdown
Contributor

Closes #2698.

Description

Suggestions on files containing a single-line hunk silently lose their deep-link into the diff.

Root cause

find_line_number_of_relevant_line_in_file parsed hunk headers with map(int, match.groups()[:4]) at pr_agent/algo/utils.py:1151, :1173 and :1188, with no None handling. When a unified-diff count is omitted the group is None and int(None) raises.

This is a separate defect from the one in extract_hunk_headers: different function, and a hard exception rather than silently wrong numbers.

The fix

Reuse the shared extract_hunk_headers helper at all three sites, removing the duplicated parsing.

Behaviour change

Before @@ -1 +1 @@ → TypeError; suggestion link → ''
After @@ -1 +1 @@ → parsed; link → https://github.com/acme/app/pull/7/files#diff-…R1

The same helper is reached from create_inline_comment / publish_inline_comment in the GitHub, Bitbucket, Bitbucket Server and Gitea providers, which have no try/except — this removes a latent crash there too.

Files changed

pr_agent/algo/utils.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Testing

  • pytest tests/unittest — 1748 passed, 1 skipped, 1 xfailed (unchanged from main)
  • CI pipeline reproduced locally exactly as .github/workflows/build-and-test.yaml runs it:
    docker build -f docker/Dockerfile --target test .
    docker run --rm <image> pytest -v tests/unittest
    
    → 1748 passed, 1 skipped, 1 xfailed on python:3.12.13-slim
  • Targeted regression check for this defect: reproduced on main, no longer reproducible on this branch
  • ruff — no new findings vs main; isort — clean

Risk / compatibility

Behaviour for headers with explicit counts is unchanged.

Checklist

  • Focused on a single fix
  • Existing tests pass
  • No new dependencies
  • No user-facing configuration changes
  • Reviewed by a maintainer

Copilot AI lite review requested due to automatic review settings August 17, 2026 17:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

qodo-code-review Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Tests use single-quoted strings ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new regression tests use single quotes for FilePatchInfo values, patch contents, and function
arguments. The checklist requires double quotes for all new Python string literals.
Code

tests/unittest/test_find_line_number_of_relevant_line_in_file.py[R72-73]

+            FilePatchInfo(base_file='file1', head_file='file1',
+                          patch='@@ -1 +1 @@\n-alpha\n+ALPHA', filename='file1')
Relevance

●● Moderate

Recent unit-test quote-style precedents conflict: accepted in #2569, rejected in #2598.

PR-#2569
PR-#2598

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2694657 requires Python string literals to use double quotes. The added tests
contain multiple single-quoted literals, including base_file='file1', `patch='@@ -1 +1
@@\n-alpha\n+ALPHA', and '+ALPHA'`.

Rule 2694657: Use double quotes for all Python string literals
tests/unittest/test_find_line_number_of_relevant_line_in_file.py[72-89]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The newly added tests use single-quoted Python string literals, contrary to the required double-quote convention.

## Issue Context
Convert the new non-docstring literals without changing their contents or test behavior.

## Fix Focus Areas
- tests/unittest/test_find_line_number_of_relevant_line_in_file.py[72-89]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. Docstring lacks imperative phrasing ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
The new test docstring begins with the descriptive phrase git writes rather than an imperative
verb. This violates the required imperative phrasing for method docstrings.
Code

tests/unittest/test_find_line_number_of_relevant_line_in_file.py[R69-70]

+        """git writes '@@ -1 +1 @@' whenever a side spans exactly one line; the header must
+        be parsed instead of raising TypeError on int(None)."""
Relevance

● Weak

Recent identical imperative-docstring suggestion in unit tests was rejected.

PR-#2661

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2694688 requires newly added method docstrings to begin with imperative phrasing.
The added docstring starts with git writes, which narrates behavior rather than instructing with
an imperative verb.

Rule 2694688: Docstrings and comments must use imperative phrasing
tests/unittest/test_find_line_number_of_relevant_line_in_file.py[69-70]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new test method's docstring uses descriptive rather than imperative phrasing.

## Issue Context
Rewrite the first sentence to begin with an imperative verb while preserving its explanation of omitted hunk counts.

## Fix Focus Areas
- tests/unittest/test_find_line_number_of_relevant_line_in_file.py[69-70]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Grey Divider

Context sources
✅ Compliance rules (platform): 34 rules
Review mode: ⏭️ Skipped: The latest push only reformats test literals and revises a test docstring; it introduces no semantic or runtime behavior change.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@dwin-gharibi

Copy link
Copy Markdown
Contributor Author

@naorpeled

@dwin-gharibi
dwin-gharibi force-pushed the fix/line-number-lookup-omitted-count branch from 6ed79d5 to 3632876 Compare August 19, 2026 11:49
@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit 3632876

…): using double quotes and imperative phrasing
@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit 08ee1e4

@IsmaelMartinez IsmaelMartinez self-assigned this Aug 20, 2026
@IsmaelMartinez
IsmaelMartinez merged commit 6f5e88a into The-PR-Agent:main Aug 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError on an omitted hunk count, in a helper shared by six providers

3 participants