no clean? no done!

This commit is contained in:
Yanick Champoux 2021-11-25 14:01:49 -05:00
parent bba261c7c2
commit 4c1c4989b5
4 changed files with 185 additions and 188 deletions

View File

@ -3,7 +3,7 @@ const u = require("updeep");
const _ = require("lodash");
const fp = require("lodash/fp");
const log = require('./log');
const log = require("./log");
const normalizeArray = (value) =>
Array.isArray(value) ? value : [value].filter((x) => x);
@ -16,12 +16,14 @@ const initBranch = (config = {}) => ({
const git = Git();
const currentBranch = _.once(() =>git
.raw("branch", "--show-current")
.then((r) => r.replace("\n", "")));
const currentBranch = _.once(() =>
git.raw("branch", "--show-current").then((r) => r.replace("\n", ""))
);
const isClean = () => git.status().then(({ files }) => !files.length);
const branches = _.once(async () => {
const config = await git.listConfig("local").then(fp.get('all'));
const config = await git.listConfig("local").then(fp.get("all"));
let tree = Object.entries(config).reduce(
(accum, [key, value]) => u.updateIn(key, value, accum),
@ -58,9 +60,12 @@ const branches = _.once(async () => {
// include the merged info
for (const branch of Object.values(branches)) {
branch.contains = _.compact(await git.raw( 'branch', '--merged', branch.name )
.then( r => r.replace( /[ *]/g, '' ) )
.then( r => r.split("\n") ))
branch.contains = _.compact(
await git
.raw("branch", "--merged", branch.name)
.then((r) => r.replace(/[ *]/g, ""))
.then((r) => r.split("\n"))
);
}
const current = await currentBranch();
@ -73,43 +78,41 @@ const branches = _.once(async () => {
async function canBeDeleted() {
const allBranches = await branches();
return Object.values(allBranches).filter(
fp.get('done')
).filter( ({name,upstream})=>
upstream.every( u => allBranches[u].contains.includes(name) )
).map(fp.get('name'));
return Object.values(allBranches)
.filter(fp.get("done"))
.filter(({ name, upstream }) =>
upstream.every((u) => allBranches[u].contains.includes(name))
)
.map(fp.get("name"));
}
async function canBeWorkedOn() {
const allBranches = await branches();
return Object.values(allBranches).filter(
({done}) => !done
).filter( ({name,dependencies})=>
dependencies.every( u => allBranches[u].done )
).map(fp.get('name'));
return Object.values(allBranches)
.filter(({ done }) => !done)
.filter(({ name, dependencies }) =>
dependencies.every((u) => allBranches[u].done)
)
.map(fp.get("name"));
}
async function needsRebasing() {
const allBranches = await branches();
return Object.values(allBranches).filter(
fp.get('base')
).filter( ({base,name})=>
!allBranches[name].contains.includes(base)
).map(fp.get('name'));
return Object.values(allBranches)
.filter(fp.get("base"))
.filter(({ base, name }) => !allBranches[name].contains.includes(base))
.map(fp.get("name"));
}
async function needsMerging() {
const allBranches = await branches();
return Object.values(allBranches).filter(
fp.get('done')
).flatMap( ({upstream,name})=> upstream.map( u => [ name, u ] ) )
.filter( ([name,up]) => !allBranches[up].contains.includes(name) )
return Object.values(allBranches)
.filter(fp.get("done"))
.flatMap(({ upstream, name }) => upstream.map((u) => [name, u]))
.filter(([name, up]) => !allBranches[up].contains.includes(name));
}
module.exports = {
@ -119,4 +122,5 @@ module.exports = {
canBeWorkedOn,
needsRebasing,
needsMerging,
isClean,
};

View File

@ -1,15 +1,20 @@
const Git = require('simple-git');
const inquirer = require('inquirer');
const report = require('yurnalist');
const _ = require('lodash');
const { currentBranch } = require( '../utils');
const Git = require("simple-git");
const inquirer = require("inquirer");
const report = require("yurnalist");
const _ = require("lodash");
const myGit = require("../branches");
const log = require("../log");
module.exports = async (yargs) => {
if (!(await myGit.isClean())) {
log.error("workspace not clean, aborting");
return;
}
const current = await currentBranch();
const current = await myGit.currentBranch();
console.log(`marking branch '${current}' as done`);
log.success(`W00t! marking branch '${current}' as done`);
await Git().addConfig( `branch.${current}.mikado-done`, true );
}
await Git().addConfig(`branch.${current}.mikado-done`, true);
};

View File

@ -7,36 +7,33 @@ const u = require("updeep");
const columnify = require("columnify");
const chalk = require("chalk");
const myGit = require('../branches');
const log = require('../log');
const myGit = require("../branches");
const log = require("../log");
const iconFor = ( branch, branches ) => {
if(branch.done ) return "✅";
const iconFor = (branch, branches) => {
if (branch.done) return "✅";
for( const dep of branch.dependencies ) {
if( !branches[dep].done ) return "⛔";
for (const dep of branch.dependencies) {
if (!branches[dep].done) return "⛔";
}
return "🙋";
};
}
const decorateCurrent = async branch => {
if( branch !== await myGit.currentBranch() ) return branch;
const decorateCurrent = async (branch) => {
if (branch !== (await myGit.currentBranch())) return branch;
return chalk.underline.bold(branch);
}
};
async function printNeedsRebasing() {
const needsRebasing = await myGit.needsRebasing();
if( !needsRebasing.length ) return false;
if (!needsRebasing.length) return false;
log.subtitle(':arrow_heading_up: needs rebasing');
const b = await Promise.all(
needsRebasing.map( decorateCurrent )
);
log.info( "\t", b.join(', ') );
log.subtitle(":arrow_heading_up: needs rebasing");
const b = await Promise.all(needsRebasing.map(decorateCurrent));
log.info("\t", b.join(", "));
return true;
}
@ -44,51 +41,46 @@ async function printNeedsRebasing() {
async function printNeedsMerging() {
const needsMerging = await myGit.needsMerging();
if(!needsMerging.length) return false;
if (!needsMerging.length) return false;
log.subtitle(':thumbsup: ready to be merged');
log.info( "\t", needsMerging.map( x => x.join('->') ).join(', ') );
log.subtitle(":thumbsup: ready to be merged");
log.info("\t", needsMerging.map((x) => x.join("->")).join(", "));
return true;
}
async function printActionables() {
log.title(":point_right: What's next?");
let something = false;
const accumSomething = (value) => something ||= value;
const accumSomething = (value) => (something ||= value);
accumSomething( await printNeedsRebasing() );
accumSomething(await printNeedsMerging());
accumSomething( await printNeedsMerging() );
accumSomething(await printNeedsRebasing());
const canBeDeleted = await myGit.canBeDeleted();
if( canBeDeleted.length ) {
if (canBeDeleted.length) {
something = true;
log.subtitle(':recycle: branches that can be deleted');
log.info( "\t", canBeDeleted.join(', ') );
log.subtitle(":recycle: branches that can be deleted");
log.info("\t", canBeDeleted.join(", "));
}
const canBeWorkedOn = await myGit.canBeWorkedOn();
if( canBeWorkedOn.length ) {
if (canBeWorkedOn.length) {
something = true;
log.subtitle(':hammer: ready to be worked on');
const b = await Promise.all(
canBeWorkedOn.map( decorateCurrent )
);
log.info( "\t", b.join(', ') );
log.subtitle(":hammer: ready to be worked on");
const b = await Promise.all(canBeWorkedOn.map(decorateCurrent));
log.info("\t", b.join(", "));
}
if(!something) {
if (!something) {
log.info("nothing? :shrug:");
}
}
module.exports = async () => {
@ -98,9 +90,7 @@ module.exports = async () => {
let color = branches[dep].done ? chalk.green : chalk.red;
let contains = await Git().raw("branch", "--contains", dep);
contains = contains
.split("\n")
.map((x) => x.trim().replace("* ", ""));
contains = contains.split("\n").map((x) => x.trim().replace("* ", ""));
if (contains.includes(current)) color = color.underline;
@ -111,9 +101,7 @@ module.exports = async () => {
let color = branches[up].done ? chalk.green : chalk.red;
let contains = await Git().raw("branch", "--contains", current);
contains = contains
.split("\n")
.map((x) => x.trim().replace("* ", ""));
contains = contains.split("\n").map((x) => x.trim().replace("* ", ""));
if (contains.includes(up)) color = color.underline;
@ -126,9 +114,9 @@ module.exports = async () => {
for (const branch of sorted) {
console.log(
iconFor(branch,branches),
iconFor(branch, branches),
chalk.blue(branch.name),
branch.current ? "👷" : ' '
branch.current ? "👷" : " "
);
console.log(`\tbase: ${chalk.magenta(branch.base ?? "<none>")}`);
@ -145,9 +133,7 @@ module.exports = async () => {
);
console.log("\tdependencies:", deps.join(" "));
}
}
await printActionables();
};

View File

@ -1,12 +1,14 @@
const emoji = require('node-emoji');
const emoji = require("node-emoji");
const chalk = require("chalk");
function groomLog(...entries) {
console.log( ...(entries.map(emoji.emojify)) );
console.log(...entries.map(emoji.emojify));
}
module.exports = {
info: groomLog,
title: title => groomLog("\n",chalk.blue.bold(title)),
subtitle: title => groomLog("\n",chalk.blue(title)),
}
title: (title) => groomLog("\n", chalk.blue.bold(title)),
subtitle: (title) => groomLog("\n", chalk.blue(title)),
error: (message) => groomLog(":skull:", chalk.red(message)),
success: (message) => groomLog(":sparkles:", chalk.green(message)),
};