added clean old branches command (#19)
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||||
|
import {
|
||||||
|
confirmMessage,
|
||||||
|
defaultMenuSettings,
|
||||||
|
getSettings
|
||||||
|
} from '../../../../globals';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'clean_old_branches',
|
||||||
|
alias: ['cb'],
|
||||||
|
description: 'Prune remote and clean local branches if gone (cb)',
|
||||||
|
hidden: false,
|
||||||
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
|
const { filesystem, print, system, strings } = toolbox;
|
||||||
|
|
||||||
|
// Load settings
|
||||||
|
const config = await getSettings(toolbox);
|
||||||
|
if (!config || !config.photowall_repo || config.photowall_repo === '') {
|
||||||
|
print.error(`
|
||||||
|
|
||||||
|
The Clean command requires that you set an absolute path to your local photowall repository.
|
||||||
|
|
||||||
|
`);
|
||||||
|
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if current path is the photowall repo
|
||||||
|
const currentPath = strings.trim(await system.run('pwd'));
|
||||||
|
// Check if the current path is a git repo by looking for the .git folder
|
||||||
|
const isGitRepo = await filesystem.existsAsync(`${currentPath}/.git`);
|
||||||
|
if (!isGitRepo) {
|
||||||
|
print.error(`
|
||||||
|
The Clean command requires that you are in a git repository.
|
||||||
|
`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (await confirmMessage(`Prune remote in this repo?`)) {
|
||||||
|
const pruneRemote = await system.run(`git remote prune origin`);
|
||||||
|
print.fancy(pruneRemote);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all local branches
|
||||||
|
const localBranches = await system.run(`git branch -vv`);
|
||||||
|
// Split on new line
|
||||||
|
const localBranchesArray = localBranches.split('\n');
|
||||||
|
|
||||||
|
// For each line check if there is a :gone inside the first brackets like [something :gone] with regex
|
||||||
|
// If there is a match, then prompt user and ask to remove it
|
||||||
|
const regex = /\[.*: gone\]/;
|
||||||
|
const branchesToDelete = localBranchesArray
|
||||||
|
.filter(branch => regex.test(branch))
|
||||||
|
.map(branch => {
|
||||||
|
return strings
|
||||||
|
.trim(branch)
|
||||||
|
.replace(' ', '{space}')
|
||||||
|
.split('{space}')[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
if (branchesToDelete.length > 0) {
|
||||||
|
for (const branch of branchesToDelete) {
|
||||||
|
if (await confirmMessage(`Delete ${branch}?`)) {
|
||||||
|
const deleteBranch = await system.run(`git branch -D ${branch}`);
|
||||||
|
print.fancy(deleteBranch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print.info(`No branches to delete`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toolbox.fromMenu()) {
|
||||||
|
await toolbox.menu.showMenu('workflow git', defaultMenuSettings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||||
|
import { defaultMenuSettings } from '../../../globals';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'git',
|
||||||
|
alias: ['g'],
|
||||||
|
description: 'Tools for git to make repo life easier (g)',
|
||||||
|
hidden: false,
|
||||||
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
|
await toolbox.menu.showMenu('workflow git', defaultMenuSettings);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -12,7 +12,7 @@ import { getIssueFromRepo, getOrgIssues } from '../../../services/github_rest';
|
|||||||
const { AutoComplete } = require('enquirer');
|
const { AutoComplete } = require('enquirer');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'SetupIssue',
|
name: 'setupissue',
|
||||||
alias: ['si'],
|
alias: ['si'],
|
||||||
description: 'Setup everything for a issue (si)',
|
description: 'Setup everything for a issue (si)',
|
||||||
hidden: false,
|
hidden: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user