diff --git a/src/commands/workflow/git/clean_old_branches/clean_old_branches.ts b/src/commands/workflow/git/clean_old_branches/clean_old_branches.ts new file mode 100644 index 0000000..6df92dd --- /dev/null +++ b/src/commands/workflow/git/clean_old_branches/clean_old_branches.ts @@ -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); + } + } +}; diff --git a/src/commands/workflow/git/git.ts b/src/commands/workflow/git/git.ts new file mode 100644 index 0000000..f3e2c27 --- /dev/null +++ b/src/commands/workflow/git/git.ts @@ -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); + } +}; diff --git a/src/commands/workflow/setupissue/setupissue.ts b/src/commands/workflow/setupissue/setupissue.ts index e5ec93a..8f9692d 100644 --- a/src/commands/workflow/setupissue/setupissue.ts +++ b/src/commands/workflow/setupissue/setupissue.ts @@ -12,7 +12,7 @@ import { getIssueFromRepo, getOrgIssues } from '../../../services/github_rest'; const { AutoComplete } = require('enquirer'); module.exports = { - name: 'SetupIssue', + name: 'setupissue', alias: ['si'], description: 'Setup everything for a issue (si)', hidden: false,