new branch select on create server

This commit is contained in:
Arwid Thornström
2022-02-04 14:28:10 +01:00
parent 1c80394e96
commit 1c8955bacb
5 changed files with 128 additions and 46 deletions
@@ -1,9 +1,10 @@
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
const chalk = require('chalk');
const { Input, Confirm } = require('enquirer');
const { AutoComplete, Input, Confirm } = require('enquirer');
import { Octokit } from "@octokit/core";
import { GluegunPrint } from 'gluegun';
import { defaultMenuSettings, getSettings } from '../../../../globals';
import { getRepoBranches } from '../../../../services/github_rest';
const os = require("os");
const STACK_DEFAULTS = {
@@ -69,32 +70,6 @@ const getCreateStackCommand = (stackName: string, branch: string, templateFile:
return cmd.join(' ');
};
const getBranchName = async (print: GluegunPrint, token: string) => {
const input = new Input({
type: 'input',
name: 'branch',
message: 'What github branch should be deployed?'
});
const responseBranch = await input.run();
// First ask what branch should be deployed
const octokit = new Octokit({ auth: token });
try {
const response = await octokit.request("GET /repos/{owner}/{repo}/branches/{branch}", {
owner: "photowall",
repo: "photowall",
branch: responseBranch
});
if (response.status === 200) {
return responseBranch;
}
} catch (e) {
print.error('Not a valid branch on photowall repo');
return null;
}
};
const getConfirmation = async (branchName: string, stackName: string) => {
const url = stackName.replace('photowall-', '');
const confirm = new Confirm({
@@ -125,10 +100,17 @@ module.exports = {
return;
}
let branchName = null;
while (!branchName) {
branchName = await getBranchName(print, config.gh_token);
}
const branches = await getRepoBranches(toolbox, config.gh_token, 'Photowall', 'photowall');
const branchOptions = branches.map(item => item.name);
const promptBranch = new AutoComplete({
name: 'branchName',
message: 'Select a branch',
limit: 10,
initial: 10,
choices: branchOptions
});
const branchName = await promptBranch.run();
const stacks = JSON.parse(
strings.trim(await system.run(`aws cloudformation list-stacks`))
@@ -0,0 +1,52 @@
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
import chalk = require('chalk');
import { confirmMessage, defaultMenuSettings } from '../../../../globals';
const { AutoComplete } = require('enquirer');
const { spawn } = require('child_process');
module.exports = {
name: 'logs',
alias: ['l'],
description: 'Tail a log in cloudwatch (l)',
hidden: false,
run: async (toolbox: GluegunMenuToolbox) => {
const { system, strings } = toolbox
// aws logs tail /aws/codebuild/photowall-test-arwid-1 --follow
// aws logs describe-log-groups --log-group-name-prefix codepipeline
// const groups = JSON.parse(strings.trim(await system.run(`aws logs describe-log-groups`)));
// const options = groups.logGroups.map(item => {
// return item.logGroupName;
// });
// const prompt = new AutoComplete({
// name: 'logGroups',
// message: 'Choose a logGroup',
// limit: 30,
// initial: options.length - 1,
// choices: options
// });
// const logGroup = await prompt.run();
const logGroup = 'top';
if (await confirmMessage(`Tail logs from ${chalk.yellow(logGroup)}?`)) {
// system.run(`aws logs tail ${logGroup} --follow`);
// const child = spawn(`aws logs tail ${logGroup} --follow`);
const child = spawn(`top`);
child.stdout.setEncoding('utf8');
child.stdout.on('data', function(data) {
//Here is where the output goes
console.clear();
console.log(data);
});
}
if (toolbox.fromMenu()) {
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
}
}
}
+1 -15
View File
@@ -2,24 +2,10 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
import { Octokit } from '@octokit/core';
import chalk = require('chalk');
import { system } from 'gluegun';
import { defaultMenuSettings, getSettings, issueToBranchName } from '../../../globals';
import { confirmMessage, defaultMenuSettings, getSettings, issueToBranchName } from '../../../globals';
import { createPullRequest, getIssueFromRepo, getOpenIssuesFromRepo, getOrgIssues, getOrgRepos } from '../../../services/github_rest';
const { AutoComplete, Confirm, Input } = require('enquirer');
const confirmMessage = async (message: string) => {
const confirm = new Confirm({
name: 'confirm',
message: message
});
try {
return await confirm.run();
} catch (e) {
console.error(e);
return false;
}
};
module.exports = {
name: 'SetupIssue',
alias: ['si'],