Skip to content

fix: stop bare #N in comments, link text, colours and words becoming tickets - #4198

Merged
IsmaelMartinez merged 4 commits into
The-PR-Agent:mainfrom
jay23606:fix/4196-ticket-hash-refs
Oct 21, 2026
Merged

IsmaelMartinez merged 4 commits into
The-PR-Agent:mainfrom
jay23606:fix/4196-ticket-hash-refs

Conversation

@jay23606

@jay23606 jay23606 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

User description

Fixes #4196

Change

extract_ticket_links_from_pr_description treated every bare #N (up to six digits) as an issue of the PR's own repository. The default #N branch now skips a match when it is:

  • inside a closed HTML comment (<!-- Example: Closes #1234 -->),
  • the whole text of an HTML or Markdown link (<a href="...">#6211</a>, [#6211](...)),
  • glued to a word on either side (issue#12, #0a0a0a),
  • a Tailwind arbitrary value, where [ follows a word character or - (bg-[#121212], dark:bg-[#0a0a0a]).

Unchanged: explicit issue URLs, owner/repo#N shorthand, (#42), [#42], and the description_issue_regex path.

Design choice

The issue suggests these four rules. I did not follow the issue's wording for one case. The "glued to a word" rule does not apply when the glued text is an owner/repo#N tail, because x/my-org/my-repo#42 already resolves to local issue 42 and test_regression_mid_token_does_not_match_cross_repo pins that. Alternative for the maintainer: drop the before-side word check entirely, which would leave issue#12 resolving as a ticket.

Tests

Failing test first: tests/unittest/test_hash_reference_false_positives.py.

  • Before the fix: 9 failed, 5 passed (the 5 are controls for (#42), [#42], Fixes #42 and the real anchor/comment cases).
  • After the fix: that file passes in full.

Touched tests after the fix:

  • test_hash_reference_false_positives.py, test_github_issue_reference_extraction.py, test_ticket_compliance.py, test_ticket_compliance_non_list.py, test_extract_issue_from_branch.py, test_markdown_ticket_output_core.py: 280 passed.

Not verified: the full unit suite was not run. Only the ticket-extraction test files above were run, on Python 3.14 on Windows.

🤖 Generated with Claude Code


PR Type

Bug fix, Tests


Description

  • Ignore bare issue numbers in comments and links.

  • Reject word fragments and Tailwind colour values.

  • Preserve explicit references and custom regex behavior.

  • Add regression tests for false-positive ticket extraction.


Diagram Walkthrough

flowchart LR
  description["PR description"]
  extraction["Issue reference extraction"]
  filter["Filter non-reference bare #N matches"]
  tickets["Extracted ticket links"]
  description --> extraction
  extraction -- "Default bare references" --> filter
  filter -- "Valid references" --> tickets
  extraction -- "Explicit URLs, shorthand, custom regex" --> tickets
Loading

File Walkthrough

Relevant files
Bug fix
ticket_pr_compliance_check.py
Filter misleading bare hashes during ticket extraction     

pr_agent/tools/ticket_pr_compliance_check.py

  • Identify closed HTML comments and HTML or Markdown link text
    containing only #N.
  • Skip default bare references within those spans, glued to words, or
    inside Tailwind arbitrary values.
  • Preserve existing handling of explicit URLs, repository shorthand,
    custom regexes, and repository-like tails.
+32/-0   
Tests
test_hash_reference_false_positives.py
Cover false positives and valid issue references                 

tests/unittest/test_hash_reference_false_positives.py

  • Add regression coverage for HTML comments and HTML or Markdown link
    text.
  • Test rejection of word-adjacent hashes and Tailwind colour values.
  • Verify ordinary, parenthesized, and bracketed references remain
    extractable.
+57/-0   


⚙️ Agent run details
  • Model: openai/gpt-6.1-sol
  • Tokens: 7,007 in / 363 out / 7,370 total
  • Time cost: 11.1s
  • AI calls: 1

@the-pr-agent-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

4196 - Partially compliant

Compliant requirements:

  • Ignore Tailwind arbitrary colour values while preserving parenthesized and bracketed references.

Non-compliant requirements:

  • Ignore template-comment references when using description_issue_regex.
  • Ignore issue-number link text for all Markdown link forms.
  • Require non-word boundaries on both sides without the retained repository-tail exception.

Requires further human verification:

  • Confirm whether the documented repository-tail exception is acceptable despite the ticket's boundary requirement.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Custom-pattern bypass

Comment filtering runs only in the default-pattern branch. With description_issue_regex configured to capture the number in Closes #1234, <!-- Example: Closes #1234 --> still produces a local ticket. This leaves the ticket's explicitly reported custom-regex failure unresolved. Apply closed-comment filtering to custom matches as well.

elif custom_pattern is None:  # Default #123 format
    issue_number = match[6][1:]
    if _is_non_reference_hash(pr_description, match.start(), match.end(), non_reference_spans):
        continue
Reference-style links

The Markdown alternative recognizes only inline links. A valid reference-style link such as [#6211][release], with [release]: https://example.com/changelog elsewhere in the description, still produces a local issue despite its entire link text being #6211. Recognize reference-style links too, while preserving standalone [#42].

_HASH_LINK_TEXT_PATTERN = re.compile(r"<a\b[^>]*>\s*(#\d+)\s*</a\s*>|\[\s*(#\d+)\s*\]\(", re.IGNORECASE)

⚙️ Agent run details
  • Model: openai/gpt-6.1-sol
  • Tokens: 7,845 in / 745 out / 8,590 total
  • Time cost: 17.8s
  • AI calls: 1

@the-pr-agent-bot

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible bug
Handle quoted delimiters in HTML attributes

Handle quoted HTML attribute values when locating the end of an opening anchor tag.
Valid markup such as #42 currently
bypasses this filter and incorrectly creates a ticket reference.

pr_agent/tools/ticket_pr_compliance_check.py [21]

-_HASH_LINK_TEXT_PATTERN = re.compile(r"<a\b[^>]*>\s*(#\d+)\s*</a\s*>|\[\s*(#\d+)\s*\]\(", re.IGNORECASE)
+_HASH_LINK_TEXT_PATTERN = re.compile(
+    r"""<a\b(?:[^"'<>]|"[^"]*"|'[^']*')*>\s*(#\d+)\s*</a\s*>|\[\s*(#\d+)\s*\]\(""",
+    re.IGNORECASE,
+)
Suggestion importance[1-10]: 5

__

Why: The current [^>]* stops at a > inside a quoted attribute, allowing link text such as #42 to become a false ticket reference. The replacement correctly handles quoted attribute values while preserving the capture groups used by _non_reference_hash_spans.

Low

⚙️ Agent run details
  • Model: openai/gpt-6.1-sol
  • Tokens: 9,371 in / 1,193 out / 10,564 total
  • Time cost: 33.6s
  • AI calls: 2

@jay23606
jay23606 force-pushed the fix/4196-ticket-hash-refs branch from 3665003 to 8f63088 Compare October 20, 2026 09:56
jay23606 and others added 2 commits October 20, 2026 08:57
…tickets

A bare `#N` was read as an issue of the PR's own repository wherever it
appeared. Dependabot release notes link `#6211` to another repo, PR templates
keep example `Closes #1234` inside HTML comments, and Tailwind arbitrary
values such as `bg-[#121212]` produced bogus tickets like `issues/121212`.

The default `#N` branch now skips a match when it is:
- inside a closed HTML comment,
- the whole text of an HTML or Markdown link,
- glued to a word on either side (`issue#12`, `#0a0a0a`),
- a Tailwind arbitrary value (`[` preceded by a word or `-`).

An `owner/repo#N` tail keeps its existing behaviour. Explicit URLs and
shorthand references are unchanged, as is the `[#42]` and `(#42)` form.

Fixes #4196

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@jay23606
jay23606 force-pushed the fix/4196-ticket-hash-refs branch from 6a84036 to 13d72d4 Compare October 20, 2026 12:57

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @jay23606 for turning #4196 round the same day, failing tests first. Every default-path example from the issue now drops out, while Fixes #42, (#42), [#42], full issue URLs and owner/repo#N still resolve. Two asks before merge. The comment pattern, the anchor pattern and the any() over spans all go quadratic on long input, and new regexes here need to be linear-time; the first three suggestions keep every default-path result identical on real descriptions with one find pass, [^<>]* and a set lookup. #4196 also names description_issue_regex taking #1234 from a template comment; the second suggestion fixes that by seeding explicit_spans with the comment spans, and the last one pins it.

jay23606 and others added 2 commits October 20, 2026 17:49
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
Refs #4196

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IsmaelMartinez

Copy link
Copy Markdown
Collaborator

Thanks for working through all four suggestions, and for picking up the PR-Agent bot's quoted-attribute and reference-link cases too. One regression came in with the reference-link support: allowing a space between ] and ( or [ made Fixes [#42] (crash on start) and [#42] [#43] lose #42, which main still finds and Markdown does not render as a link. I've pushed that fix with two test cases and will merge once CI is green.

@IsmaelMartinez
IsmaelMartinez merged commit 4d1ecc1 into The-PR-Agent:main Oct 21, 2026
10 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.

Ticket extraction reads #N in Dependabot release notes, PR-template comments and CSS colours as issues of the PR's own repository

2 participants