Skip to content

Commit 8e2ad9f

Browse files
committed
fix(nx-heroku): wrap parameters with double quotes
1 parent 7388c5d commit 8e2ad9f

File tree

8 files changed

+44
-31
lines changed

8 files changed

+44
-31
lines changed

packages/nx-heroku/src/executors/common/heroku/addons.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export async function getAddons(
88
): Promise<{ addon_service: { name: string } }[]> {
99
const { stdout, stderr } = await exec(
1010
`heroku addons --app ${appName} --json`,
11-
{
12-
encoding: 'utf-8',
13-
}
11+
{ encoding: 'utf-8' }
1412
);
1513
if (!stderr) {
1614
return parseJsonString(stdout);
@@ -25,7 +23,7 @@ export async function addAddon(options: {
2523
addonName: string;
2624
}) {
2725
const { addonAlias, addonName, appName } = options;
28-
const baseCommand = `heroku addons:create ${addonName} -a ${appName}`;
26+
const baseCommand = `heroku addons:create ${addonName} --app ${appName}`;
2927
const command = addonAlias
3028
? `${baseCommand} --as ${addonAlias}`
3129
: baseCommand;

packages/nx-heroku/src/executors/common/heroku/apps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function appExists(options: {
5858
}): Promise<boolean> {
5959
try {
6060
// check if appName exists, throws an error if it doesn't
61-
const { stderr } = await exec(`heroku apps:info -a ${options.appName}`, {
61+
const { stderr } = await exec(`heroku apps:info --app ${options.appName}`, {
6262
encoding: 'utf-8',
6363
});
6464
if (stderr) {

packages/nx-heroku/src/executors/common/heroku/config-vars.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function getConfigVars(options: {
1414
appName: string;
1515
}): Promise<Record<string, string>> {
1616
const { appName } = options;
17-
const { stdout: configVars } = await exec(`heroku config --app=${appName}`, {
17+
const { stdout: configVars } = await exec(`heroku config --app ${appName}`, {
1818
encoding: 'utf-8',
1919
});
2020
const rawAppEnv = parseTable(configVars) || [];
@@ -80,7 +80,7 @@ export async function setConfigVars(options: {
8080
// outputs variables set to stdout key1: value1 \n key2: value2
8181
// outputs success message to stderr Setting <configVars keys comma separated> and restarting ${appName}...
8282
const { stdout = '' } = await exec(
83-
`heroku config:set --app=${appName} ${configVars.join(' ')}`
83+
`heroku config:set --app ${appName} ${configVars.join(' ')}`
8484
);
8585
const updatedConfigVarsMatrix = stdout
8686
.trim()

packages/nx-heroku/src/executors/common/heroku/drains.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ export async function getDrains(appName: string): Promise<
1515
url: string;
1616
}[]
1717
> {
18-
const { stdout, stderr } = await exec(`heroku drains -a ${appName} --json`, {
19-
encoding: 'utf-8',
20-
});
18+
const { stdout, stderr } = await exec(
19+
`heroku drains --app ${appName} --json`,
20+
{
21+
encoding: 'utf-8',
22+
}
23+
);
2124
if (stderr) {
2225
logger.warn(HerokuError.cleanMessage(stderr));
2326
return [];
@@ -47,7 +50,7 @@ export async function addDrain(options: {
4750
return 'found';
4851
}
4952
// output success to stdout: Successfully added drain ${drain.url}
50-
const { stderr } = await exec(`heroku drains:add ${url} -a ${appName}`);
53+
const { stderr } = await exec(`heroku drains:add ${url} --app ${appName}`);
5154
if (stderr) {
5255
throw new HerokuError(stderr);
5356
}

packages/nx-heroku/src/executors/common/heroku/members.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export async function getMembers(appName: string): Promise<
1717
privileges: { name: string; description: string }[];
1818
}[]
1919
> {
20-
const { stdout, stderr } = await exec(`heroku access -a ${appName} --json`, {
21-
encoding: 'utf-8',
22-
});
20+
const { stdout, stderr } = await exec(
21+
`heroku access --app ${appName} --json`,
22+
{ encoding: 'utf-8' }
23+
);
2324
if (stderr && !stdout) {
2425
throw new HerokuError(stderr);
2526
}
@@ -46,7 +47,7 @@ export async function addMember(options: {
4647
} else {
4748
// success message is sent to stderr : Adding ${serviceUser} access to the app ${appName}
4849
await exec(
49-
`heroku access:add ${serviceUser} -a ${appName} -p ${permissions}`
50+
`heroku access:add ${serviceUser} --app ${appName} --permissions "${permissions}"`
5051
);
5152
return 'created';
5253
}

packages/nx-heroku/src/executors/common/heroku/webhooks.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { HerokuError } from './error';
77
export async function getWebhooks(
88
appName: string
99
): Promise<{ id: string; url: string; include: string; level: string }[]> {
10-
const { stdout, stderr } = await exec(`heroku webhooks -a ${appName}`, {
10+
const { stdout, stderr } = await exec(`heroku webhooks --app ${appName}`, {
1111
encoding: 'utf-8',
1212
});
1313
if (stderr) {
@@ -47,11 +47,15 @@ export async function addWebhook(options: {
4747
const include = webhook.include.join(',');
4848
const webhooks = await getWebhooks(appName);
4949
const sameWebhookEndpoint = webhooks.find((hook) => hook.url === url);
50+
51+
const baseCommandParameters = `--app ${appName} --url ${url} --include "${include}" --level ${level}`;
52+
const commandParameters = secret
53+
? `${baseCommandParameters} --secret "${secret}"`
54+
: baseCommandParameters;
55+
5056
if (!sameWebhookEndpoint) {
5157
// output success to stderr : Adding webhook to ${appName}... done
52-
await exec(
53-
`heroku webhooks:add -u ${url} -i ${include} -l ${level} -s ${secret} -a ${appName}`
54-
);
58+
await exec(`heroku webhooks:add ${commandParameters}`);
5559
return 'created';
5660
} else if (
5761
sameWebhookEndpoint.id &&
@@ -60,7 +64,7 @@ export async function addWebhook(options: {
6064
) {
6165
// output success to stderr : Updating webhook ${sameWebhookEndpoint.id} for ${appName}... done
6266
await exec(
63-
`heroku webhooks:update ${sameWebhookEndpoint.id} -u ${url} -i ${include} -l ${level} -s ${secret} -a ${appName}`
67+
`heroku webhooks:update ${sameWebhookEndpoint.id} ${commandParameters}`
6468
);
6569
return 'updated';
6670
}

packages/nx-heroku/src/executors/deploy/schema.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
},
9393
"include": {
9494
"type": "array",
95-
"description": "The subscription scope",
95+
"description": "The subscription entities, https://devcenter.heroku.com/articles/app-webhooks#subscribing-to-webhooks-via-the-heroku-cli",
9696
"items": {
9797
"type": "string",
9898
"enum": [
@@ -120,7 +120,7 @@
120120
"description": "Webhook secret to override the one autogenerated by Heroku during webhook registration"
121121
}
122122
},
123-
"required": ["url", "include", "level", "secret"]
123+
"required": ["url", "include", "level"]
124124
},
125125
"drain": {
126126
"description": "Log drain to register on Heroku, see https://devcenter.heroku.com/articles/log-drains",

packages/nx-heroku/src/executors/deploy/services/heroku-app.service.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,19 @@ class HerokuApp {
112112
context.nxJsonConfiguration?.workspaceLayout?.appsDir || 'apps';
113113
}
114114

115-
private async addAndCommit(
115+
private async addAndCommitFile(
116116
projectName: string,
117-
pattern: string
117+
fileName: string
118118
): Promise<void> {
119119
try {
120-
//? allow custom commit message
120+
//? allow custom commit message with format from 'util'
121+
// const COMMIT_MESSAGE_TEMPLATE = '%s(%s): %s';
122+
// format(COMMIT_MESSAGE_TEMPLATE, conf.type, conf.scope, conf.message);
123+
const path = `${this.appsDir}/${projectName}/${fileName}`;
121124
await exec(
122-
`git add ${pattern} && git commit -m "ci(${projectName}): add ${pattern}" -n --no-gpg-sign`
125+
`git add ${path} && git commit -m "ci(${projectName}): add ${fileName}" -n --no-gpg-sign`
123126
);
124-
this.logger.info(`Wrote ${pattern} with custom configuration.`);
127+
this.logger.info(`Wrote ${path} with custom configuration.`);
125128
} catch (error) {
126129
const ex = error as ExecException;
127130
// there is (probably) nothing to commit
@@ -136,7 +139,7 @@ class HerokuApp {
136139
if (procfile) {
137140
const procfilePath = `${this.appsDir}/${projectName}/${PROCFILE}`;
138141
await writeFile(join(process.cwd(), procfilePath), procfile);
139-
await this.addAndCommit(projectName, PROCFILE);
142+
await this.addAndCommitFile(projectName, PROCFILE);
140143
}
141144
}
142145

@@ -157,7 +160,7 @@ class HerokuApp {
157160
if (destBuildPackFile === srcBuildPackFile) return;
158161

159162
await writeFile(destPath, srcBuildPackFile);
160-
await this.addAndCommit(projectName, buildPackFile);
163+
await this.addAndCommitFile(projectName, buildPackFile);
161164
}
162165
}
163166

@@ -325,10 +328,14 @@ class HerokuApp {
325328
args.push('--force');
326329
}
327330

328-
const push = spawn('git', args, { signal });
329-
//? if data contains `Everything up-to-date`, should we still restart the app
331+
console.warn({
332+
cwd: process.cwd(),
333+
cwd2: this.context.cwd,
334+
});
335+
const push = spawn('git', args, { signal, cwd: this.context.cwd });
330336
push.stdout
331337
.setEncoding('utf-8')
338+
//? if data contains `Everything up-to-date`, should we still restart the app ?
332339
.on('data', (data) => this.logger.info(data?.trim()));
333340

334341
push.stderr

0 commit comments

Comments
 (0)