Skip to content

Commit 7e38026

Browse files
Copilotpelikhan
andauthored
Fix temporary ID updates in comments
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 054c518 commit 7e38026

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

actions/setup/js/safe_output_handler_manager.cjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,26 @@ async function processMessages(messageHandlers, messages, onItemCreated = null)
11661166
// Check if this output was created with unresolved temporary IDs
11671167
// For create_issue, create_discussion, add_comment - check if body has unresolved IDs
11681168

1169-
// Handle add_comment which returns an array of comments
1169+
// Handle the current add_comment result shape.
1170+
if (messageType === "add_comment" && result?.commentId && result?.repo) {
1171+
const contentToCheck = getContentToCheck(messageType, message, result);
1172+
if (contentToCheck && hasUnresolvedTemporaryIds(contentToCheck, temporaryIdMap, artifactUrlMap)) {
1173+
core.info(`Comment ${result.commentId} on ${result.repo}#${result.itemNumber} was created with unresolved temporary IDs - tracking for update`);
1174+
outputsWithUnresolvedIds.push({
1175+
type: messageType,
1176+
message,
1177+
result: {
1178+
commentId: result.commentId,
1179+
itemNumber: result.itemNumber,
1180+
repo: result.repo,
1181+
isDiscussion: result.isDiscussion,
1182+
},
1183+
originalTempIdMapSize: tempIdMapSizeBefore,
1184+
});
1185+
}
1186+
}
1187+
1188+
// Handle the legacy add_comment result shape.
11701189
if (messageType === "add_comment" && Array.isArray(result)) {
11711190
const contentToCheck = getContentToCheck(messageType, message, result);
11721191
if (contentToCheck && hasUnresolvedTemporaryIds(contentToCheck, temporaryIdMap, artifactUrlMap)) {

actions/setup/js/safe_output_handler_manager.test.cjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,44 @@ describe("Safe Output Handler Manager", () => {
153153

154154
expect(sortMessageIndicesByTemporaryIdDependencies([dependent, producer, unrelated])).toEqual([1, 0, 2]);
155155
});
156+
157+
it("tracks a comment emitted before its temporary-ID producer", async () => {
158+
const callOrder = [];
159+
const handlers = new Map([
160+
[
161+
"add_comment",
162+
vi.fn(async (_message, resolvedTemporaryIds) => {
163+
callOrder.push("add_comment");
164+
expect(resolvedTemporaryIds).toEqual({});
165+
return { success: true, commentId: 123, itemNumber: 42, repo: "owner/repo", isDiscussion: false };
166+
}),
167+
],
168+
[
169+
"create_issue",
170+
vi.fn(async () => {
171+
callOrder.push("create_issue");
172+
return { success: true, temporaryId: "aw_track1", repo: "owner/tracker", number: 99 };
173+
}),
174+
],
175+
]);
176+
const messages = [
177+
{ type: "add_comment", item_number: 42, body: "Tracking issue: #aw_track1" },
178+
{ type: "create_issue", temporary_id: "aw_track1", title: "Tracking issue" },
179+
];
180+
181+
const result = await processMessages(handlers, messages);
182+
183+
expect(callOrder).toEqual(["add_comment", "create_issue"]);
184+
expect(result.temporaryIdMap.aw_track1).toEqual({ repo: "owner/tracker", number: 99 });
185+
expect(result.outputsWithUnresolvedIds).toEqual([
186+
{
187+
type: "add_comment",
188+
message: { type: "add_comment", item_number: 42, body: "Tracking issue: #aw_track1" },
189+
result: { commentId: 123, itemNumber: 42, repo: "owner/repo", isDiscussion: false },
190+
originalTempIdMapSize: 0,
191+
},
192+
]);
193+
});
156194
});
157195

158196
describe("logCreatedItemFromResult", () => {

0 commit comments

Comments
 (0)