Skip to content
Merged
Show file tree
Hide file tree
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
73 changes: 71 additions & 2 deletions .github/scripts/__tests__/agents-pr-meta-update-body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
extractIssueRefsFromText,
extractContextSectionWithPython,
upsertBlock,
run,
} = require('../agents_pr_meta_update_body.js');

test('extractContextSectionWithPython returns trimmed stdout from python', () => {
Expand Down Expand Up @@ -545,6 +546,7 @@ test('hasExplicitIssueSyncReference ignores heuristic issue-number sources', ()
assert.equal(hasExplicitIssueSyncReference({ body: 'Closes #123' }), true);
assert.equal(hasExplicitIssueSyncReference({ body: 'Related to #123' }), true);
assert.equal(hasExplicitIssueSyncReference({ body: 'Related to issue #123' }), true);
assert.equal(hasExplicitIssueSyncReference({ body: 'Refs #123' }), true);
assert.equal(hasExplicitIssueSyncReference({ body: 'References issue #123' }), true);
assert.equal(hasExplicitIssueSyncReference({ body: 'source issue #123' }), true);
assert.equal(hasExplicitIssueSyncReference({ body: 'This issue only mentions review follow-up PR #123' }), false);
Expand All @@ -556,9 +558,9 @@ test('extractExplicitIssueSyncNumbers returns only explicit issue references', (
assert.deepEqual(
Array.from(extractExplicitIssueSyncNumbers({
title: 'Review follow-up',
body: 'Closes #123\nReferences issue #456\nReview follow-up from PR #789',
body: 'Closes #123\nReferences issue #456\nRefs #234\nReview follow-up from PR #789',
})).sort((a, b) => a - b),
[123, 456],
[123, 234, 456],
);
});

Expand Down Expand Up @@ -678,6 +680,73 @@ test('resolveSourceContextRepairComment skips when no warning exists', async ()
assert.strictEqual(updated, false);
});

test('run leaves source repair warning unresolved when issue fetch fails', async () => {
const calls = {
listComments: 0,
updateComment: 0,
};
const github = {
paginate: async () => {
calls.listComments += 1;
return [{ id: 99, body: '<!-- missing-issue-warning -->\nstale warning' }];
},
rest: {
pulls: {
get: async () => ({
data: {
number: 55,
state: 'open',
title: 'Sync body',
body: 'Refs #123',
head: { sha: 'abc123', ref: 'codex/sync-body' },
labels: [],
},
}),
update: async () => {
throw new Error('should not update PR body');
},
},
issues: {
get: async () => {
throw new Error('issue not found');
},
listComments: {},
updateComment: async () => {
calls.updateComment += 1;
},
},
},
};
const failures = [];
const core = {
info: () => {},
debug: () => {},
warning: () => {},
error: () => {},
setFailed: (message) => failures.push(message),
};

await run({
github,
context: {
repo: { owner: 'octo', repo: 'demo' },
eventName: 'pull_request',
payload: {
pull_request: {
number: 55,
head: { sha: 'abc123' },
},
},
},
core,
inputs: {},
});

assert.strictEqual(calls.listComments, 0);
assert.strictEqual(calls.updateComment, 0);
assert.match(failures[0], /issue not found/);
});

// ========== fetchConnectorCheckboxStates tests ==========

test('fetchConnectorCheckboxStates extracts checked boxes from connector bot comments', async () => {
Expand Down
16 changes: 8 additions & 8 deletions .github/scripts/agents_pr_meta_update_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ function extractExplicitIssueSyncNumbers(pr = {}) {
const issueNumbers = new Set();
const patterns = [
/\b(?:close[sd]?|closing|fix(?:e[sd])?|fixing|resolve[sd]?|resolving|address(?:e[sd])?|addressing)\s*[:#-]?\s*#([0-9]+)\b/gi,
/\b(?:(?:relate[sd]?\s+to|references?)\s+(?:issue\s+)?|(?:source|github|linked)\s+issue\s*)[:#-]?\s*#([0-9]+)\b/gi,
/\b(?:(?:relate[sd]?\s+to|refs?|references?)\s+(?:issue\s+)?|(?:source|github|linked)\s+issue\s*)[:#-]?\s*#([0-9]+)\b/gi,
];
for (const pattern of patterns) {
for (const match of text.matchAll(pattern)) {
Expand Down Expand Up @@ -1488,6 +1488,13 @@ async function run({github: rawGithub, context, core, inputs}) {
return;
}

core.info(`Fetching content from issue #${issueNumber} for PR #${pr.number}`);
const issueResponse = await withRetries(
() => github.rest.issues.get({owner, repo, issue_number: issueNumber}),
{description: `issues.get #${issueNumber}`, core},
);
const issueBody = issueResponse.data.body || '';

try {
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
Expand All @@ -1507,13 +1514,6 @@ async function run({github: rawGithub, context, core, inputs}) {
core.warning(`Failed to resolve workflow source repair comment: ${error.message}`);
}

core.info(`Fetching content from issue #${issueNumber} for PR #${pr.number}`);
const issueResponse = await withRetries(
() => github.rest.issues.get({owner, repo, issue_number: issueNumber}),
{description: `issues.get #${issueNumber}`, core},
);
const issueBody = issueResponse.data.body || '';

if (!issueBody) {
core.warning(`Issue #${issueNumber} has no body content`);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ function extractExplicitIssueSyncNumbers(pr = {}) {
const issueNumbers = new Set();
const patterns = [
/\b(?:close[sd]?|closing|fix(?:e[sd])?|fixing|resolve[sd]?|resolving|address(?:e[sd])?|addressing)\s*[:#-]?\s*#([0-9]+)\b/gi,
/\b(?:(?:relate[sd]?\s+to|references?)\s+(?:issue\s+)?|(?:source|github|linked)\s+issue\s*)[:#-]?\s*#([0-9]+)\b/gi,
/\b(?:(?:relate[sd]?\s+to|refs?|references?)\s+(?:issue\s+)?|(?:source|github|linked)\s+issue\s*)[:#-]?\s*#([0-9]+)\b/gi,
];
for (const pattern of patterns) {
for (const match of text.matchAll(pattern)) {
Expand Down Expand Up @@ -1488,6 +1488,13 @@ async function run({github: rawGithub, context, core, inputs}) {
return;
}

core.info(`Fetching content from issue #${issueNumber} for PR #${pr.number}`);
const issueResponse = await withRetries(
() => github.rest.issues.get({owner, repo, issue_number: issueNumber}),
{description: `issues.get #${issueNumber}`, core},
);
const issueBody = issueResponse.data.body || '';

try {
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
Expand All @@ -1507,13 +1514,6 @@ async function run({github: rawGithub, context, core, inputs}) {
core.warning(`Failed to resolve workflow source repair comment: ${error.message}`);
}

core.info(`Fetching content from issue #${issueNumber} for PR #${pr.number}`);
const issueResponse = await withRetries(
() => github.rest.issues.get({owner, repo, issue_number: issueNumber}),
{description: `issues.get #${issueNumber}`, core},
);
const issueBody = issueResponse.data.body || '';

if (!issueBody) {
core.warning(`Issue #${issueNumber} has no body content`);
} else {
Expand Down
Loading