Skip to content

Commit 846cc6c

Browse files
authored
Merge pull request #5285 from modelcontextprotocol/v2/chore/5067-sdk-watch-refresh-open-issue
fix(sdk-watch): refresh an open issue's rows and scope labels for the same target
2 parents d733056 + 7129ec2 commit 846cc6c

4 files changed

Lines changed: 721 additions & 37 deletions

File tree

‎scripts/lib/sweep.mjs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,31 @@ export function issueWriter({
386386
return { url, number };
387387
},
388388
/**
389+
* Labels are changed one by one, never replaced as a set, so a label
390+
* someone else applied survives an edit that does not name it.
391+
*
389392
* @param {number} number
390-
* @param {{title?: string, body: string}} change
393+
* @param {{title?: string, body: string, addLabels?: string[], removeLabels?: string[]}} change
391394
*/
392-
edit(number, { title, body }) {
395+
edit(number, { title, body, addLabels = [], removeLabels = [] }) {
393396
if (dryRun) {
394-
show(`edit #${number}`, { title }, body);
397+
show(
398+
`edit #${number}`,
399+
{
400+
title,
401+
"add labels": addLabels.length ? addLabels.join(", ") : undefined,
402+
"remove labels": removeLabels.length
403+
? removeLabels.join(", ")
404+
: undefined,
405+
},
406+
body,
407+
);
395408
return;
396409
}
397410
const args = ["issue", "edit", String(number), "--repo", repo];
398411
if (title !== undefined) args.push("--title", title);
412+
for (const label of addLabels) args.push("--add-label", label);
413+
for (const label of removeLabels) args.push("--remove-label", label);
399414
args.push("--body-file", "-");
400415
run(args, body, "gh issue edit");
401416
},

‎scripts/lib/sweep.test.mjs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,42 @@ test("issueWriter writes through gh with bodies on stdin", () => {
299299
assert.equal(calls[3].input, "C");
300300
});
301301

302+
test("issueWriter edits labels one by one, never as a set", () => {
303+
const { spawn, calls } = fakeSpawn(() => ({ status: 0 }));
304+
const writer = issueWriter({ repo: "o/r", spawn, sweep: "s", log: () => {} });
305+
writer.edit(7, {
306+
body: "B",
307+
addLabels: ["server-git"],
308+
removeLabels: ["server-time", "server-fetch"],
309+
});
310+
assert.deepEqual(calls[0].args, [
311+
"issue",
312+
"edit",
313+
"7",
314+
"--repo",
315+
"o/r",
316+
"--add-label",
317+
"server-git",
318+
"--remove-label",
319+
"server-time",
320+
"--remove-label",
321+
"server-fetch",
322+
"--body-file",
323+
"-",
324+
]);
325+
assert.ok(!calls[0].args.includes("--label"));
326+
327+
const lines = [];
328+
issueWriter({
329+
repo: "o/r",
330+
spawn: () => assert.fail("a dry run must not spawn"),
331+
dryRun: true,
332+
sweep: "s",
333+
log: (line) => lines.push(line),
334+
}).edit(7, { body: "B", addLabels: ["a"], removeLabels: ["b"] });
335+
assert.match(lines.join("\n"), /add labels: a\nremove labels: b/);
336+
});
337+
302338
test("issueWriter create without a milestone omits the flag", () => {
303339
const { spawn, calls } = fakeSpawn(() => ({
304340
status: 0,

0 commit comments

Comments
 (0)