Skip to content

Commit 415847e

Browse files
committed
Fix release comment command escaping
1 parent 8d79c82 commit 415847e

2 files changed

Lines changed: 52 additions & 35 deletions

File tree

scripts/release-comments.ts

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function findBoundingTags() {
4747
`-l ${PACKAGE_NAME}@*`,
4848
"--sort -creatordate",
4949
"--format %\\(refname:strip=2\\)",
50-
].join(" "),
50+
],
5151
true,
5252
);
5353
let stableGitTags = stdout
@@ -79,7 +79,7 @@ function getCommits(from: Tag, to: Tag): Array<string> {
7979
"--pretty=format:%H",
8080
`${from.raw}...${to.raw}`,
8181
DIRECTORY_TO_CHECK!,
82-
].join(" "),
82+
],
8383
true,
8484
);
8585

@@ -99,21 +99,17 @@ async function commentOnPrAndLinkedIssues(pr: MergedPR, latest: Tag) {
9999
debug(`[dry-run] would comment on PR #${pr.number}`);
100100
} else {
101101
// Comment on PR
102-
logAndExec(
103-
["gh", "pr", "comment", String(pr.number), "--body", prComment].join(" "),
104-
);
102+
logAndExec(["gh", "pr", "comment", String(pr.number), "--body", prComment]);
105103

106104
// Remove PR labels
107-
logAndExec(
108-
[
109-
"gh",
110-
"pr",
111-
"edit",
112-
String(pr.number),
113-
"--remove-label",
114-
PR_LABELS_TO_REMOVE,
115-
].join(" "),
116-
);
105+
logAndExec([
106+
"gh",
107+
"pr",
108+
"edit",
109+
String(pr.number),
110+
"--remove-label",
111+
PR_LABELS_TO_REMOVE,
112+
]);
117113
}
118114

119115
let promises = pr.issues.map((issue) => commentOnIssue(issue, latest));
@@ -153,32 +149,33 @@ async function commentOnIssue(issue: number, latest: Tag) {
153149
);
154150
} else {
155151
// Comment on linked issue
156-
logAndExec(
157-
["gh", "issue", "comment", String(issue), "--body", issueComment].join(
158-
" ",
159-
),
160-
);
152+
logAndExec([
153+
"gh",
154+
"issue",
155+
"comment",
156+
String(issue),
157+
"--body",
158+
issueComment,
159+
]);
161160

162161
// Close linked issue
163162
if (shouldClose) {
164-
logAndExec(["gh", "issue", "close", String(issue)].join(" "));
163+
logAndExec(["gh", "issue", "close", String(issue)]);
165164
} else {
166165
debug(
167166
`Skipping close of issue #${issue} due to "${ISSUE_LABELS_TO_KEEP_OPEN}" label`,
168167
);
169168
}
170169

171170
// Remove labels from linked issue
172-
logAndExec(
173-
[
174-
"gh",
175-
"issue",
176-
"edit",
177-
String(issue),
178-
"--remove-label",
179-
ISSUE_LABELS_TO_REMOVE,
180-
].join(" "),
181-
);
171+
logAndExec([
172+
"gh",
173+
"issue",
174+
"edit",
175+
String(issue),
176+
"--remove-label",
177+
ISSUE_LABELS_TO_REMOVE,
178+
]);
182179
}
183180
}
184181

@@ -233,7 +230,7 @@ async function findMergedPRs(
233230
"merged",
234231
"--json",
235232
"number,title,url,body",
236-
].join(" "),
233+
],
237234
true,
238235
);
239236

@@ -302,7 +299,7 @@ function getIssuesLinkedToPullRequest(prHtmlUrl: string): Array<number> {
302299
"--paginate",
303300
`--field prHtmlUrl=${prHtmlUrl}`,
304301
`--raw-field query='${trimNewlines(query)}'`,
305-
].join(" "),
302+
],
306303
true,
307304
);
308305

@@ -349,7 +346,7 @@ function getIssueLabels(number: string): Array<string> {
349346
`--field repo=${repo}`,
350347
`--field number=${number}`,
351348
`--raw-field query='${trimNewlines(query)}'`,
352-
].join(" "),
349+
],
353350
true,
354351
);
355352

scripts/utils/process.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,27 @@ export function getRootDir(): string {
1515
return process.cwd();
1616
}
1717

18-
export function logAndExec(command: string, captureOutput = false): string {
18+
export function logAndExec(args: string[], captureOutput?: boolean): string;
19+
export function logAndExec(command: string, captureOutput?: boolean): string;
20+
export function logAndExec(
21+
commandOrArgs: string | string[],
22+
captureOutput = false,
23+
): string {
24+
let command: string;
25+
if (typeof commandOrArgs === "string") {
26+
command = commandOrArgs;
27+
} else {
28+
command = [
29+
commandOrArgs[0],
30+
// Quote each argument
31+
...commandOrArgs
32+
.slice(1)
33+
.map((arg) =>
34+
arg.startsWith("-") ? arg : `'${arg.replaceAll("'", "'\\''")}'`,
35+
),
36+
].join(" ");
37+
}
38+
1939
console.log(`$ ${command}`);
2040
if (captureOutput) {
2141
return cp.execSync(command, { stdio: "pipe", encoding: "utf-8" }).trim();

0 commit comments

Comments
 (0)