Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/queue-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,27 @@ jobs:
const pr = context.payload.pull_request;
const refs = [...new Set((pr.title + ' ' + (pr.body || '')).match(/#\d+/g) || [])];
const found = new Map();
// The search is a prefilter, not the answer. GitHub's tokenizer does not treat
// '#' as part of a word, so a query for "#607" is really a query for the token
// 607 and matches any text containing those digits — a byte count, a timing, a
// throughput figure. That is how #271 came to be reported as citing #607: its
// body measures 6,607 appends/s, and '6,607' tokenizes on the comma. PR bodies
// here carry measurements routinely, so this is the common case, not a corner.
// Every hit is therefore re-checked against the text the search already returns
// (free — no extra request), and only a literal reference survives.
const cites = (item, ref) => {
const n = ref.slice(1);
// '#N' or an issues/N | pull/N URL tail, and not the prefix of a longer
// number: #607 must not answer for #6071.
const rx = new RegExp('(#|(?:issues|pull)\\/)' + n + '(?!\\d)');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize GH-N issue references

When a newly opened PR cites #607 but an existing open PR uses GitHub’s supported GH-607 shorthand for the same issue, the search prefilter returns the existing PR but this regex rejects it, silently hiding a genuine overlap that the previous implementation reported. Accept the GH- prefix as another literal reference form.

AGENTS.md reference: AGENTS.md:L30-L31

Useful? React with 👍 / 👎.

return rx.test((item.title || '') + ' ' + (item.body || ''));
};
for (const ref of refs.slice(0, 8)) {
const q = 'repo:' + context.repo.owner + '/' + context.repo.repo +
' is:pr is:open "' + ref + '" in:title,body';
const res = await github.rest.search.issuesAndPullRequests({ q, per_page: 10 });
for (const item of res.data.items)
if (item.number !== pr.number && !found.has(item.number))
if (item.number !== pr.number && !found.has(item.number) && cites(item, ref))
found.set(item.number, ref);
}
const marker = '<!-- queue-guard-overlap -->';
Expand Down
Loading