Add command to fix templates (#21)
* add command to fix templates * replaceAll and lint fixes * fixed menu * fix lint command and run it * add basic error handling for listing of templates * CR suggestions --------- Co-authored-by: Arwid Thornström <arwidt@gmail.com>
This commit is contained in:
co-authored by
Arwid Thornström
parent
bc9ba08e76
commit
724f3905ab
@@ -2,7 +2,7 @@ const { system, filesystem } = require('gluegun');
|
||||
|
||||
const src = filesystem.path(__dirname, '..');
|
||||
|
||||
const cli = async cmd =>
|
||||
const cli = async (cmd) =>
|
||||
system.run('node ' + filesystem.path(src, 'bin', 'pwcli') + ` ${cmd}`);
|
||||
|
||||
test('outputs version', async () => {
|
||||
|
||||
Generated
-14199
File diff suppressed because it is too large
Load Diff
+6
-5
@@ -8,7 +8,7 @@
|
||||
"pwcli": "bin/pwcli"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "prettier --write **/*.{js,ts,tsx,json}",
|
||||
"format": "prettier --write './**/*.{js,ts,json}'",
|
||||
"clean-build": "rm -rf ./build",
|
||||
"compile": "tsc -p .",
|
||||
"copy-templates": "if [ -e ./src/templates ]; then cp -a ./src/templates ./build/; fi",
|
||||
@@ -31,6 +31,7 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@lenne.tech/gluegun-menu": "^0.0.5",
|
||||
"@mailchimp/mailchimp_transactional": "^1.0.59",
|
||||
"@octokit/core": "^3.5.1",
|
||||
"chalk": "^4.1.2",
|
||||
"cli-select": "^1.1.2",
|
||||
@@ -43,15 +44,15 @@
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.18",
|
||||
"@types/node": "^12.7.11",
|
||||
"jest": "^24.1.0",
|
||||
"prettier": "^1.12.1",
|
||||
"ts-jest": "^24.1.0",
|
||||
"ts-node": "^8.4.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
||||
"@typescript-eslint/parser": "^5.44.0",
|
||||
"eslint": "^8.28.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"jest": "^24.1.0",
|
||||
"prettier": "^2.0.0",
|
||||
"ts-jest": "^24.1.0",
|
||||
"ts-node": "^8.4.1",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"jest": {
|
||||
|
||||
+3
-3
@@ -11,16 +11,16 @@ async function run(argv) {
|
||||
.plugins('./node_modules', { matching: 'pwcli-*', hidden: true })
|
||||
.plugin(__dirname + '/../node_modules/@lenne.tech/gluegun-menu/dist', {
|
||||
commandFilePattern: '*.js',
|
||||
extensionFilePattern: '*.js'
|
||||
extensionFilePattern: '*.js',
|
||||
})
|
||||
.help({
|
||||
name: 'help',
|
||||
alias: 'h',
|
||||
hidden: false,
|
||||
dashed: true,
|
||||
run: toolbox => {
|
||||
run: (toolbox) => {
|
||||
toolbox.print.info('This is the help');
|
||||
}
|
||||
},
|
||||
}) // provides default for help, h, --help, -h
|
||||
// .version() // provides default for version, v, --version, -v
|
||||
.create();
|
||||
|
||||
@@ -8,5 +8,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = {
|
||||
strings.trim(await system.run(`aws logs describe-log-groups`))
|
||||
);
|
||||
|
||||
const options = groups.logGroups.map(item => {
|
||||
const options = groups.logGroups.map((item) => {
|
||||
return item.logGroupName;
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ module.exports = {
|
||||
message: 'Choose a logGroup',
|
||||
limit: 30,
|
||||
initial: options.length - 1,
|
||||
choices: options
|
||||
choices: options,
|
||||
});
|
||||
|
||||
const logGroup = await prompt.run();
|
||||
@@ -36,16 +36,16 @@ module.exports = {
|
||||
`${logGroup}`,
|
||||
'--follow',
|
||||
'--format',
|
||||
'short'
|
||||
'short',
|
||||
]);
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stdout.on('data', function(data) {
|
||||
child.stdout.on('data', function (data) {
|
||||
print.info(data);
|
||||
});
|
||||
child.stderr.on('data', data => {
|
||||
child.stderr.on('data', (data) => {
|
||||
console.error(`stderr: ${data}`);
|
||||
});
|
||||
child.on('close', code => {
|
||||
child.on('close', (code) => {
|
||||
console.log(`child process exited with code ${code}`);
|
||||
});
|
||||
}
|
||||
@@ -53,5 +53,5 @@ module.exports = {
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ module.exports = {
|
||||
|
||||
filesystem.file('/tmp/.pwcli_parametercache', {
|
||||
mode: '600',
|
||||
content: JSON.stringify(valueNames)
|
||||
content: JSON.stringify(valueNames),
|
||||
});
|
||||
await sleep(2000);
|
||||
|
||||
@@ -62,7 +62,7 @@ module.exports = {
|
||||
message: 'Choose a parameter (esc to exit)',
|
||||
limit: 30,
|
||||
initial: 10,
|
||||
choices: valueNames
|
||||
choices: valueNames,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -87,5 +87,5 @@ module.exports = {
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('aws', defaultMenuSettings);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -11,5 +11,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('aws pipeline', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ module.exports = {
|
||||
// });
|
||||
|
||||
const curratedPipes: Pipeline[] = pipelines.pipelines.filter(Boolean);
|
||||
const options = curratedPipes.map(item => {
|
||||
const options = curratedPipes.map((item) => {
|
||||
return item.name;
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ module.exports = {
|
||||
message: 'Choose a pipeline',
|
||||
limit: options.length - 1,
|
||||
initial: options.length - 1,
|
||||
choices: options
|
||||
choices: options,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -104,5 +104,5 @@ module.exports = {
|
||||
} else {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,5 +8,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('deployment', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ const getConfirmation = async (branchName: string, stackName: string) => {
|
||||
name: 'confirm',
|
||||
message: `Will create ${chalk.yellow(
|
||||
url + '.photowall-test.xx'
|
||||
)} and publish ${chalk.green(branchName)} to it, continue?`
|
||||
)} and publish ${chalk.green(branchName)} to it, continue?`,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -49,27 +49,27 @@ module.exports = {
|
||||
'Photowall',
|
||||
'photowall'
|
||||
);
|
||||
const branchOptions = branches.map(item => item.name);
|
||||
const branchOptions = branches.map((item) => item.name);
|
||||
|
||||
const promptBranch = new AutoComplete({
|
||||
name: 'branchName',
|
||||
message: 'Select a branch',
|
||||
limit: 10,
|
||||
initial: 10,
|
||||
choices: branchOptions
|
||||
choices: branchOptions,
|
||||
});
|
||||
const branchName = await promptBranch.run();
|
||||
|
||||
const testStacks = await getTestStacksInfo(toolbox);
|
||||
const testStacks = await getTestStacksInfo(toolbox);
|
||||
|
||||
const options = testStacks.map(item => {
|
||||
const options = testStacks.map((item) => {
|
||||
return item.name;
|
||||
});
|
||||
|
||||
const input = new Input({
|
||||
type: 'input',
|
||||
name: 'stack',
|
||||
message: `Subdomain of new server (${chalk.yellow('test-xxx')})`
|
||||
message: `Subdomain of new server (${chalk.yellow('test-xxx')})`,
|
||||
});
|
||||
const stacksuffix = await input.run();
|
||||
const stackName = `photowall-${stacksuffix}`;
|
||||
@@ -117,7 +117,7 @@ module.exports = {
|
||||
);
|
||||
const output = await system.run(cmd, {
|
||||
cwd: `${config.photowall_repo}/cloudformation/`,
|
||||
trim: true
|
||||
trim: true,
|
||||
});
|
||||
print.fancy(output);
|
||||
}
|
||||
@@ -131,5 +131,5 @@ module.exports = {
|
||||
defaultMenuSettings
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ const getConfirmation = async (stackName: string) => {
|
||||
name: 'confirm',
|
||||
message: `The stack ${chalk.yellow(stackName)} will be ${chalk.red.bold(
|
||||
'deleted'
|
||||
)}`
|
||||
)}`,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -23,7 +23,7 @@ const getConfirmation = async (stackName: string) => {
|
||||
const confirmCommand = async (cmd: string) => {
|
||||
const confirm = new Confirm({
|
||||
name: 'confirm',
|
||||
message: `RUN COMMAND > [${chalk.yellow(cmd)}] ?`
|
||||
message: `RUN COMMAND > [${chalk.yellow(cmd)}] ?`,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -54,7 +54,7 @@ module.exports = {
|
||||
|
||||
const testStacks = await getTestStacksInfo(toolbox);
|
||||
|
||||
const options = testStacks.map(item => {
|
||||
const options = testStacks.map((item) => {
|
||||
return item.name;
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ module.exports = {
|
||||
message: 'Choose a server',
|
||||
limit: options.length - 1,
|
||||
initial: options.length - 1,
|
||||
choices: options
|
||||
choices: options,
|
||||
});
|
||||
|
||||
const stackName = await prompt.run();
|
||||
@@ -119,5 +119,5 @@ module.exports = {
|
||||
defaultMenuSettings
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -60,7 +60,7 @@ module.exports = {
|
||||
return {
|
||||
issue: issueNumber,
|
||||
status: getStatusIcon(issueData ? issueData.state : 'null'),
|
||||
issueUpdated: issueData ? issueData.updated_at : null
|
||||
issueUpdated: issueData ? issueData.updated_at : null,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ module.exports = {
|
||||
issueNumber: string
|
||||
) => {
|
||||
const issueStatus = issueStatuses.find(
|
||||
issueStatus => issueStatus.issue === issueNumber
|
||||
(issueStatus) => issueStatus.issue === issueNumber
|
||||
);
|
||||
return issueStatus ? issueStatus.status : getStatusIcon('null');
|
||||
};
|
||||
@@ -125,7 +125,7 @@ module.exports = {
|
||||
'branch',
|
||||
'issue status',
|
||||
'issue updated',
|
||||
'stack updated'
|
||||
'stack updated',
|
||||
// 'url'
|
||||
])
|
||||
.line('-');
|
||||
@@ -161,19 +161,19 @@ module.exports = {
|
||||
ellipsis(stack.branch, 24),
|
||||
printIssueStatus(issueStatuses, branchIssueNumber),
|
||||
issueStatuses.find(
|
||||
issueStatus => issueStatus.issue === branchIssueNumber
|
||||
(issueStatus) => issueStatus.issue === branchIssueNumber
|
||||
)
|
||||
? timeSince(
|
||||
new Date(
|
||||
issueStatuses.find(
|
||||
issueStatus => issueStatus.issue === branchIssueNumber
|
||||
(issueStatus) => issueStatus.issue === branchIssueNumber
|
||||
).issueUpdated
|
||||
).getTime()
|
||||
)
|
||||
: '-',
|
||||
!isNaN(t.getTime())
|
||||
? timeSince(t.getTime())
|
||||
: timeSince(new Date(stack.created).getTime())
|
||||
: timeSince(new Date(stack.created).getTime()),
|
||||
// stackUrl(stack.name)
|
||||
]);
|
||||
}
|
||||
@@ -185,5 +185,5 @@ module.exports = {
|
||||
defaultMenuSettings
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -11,5 +11,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
defaultMenuSettings,
|
||||
getCurrentBranch,
|
||||
getSettings,
|
||||
sleep
|
||||
sleep,
|
||||
} from '../../../../globals';
|
||||
|
||||
type Stack = {
|
||||
@@ -30,7 +30,7 @@ const getBranchName = async (
|
||||
type: 'input',
|
||||
name: 'branch',
|
||||
message: 'What github branch should be deployed?',
|
||||
initial: currentBranch
|
||||
initial: currentBranch,
|
||||
});
|
||||
const responseBranch = await input.run();
|
||||
|
||||
@@ -43,7 +43,7 @@ const getBranchName = async (
|
||||
{
|
||||
owner: 'photowall',
|
||||
repo: 'photowall',
|
||||
branch: responseBranch
|
||||
branch: responseBranch,
|
||||
}
|
||||
);
|
||||
if (response.status === 200) {
|
||||
@@ -60,7 +60,7 @@ const getConfirmation = async (branchName: string, stackName: string) => {
|
||||
name: 'confirm',
|
||||
message: `The branch ${chalk.green(
|
||||
branchName
|
||||
)} will deploy to ${chalk.yellow(stackName)}`
|
||||
)} will deploy to ${chalk.yellow(stackName)}`,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -101,7 +101,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
const testStacks = await getTestStacksInfo(toolbox);
|
||||
const options = testStacks.map(item => {
|
||||
const options = testStacks.map((item) => {
|
||||
return item.name;
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ module.exports = {
|
||||
message: 'Choose a server',
|
||||
limit: options.length - 1,
|
||||
initial: options.length - 1,
|
||||
choices: options
|
||||
choices: options,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -128,7 +128,7 @@ module.exports = {
|
||||
);
|
||||
const output = await system.run(cmd, {
|
||||
cwd: `${config.photowall_repo}/cloudformation/`,
|
||||
trim: true
|
||||
trim: true,
|
||||
});
|
||||
print.fancy(output);
|
||||
|
||||
@@ -185,5 +185,5 @@ module.exports = {
|
||||
} else {
|
||||
exit();
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import {
|
||||
confirmMessage,
|
||||
defaultMenuSettings,
|
||||
getSettings,
|
||||
} from '../../../globals';
|
||||
import mailchimpFactory from '@mailchimp/mailchimp_transactional';
|
||||
const { AutoComplete } = require('enquirer');
|
||||
|
||||
module.exports = {
|
||||
name: 'fix_template',
|
||||
alias: ['ft'],
|
||||
description:
|
||||
'Remove any incorrect artifacts caused by Mailchimp export to Mandrill from selected template',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { print } = toolbox;
|
||||
|
||||
// Load settings
|
||||
const config = await getSettings(toolbox);
|
||||
if (!config || !config.mandrill_api_key || config.mandrill_api_key === '') {
|
||||
print.error(`
|
||||
|
||||
This commands requires that you set a Mandrill API key.
|
||||
|
||||
`);
|
||||
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||
return;
|
||||
}
|
||||
|
||||
const mailchimp = mailchimpFactory(config.mandrill_api_key);
|
||||
|
||||
const fixTemplate = async ({ name, code }) => {
|
||||
const regexPreviewText = /\*\|MC_PREVIEW_TEXT\|\*/gi;
|
||||
const regexRemoveDoubleHttp = /http(s?):\/\/\{\{/gi;
|
||||
const anyMailChimpTemplateLanguageStart = /\*\|}/g;
|
||||
const anyMailChimpTemplateLanguageEnd = /{\|\*/g;
|
||||
const fixedBody = code
|
||||
.replace(regexPreviewText, '')
|
||||
.replaceAll(regexRemoveDoubleHttp, '{{')
|
||||
.replaceAll(anyMailChimpTemplateLanguageStart, '{{')
|
||||
.replaceAll(anyMailChimpTemplateLanguageEnd, '}}');
|
||||
console.log(`Updating ${name}`);
|
||||
return mailchimp.templates.update({
|
||||
name,
|
||||
code: fixedBody,
|
||||
});
|
||||
};
|
||||
|
||||
const spinner = print.spin(`Fetching available templates...`);
|
||||
const templates = await mailchimp.templates.list();
|
||||
spinner.stop();
|
||||
if (typeof templates !== 'object' || !templates.length) {
|
||||
print.error(
|
||||
'Could not fetch templates, does your API key have the right permissions or restricts access for your current IP?'
|
||||
);
|
||||
return;
|
||||
}
|
||||
const templateNames = templates.map(({ name }) => name);
|
||||
|
||||
const prompt = new AutoComplete({
|
||||
name: 'templates',
|
||||
message: 'Choose a template',
|
||||
limit: 10,
|
||||
initial: 10,
|
||||
choices: templateNames,
|
||||
});
|
||||
|
||||
try {
|
||||
const templateName = await prompt.run();
|
||||
const templateToFix = templates.find(({ name }) => name === templateName);
|
||||
|
||||
if (await confirmMessage(`Run fixer on ${templateToFix.name}?`)) {
|
||||
await fixTemplate(templateToFix);
|
||||
}
|
||||
} catch (error) {
|
||||
print.error(error);
|
||||
}
|
||||
|
||||
print.success('Done');
|
||||
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('mandrill', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import { defaultMenuSettings } from '../../globals';
|
||||
|
||||
module.exports = {
|
||||
name: 'mandrill',
|
||||
alias: ['m'],
|
||||
description: 'Mandrill (m)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('mandrill', defaultMenuSettings);
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import { GluegunCommand } from 'gluegun'
|
||||
import { GluegunCommand } from 'gluegun';
|
||||
|
||||
const command: GluegunCommand = {
|
||||
name: 'pwcli',
|
||||
@@ -9,7 +8,7 @@ const command: GluegunCommand = {
|
||||
const { print } = toolbox;
|
||||
print.info('Welcome to photowall CLI for everything, almost 😬');
|
||||
await toolbox.menu.showMenu(null);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = command;
|
||||
|
||||
@@ -108,7 +108,8 @@ module.exports = {
|
||||
if (!config) {
|
||||
config = {
|
||||
gh_token: '',
|
||||
photowall_repo: ''
|
||||
photowall_repo: '',
|
||||
mandrill_api_key: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,12 +117,17 @@ module.exports = {
|
||||
message: `A github accesstoken is required with ${chalk.yellow(
|
||||
'Full control of private repositories'
|
||||
)}, please insert the key >`,
|
||||
initial: config.gh_token
|
||||
initial: config.gh_token,
|
||||
}).run();
|
||||
|
||||
config.photowall_repo = await new Input({
|
||||
message: `If you want to be able to use current branch in your photowall repository\nor the create and update commands for testservers, please insert\nthe absolute path to the project or leave blank >`,
|
||||
initial: config.photowall_repo
|
||||
initial: config.photowall_repo,
|
||||
}).run();
|
||||
|
||||
config.mandrill_api_key = await new Input({
|
||||
message: `If you want to be able to use the mailchimp commands, please insert\nyour mailchimp api key. Otherwise leave blank >`,
|
||||
initial: config.mandrill_api_key,
|
||||
}).run();
|
||||
|
||||
print.info(`
|
||||
@@ -133,7 +139,7 @@ module.exports = {
|
||||
await new Confirm({
|
||||
message: `Ok to save the these settings to ${chalk.yellow(
|
||||
`~/.pwcli_settings`
|
||||
)}?`
|
||||
)}?`,
|
||||
}).run()
|
||||
) {
|
||||
await system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
|
||||
@@ -145,5 +151,5 @@ module.exports = {
|
||||
|
||||
if (toolbox.fromMenu())
|
||||
await toolbox.menu.showMenu(null, defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -11,5 +11,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import {
|
||||
confirmMessage,
|
||||
defaultMenuSettings,
|
||||
getSettings
|
||||
getSettings,
|
||||
} from '../../../../globals';
|
||||
|
||||
module.exports = {
|
||||
@@ -50,12 +50,9 @@ module.exports = {
|
||||
// If there is a match, then prompt user and ask to remove it
|
||||
const regex = /\[.*: gone\]/;
|
||||
const branchesToDelete = localBranchesArray
|
||||
.filter(branch => regex.test(branch))
|
||||
.map(branch => {
|
||||
return strings
|
||||
.trim(branch)
|
||||
.replace(' ', '{space}')
|
||||
.split('{space}')[0];
|
||||
.filter((branch) => regex.test(branch))
|
||||
.map((branch) => {
|
||||
return strings.trim(branch).replace(' ', '{space}').split('{space}')[0];
|
||||
});
|
||||
|
||||
if (branchesToDelete.length > 0) {
|
||||
@@ -72,5 +69,5 @@ module.exports = {
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('workflow git', defaultMenuSettings);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,5 +8,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('workflow git', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
confirmMessage,
|
||||
defaultMenuSettings,
|
||||
getSettings,
|
||||
issueToBranchName
|
||||
issueToBranchName,
|
||||
} from '../../../globals';
|
||||
import { getIssueFromRepo, getOrgIssues } from '../../../services/github_rest';
|
||||
const { AutoComplete } = require('enquirer');
|
||||
@@ -27,9 +27,9 @@ module.exports = {
|
||||
}
|
||||
|
||||
const repos = await getOrgIssues(toolbox, config.gh_token);
|
||||
const issueOptions = repos.flatMap(repo => {
|
||||
const issueOptions = repos.flatMap((repo) => {
|
||||
return repo.issues.map(
|
||||
issue => `${issue.number}-${repo.repo}-${issue.title}`
|
||||
(issue) => `${issue.number}-${repo.repo}-${issue.title}`
|
||||
);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ module.exports = {
|
||||
message: 'Select issue',
|
||||
limit: 5,
|
||||
initial: 5,
|
||||
choices: issueOptions
|
||||
choices: issueOptions,
|
||||
});
|
||||
const issueResponse = await promptIssues.run();
|
||||
const issueNumber = issueResponse.split('-')[0];
|
||||
@@ -59,15 +59,15 @@ module.exports = {
|
||||
) {
|
||||
await system.run(`git checkout -b ${branchName} origin/master`, {
|
||||
cwd: config.photowall_repo,
|
||||
trim: true
|
||||
trim: true,
|
||||
});
|
||||
await system.run(`git push -u origin ${branchName}`, {
|
||||
cwd: config.photowall_repo,
|
||||
trim: true
|
||||
trim: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (toolbox.fromMenu())
|
||||
await toolbox.menu.showMenu('workflow', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -11,5 +11,5 @@ module.exports = {
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('workflow', defaultMenuSettings);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,8 +18,8 @@ export const getTestStacksInfo = async (
|
||||
strings.trim(await system.run(`aws cloudformation list-stacks`))
|
||||
);
|
||||
|
||||
const allStacks = await Promise.all(
|
||||
stacks.StackSummaries.map(async item => {
|
||||
const allStacks = (await Promise.all(
|
||||
stacks.StackSummaries.map(async (item) => {
|
||||
if (
|
||||
item.StackName.indexOf('photowall-test-') > -1 &&
|
||||
[
|
||||
@@ -29,7 +29,7 @@ export const getTestStacksInfo = async (
|
||||
'UPDATE_FAILED',
|
||||
'CREATE_FAILED',
|
||||
'CREATE_IN_PROGRESS',
|
||||
'ROLLBACK_COMPLETE'
|
||||
'ROLLBACK_COMPLETE',
|
||||
].includes(item.StackStatus)
|
||||
) {
|
||||
try {
|
||||
@@ -40,7 +40,7 @@ export const getTestStacksInfo = async (
|
||||
)
|
||||
)
|
||||
);
|
||||
const sourceStage = pipeline.pipeline.stages.filter(stage => {
|
||||
const sourceStage = pipeline.pipeline.stages.filter((stage) => {
|
||||
return stage.name === 'Source';
|
||||
});
|
||||
const branch =
|
||||
@@ -53,7 +53,7 @@ export const getTestStacksInfo = async (
|
||||
drift_status: item.DriftInformation.StackDriftStatus,
|
||||
branch: branch,
|
||||
updated: lastUpdated,
|
||||
created: item.CreationTime
|
||||
created: item.CreationTime,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
@@ -62,12 +62,12 @@ export const getTestStacksInfo = async (
|
||||
drift_status: '',
|
||||
branch: '',
|
||||
updated: '',
|
||||
created: item.CreationTime
|
||||
created: item.CreationTime,
|
||||
};
|
||||
}
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
})
|
||||
) as Stack[] | null;
|
||||
)) as Stack[] | null;
|
||||
return allStacks.filter(Boolean);
|
||||
};
|
||||
|
||||
+7
-6
@@ -4,12 +4,13 @@ const snakeCase = require('lodash.snakecase');
|
||||
const { Confirm } = require('enquirer');
|
||||
|
||||
export const defaultMenuSettings = {
|
||||
showHelp: false
|
||||
showHelp: false,
|
||||
};
|
||||
|
||||
export type TConfig = {
|
||||
gh_token: string;
|
||||
photowall_repo: string;
|
||||
mandrill_api_key: string;
|
||||
};
|
||||
export const getSettings = async (toolbox): Promise<TConfig | null> => {
|
||||
const { filesystem, print } = toolbox;
|
||||
@@ -40,7 +41,7 @@ export const getCurrentBranch = async (
|
||||
// git rev-parse --abbrev-ref HEAD
|
||||
const branch = await system.run('git rev-parse --abbrev-ref HEAD', {
|
||||
cwd: config.photowall_repo,
|
||||
trim: true
|
||||
trim: true,
|
||||
});
|
||||
console.log(`branch`, branch);
|
||||
return branch;
|
||||
@@ -48,14 +49,14 @@ export const getCurrentBranch = async (
|
||||
return null;
|
||||
};
|
||||
|
||||
export const issueToBranchName = issue => {
|
||||
export const issueToBranchName = (issue) => {
|
||||
return `${issue.number}-${snakeCase(issue.title).substr(0, 40)}`;
|
||||
};
|
||||
|
||||
export const confirmMessage = async (message: string) => {
|
||||
const confirm = new Confirm({
|
||||
name: 'confirm',
|
||||
message: message
|
||||
message: message,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -66,6 +67,6 @@ export const confirmMessage = async (message: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const sleep = milliseconds => {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
export const sleep = (milliseconds) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ export const getOrgRepos = async (toolbox, token, org) => {
|
||||
try {
|
||||
const response = await octokit.request('GET /orgs/{org}/repos', {
|
||||
org: org,
|
||||
per_page: 100
|
||||
per_page: 100,
|
||||
});
|
||||
if (response.status === 200) {
|
||||
return response.data;
|
||||
@@ -23,7 +23,7 @@ export const getRepo = async (toolbox, token, owner, repo) => {
|
||||
try {
|
||||
const response = await octokit.request('GET /repos/{owner}/{repo}', {
|
||||
owner: owner,
|
||||
repo: repo
|
||||
repo: repo,
|
||||
});
|
||||
if (response.status === 200) {
|
||||
return response.data;
|
||||
@@ -45,7 +45,7 @@ export const getRepoBranches = async (toolbox, token, owner, repo) => {
|
||||
owner: owner,
|
||||
repo: repo,
|
||||
page: page,
|
||||
per_page: 100
|
||||
per_page: 100,
|
||||
}
|
||||
);
|
||||
return response;
|
||||
@@ -70,9 +70,9 @@ export const getRepoBranches = async (toolbox, token, owner, repo) => {
|
||||
export const getOrgIssues = async (toolbox, token) => {
|
||||
// const { print } = toolbox;
|
||||
const repos = await getOrgRepos(toolbox, token, 'Photowall');
|
||||
const repoNames = repos.map(item => item.name);
|
||||
const repoNames = repos.map((item) => item.name);
|
||||
const allIssues = await Promise.all(
|
||||
repoNames.map(async repoName => {
|
||||
repoNames.map(async (repoName) => {
|
||||
const issues = await getOpenIssuesFromRepo(toolbox, token, repoName);
|
||||
// console.log(`${repoName} - issues`, issues.length);
|
||||
// return issues.map(item => `${item.number}-${item.title.substring(0, 10)}`);
|
||||
@@ -89,7 +89,7 @@ export const getOpenIssuesFromRepo = async (toolbox, token, repo) => {
|
||||
const response = await octokit.request('GET /repos/{owner}/{repo}/issues', {
|
||||
owner: 'Photowall',
|
||||
repo: repo,
|
||||
per_page: 100
|
||||
per_page: 100,
|
||||
});
|
||||
if (response.status === 200) {
|
||||
return response.data;
|
||||
@@ -109,7 +109,7 @@ export const getIssueFromRepo = async (toolbox, token, repo, issueNumber) => {
|
||||
{
|
||||
owner: 'Photowall',
|
||||
repo: repo,
|
||||
issue_number: issueNumber
|
||||
issue_number: issueNumber,
|
||||
}
|
||||
);
|
||||
if (response.status === 200) {
|
||||
@@ -134,7 +134,7 @@ export const createPullRequest = async (
|
||||
owner: 'Photowall',
|
||||
repo: repo,
|
||||
head: branch,
|
||||
base: 'master'
|
||||
base: 'master',
|
||||
});
|
||||
console.log(`response`, response);
|
||||
// if (response.status === 200) {
|
||||
|
||||
@@ -408,6 +408,13 @@
|
||||
resolved "https://registry.npmjs.org/@lenne.tech/gluegun-menu/-/gluegun-menu-0.0.5.tgz"
|
||||
integrity sha512-J/Tx4cFMn1nungGi7n3tJ2cvt0LJUeNuLAsDS9TbXtUomdz0/2kMZJq/m2HaUxWWeyIYSu4TSWGLIV8SQrgwTA==
|
||||
|
||||
"@mailchimp/mailchimp_transactional@^1.0.59":
|
||||
version "1.0.59"
|
||||
resolved "https://registry.yarnpkg.com/@mailchimp/mailchimp_transactional/-/mailchimp_transactional-1.0.59.tgz#2064b3e2976828aaae51ed4281562b7c1937f507"
|
||||
integrity sha512-jjTMZ78rxpYCKqO4888lSA+XMWzQ3Xcn+V+06aZJi8JDIeiY+VWNR7f2Ntyt389uN63W2TMDUu0I4Si1li7Z6g==
|
||||
dependencies:
|
||||
axios "^1.6.7"
|
||||
|
||||
"@nodelib/fs.scandir@2.1.5":
|
||||
version "2.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
|
||||
@@ -892,6 +899,15 @@ axios@^0.21.4:
|
||||
dependencies:
|
||||
follow-redirects "^1.14.0"
|
||||
|
||||
axios@^1.6.7:
|
||||
version "1.7.4"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.4.tgz#4c8ded1b43683c8dd362973c393f3ede24052aa2"
|
||||
integrity sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==
|
||||
dependencies:
|
||||
follow-redirects "^1.15.6"
|
||||
form-data "^4.0.0"
|
||||
proxy-from-env "^1.1.0"
|
||||
|
||||
babel-jest@^24.9.0:
|
||||
version "24.9.0"
|
||||
resolved "https://registry.npmjs.org/babel-jest/-/babel-jest-24.9.0.tgz"
|
||||
@@ -1217,7 +1233,7 @@ colors@1.4.0, colors@^1.1.2:
|
||||
resolved "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz"
|
||||
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
|
||||
|
||||
combined-stream@^1.0.6, combined-stream@~1.0.6:
|
||||
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
|
||||
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
|
||||
@@ -1900,6 +1916,11 @@ follow-redirects@^1.14.0:
|
||||
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz"
|
||||
integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==
|
||||
|
||||
follow-redirects@^1.15.6:
|
||||
version "1.15.6"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b"
|
||||
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==
|
||||
|
||||
for-each@^0.3.3:
|
||||
version "0.3.3"
|
||||
resolved "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz"
|
||||
@@ -1917,6 +1938,15 @@ forever-agent@~0.6.1:
|
||||
resolved "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz"
|
||||
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=
|
||||
|
||||
form-data@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
|
||||
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
form-data@~2.3.2:
|
||||
version "2.3.3"
|
||||
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz"
|
||||
@@ -3813,10 +3843,10 @@ prettier-linter-helpers@^1.0.0:
|
||||
dependencies:
|
||||
fast-diff "^1.1.2"
|
||||
|
||||
prettier@^1.12.1:
|
||||
version "1.19.1"
|
||||
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz"
|
||||
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
|
||||
prettier@^2.0.0:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
|
||||
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
|
||||
|
||||
pretty-format@^24.9.0:
|
||||
version "24.9.0"
|
||||
@@ -3836,6 +3866,11 @@ prompts@^2.0.1:
|
||||
kleur "^3.0.3"
|
||||
sisteransi "^1.0.5"
|
||||
|
||||
proxy-from-env@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
|
||||
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
|
||||
|
||||
psl@^1.1.28:
|
||||
version "1.8.0"
|
||||
resolved "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz"
|
||||
|
||||
Reference in New Issue
Block a user