added setup issue
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
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 { 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'],
|
||||
description: 'Setup everything for a issue (si)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
|
||||
const {print, system, strings} = toolbox;
|
||||
|
||||
// Load settings
|
||||
const config = await getSettings(toolbox);
|
||||
if (!config) {
|
||||
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||
return;
|
||||
}
|
||||
|
||||
const repos = await getOrgIssues(toolbox, config.gh_token);
|
||||
const issueOptions = repos.flatMap(repo => {
|
||||
return repo.issues.map(issue => `${issue.number}-${repo.repo}-${issue.title}`);
|
||||
})
|
||||
|
||||
const promptIssues = new AutoComplete({
|
||||
name: 'issues',
|
||||
message: 'Select issue',
|
||||
limit: 5,
|
||||
initial: 5,
|
||||
choices: issueOptions
|
||||
});
|
||||
const issue_response = await promptIssues.run();
|
||||
const issue_number = issue_response.split('-')[0];
|
||||
const repo = issue_response.split('-')[1];
|
||||
|
||||
const issueData = await getIssueFromRepo(toolbox, config.gh_token, repo, issue_number);
|
||||
const branchName = issueToBranchName(issueData);
|
||||
|
||||
if (await confirmMessage(`Create new branch ${chalk.yellow(branchName)} from origin/master?`)) {
|
||||
await system.run(`git checkout -b ${branchName} origin/master`, {cwd: config.photowall_repo, trim: true});
|
||||
await system.run(`git push -u origin ${branchName}`, {cwd: config.photowall_repo, trim: true});
|
||||
}
|
||||
|
||||
if (toolbox.fromMenu()) await toolbox.menu.showMenu('workflow', defaultMenuSettings);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import { defaultMenuSettings } from '../../globals';
|
||||
|
||||
/**
|
||||
* Section1 menu
|
||||
*/
|
||||
module.exports = {
|
||||
name: 'workflow',
|
||||
alias: ['wf'],
|
||||
description: 'Workflow tools (wf)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
await toolbox.menu.showMenu('workflow', defaultMenuSettings);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user