new branch select on create server
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu'
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const { Input, Confirm } = require('enquirer');
|
const { AutoComplete, Input, Confirm } = require('enquirer');
|
||||||
import { Octokit } from "@octokit/core";
|
import { Octokit } from "@octokit/core";
|
||||||
import { GluegunPrint } from 'gluegun';
|
import { GluegunPrint } from 'gluegun';
|
||||||
import { defaultMenuSettings, getSettings } from '../../../../globals';
|
import { defaultMenuSettings, getSettings } from '../../../../globals';
|
||||||
|
import { getRepoBranches } from '../../../../services/github_rest';
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
|
|
||||||
const STACK_DEFAULTS = {
|
const STACK_DEFAULTS = {
|
||||||
@@ -69,32 +70,6 @@ const getCreateStackCommand = (stackName: string, branch: string, templateFile:
|
|||||||
return cmd.join(' ');
|
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 getConfirmation = async (branchName: string, stackName: string) => {
|
||||||
const url = stackName.replace('photowall-', '');
|
const url = stackName.replace('photowall-', '');
|
||||||
const confirm = new Confirm({
|
const confirm = new Confirm({
|
||||||
@@ -125,10 +100,17 @@ module.exports = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let branchName = null;
|
const branches = await getRepoBranches(toolbox, config.gh_token, 'Photowall', 'photowall');
|
||||||
while (!branchName) {
|
const branchOptions = branches.map(item => item.name);
|
||||||
branchName = await getBranchName(print, config.gh_token);
|
|
||||||
}
|
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(
|
const stacks = JSON.parse(
|
||||||
strings.trim(await system.run(`aws cloudformation list-stacks`))
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,24 +2,10 @@ import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
|||||||
import { Octokit } from '@octokit/core';
|
import { Octokit } from '@octokit/core';
|
||||||
import chalk = require('chalk');
|
import chalk = require('chalk');
|
||||||
import { system } from 'gluegun';
|
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';
|
import { createPullRequest, getIssueFromRepo, getOpenIssuesFromRepo, getOrgIssues, getOrgRepos } from '../../../services/github_rest';
|
||||||
const { AutoComplete, Confirm, Input } = require('enquirer');
|
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 = {
|
module.exports = {
|
||||||
name: 'SetupIssue',
|
name: 'SetupIssue',
|
||||||
alias: ['si'],
|
alias: ['si'],
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import chalk = require("chalk");
|
import chalk = require("chalk");
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
var snakeCase = require('lodash.snakecase');
|
var snakeCase = require('lodash.snakecase');
|
||||||
|
const { AutoComplete, Confirm, Input } = require('enquirer');
|
||||||
|
|
||||||
export const defaultMenuSettings = {
|
export const defaultMenuSettings = {
|
||||||
showHelp: false
|
showHelp: false
|
||||||
@@ -39,3 +40,17 @@ export const getCurrentBranch = async (path: string, toolbox): Promise<string |
|
|||||||
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) => {
|
||||||
|
const confirm = new Confirm({
|
||||||
|
name: 'confirm',
|
||||||
|
message: message
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await confirm.run();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -17,6 +17,53 @@ export const getOrgRepos = async (toolbox, token, org) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getRepo = async (toolbox, token, owner, repo) => {
|
||||||
|
const { print } = toolbox;
|
||||||
|
const octokit = new Octokit({ auth: token });
|
||||||
|
try {
|
||||||
|
const response = await octokit.request("GET /repos/{owner}/{repo}", {
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
});
|
||||||
|
if (response.status === 200) {
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print.error('Not a valid organisation for your token access');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getRepoBranches = async (toolbox, token, owner, repo) => {
|
||||||
|
const { print } = toolbox;
|
||||||
|
const octokit = new Octokit({ auth: token });
|
||||||
|
|
||||||
|
const getBranches = async (toolbox, token, owner, repo, page) => {
|
||||||
|
const response = await octokit.request("GET /repos/{owner}/{repo}/branches", {
|
||||||
|
owner: owner,
|
||||||
|
repo: repo,
|
||||||
|
page: page,
|
||||||
|
per_page: 100,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
let allBranches = [];
|
||||||
|
let response = null;
|
||||||
|
let page = 0;
|
||||||
|
while (true) {
|
||||||
|
response = await getBranches(toolbox, token, owner, repo, page);
|
||||||
|
if (response.data.length > 0) {
|
||||||
|
allBranches = [...allBranches, ...response.data];
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
page += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return allBranches;
|
||||||
|
}
|
||||||
|
|
||||||
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');
|
||||||
|
|||||||
Reference in New Issue
Block a user