new branch select on create server
This commit is contained in:
@@ -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`))
|
||||
|
||||
Reference in New Issue
Block a user