Skip to content

Commit 5a6bff2

Browse files
Copilotpelikhan
andauthored
Preserve add-comment metadata during ID updates
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 7e38026 commit 5a6bff2

2 files changed

Lines changed: 51 additions & 15 deletions

File tree

actions/setup/js/safe_output_handler_manager.cjs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,12 +1174,7 @@ async function processMessages(messageHandlers, messages, onItemCreated = null)
11741174
outputsWithUnresolvedIds.push({
11751175
type: messageType,
11761176
message,
1177-
result: {
1178-
commentId: result.commentId,
1179-
itemNumber: result.itemNumber,
1180-
repo: result.repo,
1181-
isDiscussion: result.isDiscussion,
1182-
},
1177+
result,
11831178
originalTempIdMapSize: tempIdMapSizeBefore,
11841179
});
11851180
}
@@ -1196,12 +1191,7 @@ async function processMessages(messageHandlers, messages, onItemCreated = null)
11961191
outputsWithUnresolvedIds.push({
11971192
type: messageType,
11981193
message: message,
1199-
result: {
1200-
commentId: comment._tracking.commentId,
1201-
itemNumber: comment._tracking.itemNumber,
1202-
repo: comment._tracking.repo,
1203-
isDiscussion: comment._tracking.isDiscussion,
1204-
},
1194+
result: { ...comment, ...comment._tracking },
12051195
originalTempIdMapSize: tempIdMapSizeBefore,
12061196
});
12071197
}
@@ -1403,7 +1393,7 @@ function getContentToCheck(messageType, message, result) {
14031393
case "create_discussion":
14041394
return message.body || "";
14051395
case "add_comment":
1406-
return message.body || "";
1396+
return result?.body || message.body || "";
14071397
case "comment_memory":
14081398
return result?.managedBody || message.body || "";
14091399
case "create_pull_request":
@@ -2045,4 +2035,5 @@ module.exports = {
20452035
partitionFailureResults,
20462036
computeSafeOutputsStatus,
20472037
setSafeOutputsStatusOutputs,
2038+
processSyntheticUpdates,
20482039
};

actions/setup/js/safe_output_handler_manager.test.cjs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
partitionFailureResults,
2222
computeSafeOutputsStatus,
2323
setSafeOutputsStatusOutputs,
24+
processSyntheticUpdates,
2425
} from "./safe_output_handler_manager.cjs";
2526

2627
const require = createRequire(import.meta.url);
@@ -162,7 +163,14 @@ describe("Safe Output Handler Manager", () => {
162163
vi.fn(async (_message, resolvedTemporaryIds) => {
163164
callOrder.push("add_comment");
164165
expect(resolvedTemporaryIds).toEqual({});
165-
return { success: true, commentId: 123, itemNumber: 42, repo: "owner/repo", isDiscussion: false };
166+
return {
167+
success: true,
168+
commentId: 123,
169+
itemNumber: 42,
170+
repo: "owner/repo",
171+
isDiscussion: false,
172+
body: "Tracking issue: #aw_track1\n\nHandler footer marker",
173+
};
166174
}),
167175
],
168176
[
@@ -186,11 +194,48 @@ describe("Safe Output Handler Manager", () => {
186194
{
187195
type: "add_comment",
188196
message: { type: "add_comment", item_number: 42, body: "Tracking issue: #aw_track1" },
189-
result: { commentId: 123, itemNumber: 42, repo: "owner/repo", isDiscussion: false },
197+
result: {
198+
success: true,
199+
commentId: 123,
200+
itemNumber: 42,
201+
repo: "owner/repo",
202+
isDiscussion: false,
203+
body: "Tracking issue: #aw_track1\n\nHandler footer marker",
204+
},
190205
originalTempIdMapSize: 0,
191206
},
192207
]);
193208
});
209+
210+
it("updates the posted comment body while retaining handler metadata", async () => {
211+
const updateComment = vi.fn().mockResolvedValue({});
212+
const github = { rest: { issues: { updateComment } } };
213+
const trackedOutputs = [
214+
{
215+
type: "add_comment",
216+
message: { type: "add_comment", body: "Tracking issue: #aw_track1" },
217+
result: {
218+
success: true,
219+
commentId: 123,
220+
itemNumber: 42,
221+
repo: "owner/repo",
222+
isDiscussion: false,
223+
body: "Tracking issue: #aw_track1\n\nHandler footer marker",
224+
},
225+
originalTempIdMapSize: 0,
226+
},
227+
];
228+
229+
const updateCount = await processSyntheticUpdates(github, {}, trackedOutputs, new Map([["aw_track1", { repo: "owner/tracker", number: 99 }]]), new Map());
230+
231+
expect(updateCount).toBe(1);
232+
expect(updateComment).toHaveBeenCalledWith({
233+
owner: "owner",
234+
repo: "repo",
235+
comment_id: 123,
236+
body: "Tracking issue: owner/tracker#99\n\nHandler footer marker",
237+
});
238+
});
194239
});
195240

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

0 commit comments

Comments
 (0)