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:
Anders Gustafsson
2024-08-16 09:34:15 +02:00
committed by GitHub
co-authored by Arwid Thornström
parent bc9ba08e76
commit 724f3905ab
28 changed files with 248 additions and 14310 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ const { system, filesystem } = require('gluegun');
const src = filesystem.path(__dirname, '..'); const src = filesystem.path(__dirname, '..');
const cli = async cmd => const cli = async (cmd) =>
system.run('node ' + filesystem.path(src, 'bin', 'pwcli') + ` ${cmd}`); system.run('node ' + filesystem.path(src, 'bin', 'pwcli') + ` ${cmd}`);
test('outputs version', async () => { test('outputs version', async () => {
-14199
View File
File diff suppressed because it is too large Load Diff
+6 -5
View File
@@ -8,7 +8,7 @@
"pwcli": "bin/pwcli" "pwcli": "bin/pwcli"
}, },
"scripts": { "scripts": {
"format": "prettier --write **/*.{js,ts,tsx,json}", "format": "prettier --write './**/*.{js,ts,json}'",
"clean-build": "rm -rf ./build", "clean-build": "rm -rf ./build",
"compile": "tsc -p .", "compile": "tsc -p .",
"copy-templates": "if [ -e ./src/templates ]; then cp -a ./src/templates ./build/; fi", "copy-templates": "if [ -e ./src/templates ]; then cp -a ./src/templates ./build/; fi",
@@ -31,6 +31,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@lenne.tech/gluegun-menu": "^0.0.5", "@lenne.tech/gluegun-menu": "^0.0.5",
"@mailchimp/mailchimp_transactional": "^1.0.59",
"@octokit/core": "^3.5.1", "@octokit/core": "^3.5.1",
"chalk": "^4.1.2", "chalk": "^4.1.2",
"cli-select": "^1.1.2", "cli-select": "^1.1.2",
@@ -43,15 +44,15 @@
"devDependencies": { "devDependencies": {
"@types/jest": "^24.0.18", "@types/jest": "^24.0.18",
"@types/node": "^12.7.11", "@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/eslint-plugin": "^5.44.0",
"@typescript-eslint/parser": "^5.44.0", "@typescript-eslint/parser": "^5.44.0",
"eslint": "^8.28.0", "eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1", "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" "typescript": "^3.6.3"
}, },
"jest": { "jest": {
+3 -3
View File
@@ -11,16 +11,16 @@ async function run(argv) {
.plugins('./node_modules', { matching: 'pwcli-*', hidden: true }) .plugins('./node_modules', { matching: 'pwcli-*', hidden: true })
.plugin(__dirname + '/../node_modules/@lenne.tech/gluegun-menu/dist', { .plugin(__dirname + '/../node_modules/@lenne.tech/gluegun-menu/dist', {
commandFilePattern: '*.js', commandFilePattern: '*.js',
extensionFilePattern: '*.js' extensionFilePattern: '*.js',
}) })
.help({ .help({
name: 'help', name: 'help',
alias: 'h', alias: 'h',
hidden: false, hidden: false,
dashed: true, dashed: true,
run: toolbox => { run: (toolbox) => {
toolbox.print.info('This is the help'); toolbox.print.info('This is the help');
} },
}) // provides default for help, h, --help, -h }) // provides default for help, h, --help, -h
// .version() // provides default for version, v, --version, -v // .version() // provides default for version, v, --version, -v
.create(); .create();
+1 -1
View File
@@ -8,5 +8,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('aws', defaultMenuSettings); await toolbox.menu.showMenu('aws', defaultMenuSettings);
} },
}; };
+7 -7
View File
@@ -16,7 +16,7 @@ module.exports = {
strings.trim(await system.run(`aws logs describe-log-groups`)) 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; return item.logGroupName;
}); });
@@ -25,7 +25,7 @@ module.exports = {
message: 'Choose a logGroup', message: 'Choose a logGroup',
limit: 30, limit: 30,
initial: options.length - 1, initial: options.length - 1,
choices: options choices: options,
}); });
const logGroup = await prompt.run(); const logGroup = await prompt.run();
@@ -36,16 +36,16 @@ module.exports = {
`${logGroup}`, `${logGroup}`,
'--follow', '--follow',
'--format', '--format',
'short' 'short',
]); ]);
child.stdout.setEncoding('utf8'); child.stdout.setEncoding('utf8');
child.stdout.on('data', function(data) { child.stdout.on('data', function (data) {
print.info(data); print.info(data);
}); });
child.stderr.on('data', data => { child.stderr.on('data', (data) => {
console.error(`stderr: ${data}`); console.error(`stderr: ${data}`);
}); });
child.on('close', code => { child.on('close', (code) => {
console.log(`child process exited with code ${code}`); console.log(`child process exited with code ${code}`);
}); });
} }
@@ -53,5 +53,5 @@ module.exports = {
if (toolbox.fromMenu()) { if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('aws', defaultMenuSettings); await toolbox.menu.showMenu('aws', defaultMenuSettings);
} }
} },
}; };
@@ -48,7 +48,7 @@ module.exports = {
filesystem.file('/tmp/.pwcli_parametercache', { filesystem.file('/tmp/.pwcli_parametercache', {
mode: '600', mode: '600',
content: JSON.stringify(valueNames) content: JSON.stringify(valueNames),
}); });
await sleep(2000); await sleep(2000);
@@ -62,7 +62,7 @@ module.exports = {
message: 'Choose a parameter (esc to exit)', message: 'Choose a parameter (esc to exit)',
limit: 30, limit: 30,
initial: 10, initial: 10,
choices: valueNames choices: valueNames,
}); });
try { try {
@@ -87,5 +87,5 @@ module.exports = {
if (toolbox.fromMenu()) { if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('aws', defaultMenuSettings); await toolbox.menu.showMenu('aws', defaultMenuSettings);
} }
} },
}; };
+1 -1
View File
@@ -11,5 +11,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('aws pipeline', defaultMenuSettings); await toolbox.menu.showMenu('aws pipeline', defaultMenuSettings);
} },
}; };
+3 -3
View File
@@ -35,7 +35,7 @@ module.exports = {
// }); // });
const curratedPipes: Pipeline[] = pipelines.pipelines.filter(Boolean); const curratedPipes: Pipeline[] = pipelines.pipelines.filter(Boolean);
const options = curratedPipes.map(item => { const options = curratedPipes.map((item) => {
return item.name; return item.name;
}); });
@@ -44,7 +44,7 @@ module.exports = {
message: 'Choose a pipeline', message: 'Choose a pipeline',
limit: options.length - 1, limit: options.length - 1,
initial: options.length - 1, initial: options.length - 1,
choices: options choices: options,
}); });
try { try {
@@ -104,5 +104,5 @@ module.exports = {
} else { } else {
exit(); exit();
} }
} },
}; };
+1 -1
View File
@@ -8,5 +8,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('deployment', defaultMenuSettings); await toolbox.menu.showMenu('deployment', defaultMenuSettings);
} },
}; };
@@ -12,7 +12,7 @@ const getConfirmation = async (branchName: string, stackName: string) => {
name: 'confirm', name: 'confirm',
message: `Will create ${chalk.yellow( message: `Will create ${chalk.yellow(
url + '.photowall-test.xx' url + '.photowall-test.xx'
)} and publish ${chalk.green(branchName)} to it, continue?` )} and publish ${chalk.green(branchName)} to it, continue?`,
}); });
try { try {
@@ -49,27 +49,27 @@ module.exports = {
'Photowall', 'Photowall',
'photowall' 'photowall'
); );
const branchOptions = branches.map(item => item.name); const branchOptions = branches.map((item) => item.name);
const promptBranch = new AutoComplete({ const promptBranch = new AutoComplete({
name: 'branchName', name: 'branchName',
message: 'Select a branch', message: 'Select a branch',
limit: 10, limit: 10,
initial: 10, initial: 10,
choices: branchOptions choices: branchOptions,
}); });
const branchName = await promptBranch.run(); 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; return item.name;
}); });
const input = new Input({ const input = new Input({
type: 'input', type: 'input',
name: 'stack', 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 stacksuffix = await input.run();
const stackName = `photowall-${stacksuffix}`; const stackName = `photowall-${stacksuffix}`;
@@ -117,7 +117,7 @@ module.exports = {
); );
const output = await system.run(cmd, { const output = await system.run(cmd, {
cwd: `${config.photowall_repo}/cloudformation/`, cwd: `${config.photowall_repo}/cloudformation/`,
trim: true trim: true,
}); });
print.fancy(output); print.fancy(output);
} }
@@ -131,5 +131,5 @@ module.exports = {
defaultMenuSettings defaultMenuSettings
); );
} }
} },
}; };
@@ -10,7 +10,7 @@ const getConfirmation = async (stackName: string) => {
name: 'confirm', name: 'confirm',
message: `The stack ${chalk.yellow(stackName)} will be ${chalk.red.bold( message: `The stack ${chalk.yellow(stackName)} will be ${chalk.red.bold(
'deleted' 'deleted'
)}` )}`,
}); });
try { try {
@@ -23,7 +23,7 @@ const getConfirmation = async (stackName: string) => {
const confirmCommand = async (cmd: string) => { const confirmCommand = async (cmd: string) => {
const confirm = new Confirm({ const confirm = new Confirm({
name: 'confirm', name: 'confirm',
message: `RUN COMMAND > [${chalk.yellow(cmd)}] ?` message: `RUN COMMAND > [${chalk.yellow(cmd)}] ?`,
}); });
try { try {
@@ -54,7 +54,7 @@ module.exports = {
const testStacks = await getTestStacksInfo(toolbox); const testStacks = await getTestStacksInfo(toolbox);
const options = testStacks.map(item => { const options = testStacks.map((item) => {
return item.name; return item.name;
}); });
@@ -63,7 +63,7 @@ module.exports = {
message: 'Choose a server', message: 'Choose a server',
limit: options.length - 1, limit: options.length - 1,
initial: options.length - 1, initial: options.length - 1,
choices: options choices: options,
}); });
const stackName = await prompt.run(); const stackName = await prompt.run();
@@ -119,5 +119,5 @@ module.exports = {
defaultMenuSettings defaultMenuSettings
); );
} }
} },
}; };
@@ -60,7 +60,7 @@ module.exports = {
return { return {
issue: issueNumber, issue: issueNumber,
status: getStatusIcon(issueData ? issueData.state : 'null'), 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 issueNumber: string
) => { ) => {
const issueStatus = issueStatuses.find( const issueStatus = issueStatuses.find(
issueStatus => issueStatus.issue === issueNumber (issueStatus) => issueStatus.issue === issueNumber
); );
return issueStatus ? issueStatus.status : getStatusIcon('null'); return issueStatus ? issueStatus.status : getStatusIcon('null');
}; };
@@ -125,7 +125,7 @@ module.exports = {
'branch', 'branch',
'issue status', 'issue status',
'issue updated', 'issue updated',
'stack updated' 'stack updated',
// 'url' // 'url'
]) ])
.line('-'); .line('-');
@@ -161,19 +161,19 @@ module.exports = {
ellipsis(stack.branch, 24), ellipsis(stack.branch, 24),
printIssueStatus(issueStatuses, branchIssueNumber), printIssueStatus(issueStatuses, branchIssueNumber),
issueStatuses.find( issueStatuses.find(
issueStatus => issueStatus.issue === branchIssueNumber (issueStatus) => issueStatus.issue === branchIssueNumber
) )
? timeSince( ? timeSince(
new Date( new Date(
issueStatuses.find( issueStatuses.find(
issueStatus => issueStatus.issue === branchIssueNumber (issueStatus) => issueStatus.issue === branchIssueNumber
).issueUpdated ).issueUpdated
).getTime() ).getTime()
) )
: '-', : '-',
!isNaN(t.getTime()) !isNaN(t.getTime())
? timeSince(t.getTime()) ? timeSince(t.getTime())
: timeSince(new Date(stack.created).getTime()) : timeSince(new Date(stack.created).getTime()),
// stackUrl(stack.name) // stackUrl(stack.name)
]); ]);
} }
@@ -185,5 +185,5 @@ module.exports = {
defaultMenuSettings defaultMenuSettings
); );
} }
} },
}; };
@@ -11,5 +11,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings); await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
} },
}; };
@@ -8,7 +8,7 @@ import {
defaultMenuSettings, defaultMenuSettings,
getCurrentBranch, getCurrentBranch,
getSettings, getSettings,
sleep sleep,
} from '../../../../globals'; } from '../../../../globals';
type Stack = { type Stack = {
@@ -30,7 +30,7 @@ const getBranchName = async (
type: 'input', type: 'input',
name: 'branch', name: 'branch',
message: 'What github branch should be deployed?', message: 'What github branch should be deployed?',
initial: currentBranch initial: currentBranch,
}); });
const responseBranch = await input.run(); const responseBranch = await input.run();
@@ -43,7 +43,7 @@ const getBranchName = async (
{ {
owner: 'photowall', owner: 'photowall',
repo: 'photowall', repo: 'photowall',
branch: responseBranch branch: responseBranch,
} }
); );
if (response.status === 200) { if (response.status === 200) {
@@ -60,7 +60,7 @@ const getConfirmation = async (branchName: string, stackName: string) => {
name: 'confirm', name: 'confirm',
message: `The branch ${chalk.green( message: `The branch ${chalk.green(
branchName branchName
)} will deploy to ${chalk.yellow(stackName)}` )} will deploy to ${chalk.yellow(stackName)}`,
}); });
try { try {
@@ -101,7 +101,7 @@ module.exports = {
} }
const testStacks = await getTestStacksInfo(toolbox); const testStacks = await getTestStacksInfo(toolbox);
const options = testStacks.map(item => { const options = testStacks.map((item) => {
return item.name; return item.name;
}); });
@@ -110,7 +110,7 @@ module.exports = {
message: 'Choose a server', message: 'Choose a server',
limit: options.length - 1, limit: options.length - 1,
initial: options.length - 1, initial: options.length - 1,
choices: options choices: options,
}); });
try { try {
@@ -128,7 +128,7 @@ module.exports = {
); );
const output = await system.run(cmd, { const output = await system.run(cmd, {
cwd: `${config.photowall_repo}/cloudformation/`, cwd: `${config.photowall_repo}/cloudformation/`,
trim: true trim: true,
}); });
print.fancy(output); print.fancy(output);
@@ -185,5 +185,5 @@ module.exports = {
} else { } else {
exit(); 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);
}
},
};
+12
View File
@@ -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);
},
};
+2 -3
View File
@@ -1,6 +1,5 @@
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'; import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
import { GluegunCommand } from 'gluegun' import { GluegunCommand } from 'gluegun';
const command: GluegunCommand = { const command: GluegunCommand = {
name: 'pwcli', name: 'pwcli',
@@ -9,7 +8,7 @@ const command: GluegunCommand = {
const { print } = toolbox; const { print } = toolbox;
print.info('Welcome to photowall CLI for everything, almost 😬'); print.info('Welcome to photowall CLI for everything, almost 😬');
await toolbox.menu.showMenu(null); await toolbox.menu.showMenu(null);
} },
}; };
module.exports = command; module.exports = command;
+11 -5
View File
@@ -108,7 +108,8 @@ module.exports = {
if (!config) { if (!config) {
config = { config = {
gh_token: '', gh_token: '',
photowall_repo: '' photowall_repo: '',
mandrill_api_key: '',
}; };
} }
@@ -116,12 +117,17 @@ module.exports = {
message: `A github accesstoken is required with ${chalk.yellow( message: `A github accesstoken is required with ${chalk.yellow(
'Full control of private repositories' 'Full control of private repositories'
)}, please insert the key >`, )}, please insert the key >`,
initial: config.gh_token initial: config.gh_token,
}).run(); }).run();
config.photowall_repo = await new Input({ 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 >`, 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(); }).run();
print.info(` print.info(`
@@ -133,7 +139,7 @@ module.exports = {
await new Confirm({ await new Confirm({
message: `Ok to save the these settings to ${chalk.yellow( message: `Ok to save the these settings to ${chalk.yellow(
`~/.pwcli_settings` `~/.pwcli_settings`
)}?` )}?`,
}).run() }).run()
) { ) {
await system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`); await system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
@@ -145,5 +151,5 @@ module.exports = {
if (toolbox.fromMenu()) if (toolbox.fromMenu())
await toolbox.menu.showMenu(null, defaultMenuSettings); await toolbox.menu.showMenu(null, defaultMenuSettings);
} },
}; };
+1 -1
View File
@@ -11,5 +11,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('setup', defaultMenuSettings); await toolbox.menu.showMenu('setup', defaultMenuSettings);
} },
}; };
@@ -2,7 +2,7 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
import { import {
confirmMessage, confirmMessage,
defaultMenuSettings, defaultMenuSettings,
getSettings getSettings,
} from '../../../../globals'; } from '../../../../globals';
module.exports = { module.exports = {
@@ -50,12 +50,9 @@ module.exports = {
// If there is a match, then prompt user and ask to remove it // If there is a match, then prompt user and ask to remove it
const regex = /\[.*: gone\]/; const regex = /\[.*: gone\]/;
const branchesToDelete = localBranchesArray const branchesToDelete = localBranchesArray
.filter(branch => regex.test(branch)) .filter((branch) => regex.test(branch))
.map(branch => { .map((branch) => {
return strings return strings.trim(branch).replace(' ', '{space}').split('{space}')[0];
.trim(branch)
.replace(' ', '{space}')
.split('{space}')[0];
}); });
if (branchesToDelete.length > 0) { if (branchesToDelete.length > 0) {
@@ -72,5 +69,5 @@ module.exports = {
if (toolbox.fromMenu()) { if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('workflow git', defaultMenuSettings); await toolbox.menu.showMenu('workflow git', defaultMenuSettings);
} }
} },
}; };
+1 -1
View File
@@ -8,5 +8,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('workflow git', defaultMenuSettings); await toolbox.menu.showMenu('workflow git', defaultMenuSettings);
} },
}; };
@@ -6,7 +6,7 @@ import {
confirmMessage, confirmMessage,
defaultMenuSettings, defaultMenuSettings,
getSettings, getSettings,
issueToBranchName issueToBranchName,
} from '../../../globals'; } from '../../../globals';
import { getIssueFromRepo, getOrgIssues } from '../../../services/github_rest'; import { getIssueFromRepo, getOrgIssues } from '../../../services/github_rest';
const { AutoComplete } = require('enquirer'); const { AutoComplete } = require('enquirer');
@@ -27,9 +27,9 @@ module.exports = {
} }
const repos = await getOrgIssues(toolbox, config.gh_token); const repos = await getOrgIssues(toolbox, config.gh_token);
const issueOptions = repos.flatMap(repo => { const issueOptions = repos.flatMap((repo) => {
return repo.issues.map( 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', message: 'Select issue',
limit: 5, limit: 5,
initial: 5, initial: 5,
choices: issueOptions choices: issueOptions,
}); });
const issueResponse = await promptIssues.run(); const issueResponse = await promptIssues.run();
const issueNumber = issueResponse.split('-')[0]; const issueNumber = issueResponse.split('-')[0];
@@ -59,15 +59,15 @@ module.exports = {
) { ) {
await system.run(`git checkout -b ${branchName} origin/master`, { await system.run(`git checkout -b ${branchName} origin/master`, {
cwd: config.photowall_repo, cwd: config.photowall_repo,
trim: true trim: true,
}); });
await system.run(`git push -u origin ${branchName}`, { await system.run(`git push -u origin ${branchName}`, {
cwd: config.photowall_repo, cwd: config.photowall_repo,
trim: true trim: true,
}); });
} }
if (toolbox.fromMenu()) if (toolbox.fromMenu())
await toolbox.menu.showMenu('workflow', defaultMenuSettings); await toolbox.menu.showMenu('workflow', defaultMenuSettings);
} },
}; };
+1 -1
View File
@@ -11,5 +11,5 @@ module.exports = {
hidden: false, hidden: false,
run: async (toolbox: GluegunMenuToolbox) => { run: async (toolbox: GluegunMenuToolbox) => {
await toolbox.menu.showMenu('workflow', defaultMenuSettings); await toolbox.menu.showMenu('workflow', defaultMenuSettings);
} },
}; };
+7 -7
View File
@@ -18,8 +18,8 @@ export const getTestStacksInfo = async (
strings.trim(await system.run(`aws cloudformation list-stacks`)) strings.trim(await system.run(`aws cloudformation list-stacks`))
); );
const allStacks = await Promise.all( const allStacks = (await Promise.all(
stacks.StackSummaries.map(async item => { stacks.StackSummaries.map(async (item) => {
if ( if (
item.StackName.indexOf('photowall-test-') > -1 && item.StackName.indexOf('photowall-test-') > -1 &&
[ [
@@ -29,7 +29,7 @@ export const getTestStacksInfo = async (
'UPDATE_FAILED', 'UPDATE_FAILED',
'CREATE_FAILED', 'CREATE_FAILED',
'CREATE_IN_PROGRESS', 'CREATE_IN_PROGRESS',
'ROLLBACK_COMPLETE' 'ROLLBACK_COMPLETE',
].includes(item.StackStatus) ].includes(item.StackStatus)
) { ) {
try { 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'; return stage.name === 'Source';
}); });
const branch = const branch =
@@ -53,7 +53,7 @@ export const getTestStacksInfo = async (
drift_status: item.DriftInformation.StackDriftStatus, drift_status: item.DriftInformation.StackDriftStatus,
branch: branch, branch: branch,
updated: lastUpdated, updated: lastUpdated,
created: item.CreationTime created: item.CreationTime,
}; };
} catch (e) { } catch (e) {
return { return {
@@ -62,12 +62,12 @@ export const getTestStacksInfo = async (
drift_status: '', drift_status: '',
branch: '', branch: '',
updated: '', updated: '',
created: item.CreationTime created: item.CreationTime,
}; };
} }
} }
return Promise.resolve(null); return Promise.resolve(null);
}) })
) as Stack[] | null; )) as Stack[] | null;
return allStacks.filter(Boolean); return allStacks.filter(Boolean);
}; };
+7 -6
View File
@@ -4,12 +4,13 @@ const snakeCase = require('lodash.snakecase');
const { Confirm } = require('enquirer'); const { Confirm } = require('enquirer');
export const defaultMenuSettings = { export const defaultMenuSettings = {
showHelp: false showHelp: false,
}; };
export type TConfig = { export type TConfig = {
gh_token: string; gh_token: string;
photowall_repo: string; photowall_repo: string;
mandrill_api_key: string;
}; };
export const getSettings = async (toolbox): Promise<TConfig | null> => { export const getSettings = async (toolbox): Promise<TConfig | null> => {
const { filesystem, print } = toolbox; const { filesystem, print } = toolbox;
@@ -40,7 +41,7 @@ export const getCurrentBranch = async (
// git rev-parse --abbrev-ref HEAD // git rev-parse --abbrev-ref HEAD
const branch = await system.run('git rev-parse --abbrev-ref HEAD', { const branch = await system.run('git rev-parse --abbrev-ref HEAD', {
cwd: config.photowall_repo, cwd: config.photowall_repo,
trim: true trim: true,
}); });
console.log(`branch`, branch); console.log(`branch`, branch);
return branch; return branch;
@@ -48,14 +49,14 @@ export const getCurrentBranch = async (
return null; return null;
}; };
export const issueToBranchName = issue => { export const issueToBranchName = (issue) => {
return `${issue.number}-${snakeCase(issue.title).substr(0, 40)}`; return `${issue.number}-${snakeCase(issue.title).substr(0, 40)}`;
}; };
export const confirmMessage = async (message: string) => { export const confirmMessage = async (message: string) => {
const confirm = new Confirm({ const confirm = new Confirm({
name: 'confirm', name: 'confirm',
message: message message: message,
}); });
try { try {
@@ -66,6 +67,6 @@ export const confirmMessage = async (message: string) => {
} }
}; };
export const sleep = milliseconds => { export const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds)); return new Promise((resolve) => setTimeout(resolve, milliseconds));
}; };
+8 -8
View File
@@ -6,7 +6,7 @@ export const getOrgRepos = async (toolbox, token, org) => {
try { try {
const response = await octokit.request('GET /orgs/{org}/repos', { const response = await octokit.request('GET /orgs/{org}/repos', {
org: org, org: org,
per_page: 100 per_page: 100,
}); });
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
@@ -23,7 +23,7 @@ export const getRepo = async (toolbox, token, owner, repo) => {
try { try {
const response = await octokit.request('GET /repos/{owner}/{repo}', { const response = await octokit.request('GET /repos/{owner}/{repo}', {
owner: owner, owner: owner,
repo: repo repo: repo,
}); });
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
@@ -45,7 +45,7 @@ export const getRepoBranches = async (toolbox, token, owner, repo) => {
owner: owner, owner: owner,
repo: repo, repo: repo,
page: page, page: page,
per_page: 100 per_page: 100,
} }
); );
return response; return response;
@@ -70,9 +70,9 @@ export const getRepoBranches = async (toolbox, token, owner, repo) => {
export const getOrgIssues = async (toolbox, token) => { export const getOrgIssues = async (toolbox, token) => {
// const { print } = toolbox; // const { print } = toolbox;
const repos = await getOrgRepos(toolbox, token, 'Photowall'); 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( const allIssues = await Promise.all(
repoNames.map(async repoName => { repoNames.map(async (repoName) => {
const issues = await getOpenIssuesFromRepo(toolbox, token, repoName); const issues = await getOpenIssuesFromRepo(toolbox, token, repoName);
// console.log(`${repoName} - issues`, issues.length); // console.log(`${repoName} - issues`, issues.length);
// return issues.map(item => `${item.number}-${item.title.substring(0, 10)}`); // 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', { const response = await octokit.request('GET /repos/{owner}/{repo}/issues', {
owner: 'Photowall', owner: 'Photowall',
repo: repo, repo: repo,
per_page: 100 per_page: 100,
}); });
if (response.status === 200) { if (response.status === 200) {
return response.data; return response.data;
@@ -109,7 +109,7 @@ export const getIssueFromRepo = async (toolbox, token, repo, issueNumber) => {
{ {
owner: 'Photowall', owner: 'Photowall',
repo: repo, repo: repo,
issue_number: issueNumber issue_number: issueNumber,
} }
); );
if (response.status === 200) { if (response.status === 200) {
@@ -134,7 +134,7 @@ export const createPullRequest = async (
owner: 'Photowall', owner: 'Photowall',
repo: repo, repo: repo,
head: branch, head: branch,
base: 'master' base: 'master',
}); });
console.log(`response`, response); console.log(`response`, response);
// if (response.status === 200) { // if (response.status === 200) {
+40 -5
View File
@@ -408,6 +408,13 @@
resolved "https://registry.npmjs.org/@lenne.tech/gluegun-menu/-/gluegun-menu-0.0.5.tgz" resolved "https://registry.npmjs.org/@lenne.tech/gluegun-menu/-/gluegun-menu-0.0.5.tgz"
integrity sha512-J/Tx4cFMn1nungGi7n3tJ2cvt0LJUeNuLAsDS9TbXtUomdz0/2kMZJq/m2HaUxWWeyIYSu4TSWGLIV8SQrgwTA== 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": "@nodelib/fs.scandir@2.1.5":
version "2.1.5" version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
@@ -892,6 +899,15 @@ axios@^0.21.4:
dependencies: dependencies:
follow-redirects "^1.14.0" 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: babel-jest@^24.9.0:
version "24.9.0" version "24.9.0"
resolved "https://registry.npmjs.org/babel-jest/-/babel-jest-24.9.0.tgz" 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" resolved "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== 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" version "1.0.8"
resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz" resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== 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" resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz"
integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ== 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: for-each@^0.3.3:
version "0.3.3" version "0.3.3"
resolved "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz" 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" resolved "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz"
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= 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: form-data@~2.3.2:
version "2.3.3" version "2.3.3"
resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz" resolved "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz"
@@ -3813,10 +3843,10 @@ prettier-linter-helpers@^1.0.0:
dependencies: dependencies:
fast-diff "^1.1.2" fast-diff "^1.1.2"
prettier@^1.12.1: prettier@^2.0.0:
version "1.19.1" version "2.8.8"
resolved "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
pretty-format@^24.9.0: pretty-format@^24.9.0:
version "24.9.0" version "24.9.0"
@@ -3836,6 +3866,11 @@ prompts@^2.0.1:
kleur "^3.0.3" kleur "^3.0.3"
sisteransi "^1.0.5" 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: psl@^1.1.28:
version "1.8.0" version "1.8.0"
resolved "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz" resolved "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz"