From 8c5fadb99f4c7eda72ce9873f358ec2e659758b9 Mon Sep 17 00:00:00 2001 From: Ji Sang Seo Date: Sun, 11 Feb 2024 15:50:26 +0900 Subject: [PATCH] update: edge case for finish --- cli/oh-my-task-finish.mjs | 19 ++++++++++++++++++ cli/oh-my-task.mjs | 4 ++++ package.json | 4 +++- src/task/Task.mjs | 21 +++++++++++++++++--- src/task/finish.mjs | 42 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 cli/oh-my-task-finish.mjs create mode 100644 src/task/finish.mjs diff --git a/cli/oh-my-task-finish.mjs b/cli/oh-my-task-finish.mjs new file mode 100644 index 0000000..558de10 --- /dev/null +++ b/cli/oh-my-task-finish.mjs @@ -0,0 +1,19 @@ +#!/usr/bin/env node + +import { Command } from "commander"; +import { finish } from "../src/task/finish.mjs"; + +async function finishCommand() { + const program = new Command(); + program + .name("oh-my-task-end") + .description( + "Finish Task and checkout to base branch. This command is use to end Task life cycle" + ); + + program.parse(); + + await finish(); +} + +await finishCommand().catch((error) => console.error(error)); diff --git a/cli/oh-my-task.mjs b/cli/oh-my-task.mjs index 36a3d60..8ef2c6b 100644 --- a/cli/oh-my-task.mjs +++ b/cli/oh-my-task.mjs @@ -25,6 +25,10 @@ program.command( "pr", "Request Pull Request from current branch to Base branch" ); +program.command( + "finish", + "Finish Task and checkout to base branch. This command is use to end Task life cycle" +); // parsings program.showHelpAfterError(); diff --git a/package.json b/package.json index ff55d74..5509253 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "oh-my-task", "version": "0.0.0", - "description": "OH-MY-TASK is mainly focused to help indie developers to manage their projects neatly", + "description": "OH-MY-TASK is mainly focusing helping indie developers to manage their projects neatly", "main": "cli/workflow.mjs", "bin": { "oh-my-task": "cli/oh-my-task.mjs", @@ -11,6 +11,7 @@ "oh-my-task-list": "cli/oh-my-task-list.mjs", "oh-my-task-select": "cli/oh-my-task-select.mjs", "oh-my-task-pr": "cli/oh-my-task-pr.mjs", + "oh-my-task-finish": "cli/oh-my-task-finish.mjs", "omt-git": "cli/oh-my-task-git.mjs" }, "scripts": { @@ -22,6 +23,7 @@ "omt-list": "node ./cli/oh-my-task-list.mjs", "omt-select": "node ./cli/oh-my-task-select.mjs", "omt-pr": "node ./cli/oh-my-task-pr.mjs", + "omt-finish": "node ./cli/oh-my-task-finish.mjs", "omt-git": "node ./cli/oh-my-task-git.mjs" }, "keywords": [], diff --git a/src/task/Task.mjs b/src/task/Task.mjs index 5606c90..8015595 100644 --- a/src/task/Task.mjs +++ b/src/task/Task.mjs @@ -34,13 +34,28 @@ export class Task { return (this.#status = state); } - select(state) { + finish() { const previousStateText = TASK_STATUS_TEXT[this.getProgress()]; - const currentStateText = TASK_STATUS_TEXT[state]; + const currentStateText = TASK_STATUS_TEXT[TASK_STATUS.COMPLETE]; + + this.setProgress(TASK_STATUS.WORKING); + + console.log( + `Task ${chalk.blueBright( + this.key + )} progress changed complete (${chalk.gray( + previousStateText + )} -> ${chalk.green(currentStateText)})` + ); + } + + select() { + const previousStateText = TASK_STATUS_TEXT[this.getProgress()]; + const currentStateText = TASK_STATUS_TEXT[TASK_STATUS.WORKING]; console.log(`Switching to Task ${chalk.blueBright(this.key)}..`); - this.setProgress(state); + this.setProgress(TASK_STATUS.WORKING); console.log( `Task ${chalk.blueBright( diff --git a/src/task/finish.mjs b/src/task/finish.mjs new file mode 100644 index 0000000..b773bde --- /dev/null +++ b/src/task/finish.mjs @@ -0,0 +1,42 @@ +import * as context from "../context.mjs"; +import * as git from "../git.mjs"; +import { TASK_STATUS, TASK_STATUS_TEXT } from "../status.mjs"; +import { Task } from "../task/Task.mjs"; + +export async function finish() { + let taskCollection = await context.manifest.getHistory(); + + const currentBranchName = git.getCurrentBranchName(); + + let task = Object.values(taskCollection).find( + (task) => git.toBranchName(task.title) === currentBranchName + ); + + task = Task.build(task); + // set status to complete + task.finish(); + await context.manifest.setHistory(task.key, task.objectify()); + + // git actions start + + //get branch which to checkout + const seperatorIdx = task.baseBranch.indexOf("/"); + const localBaseBranch = task.baseBranch.slice(seperatorIdx + 1); + + const baseTask = Object.values(taskCollection).find( + (task) => localBaseBranch === git.toBranchName(task.title) + ); + + if (baseTask) { + } else { + // probably, base task is original branch made by git or something which user manually created. + // just set task status -> complete and let user to select which branch to move on. + const branchToCheckout = await git.selectBranch( + "Select Branch to checkout:", + false + ); + await git.checkout(branchToCheckout); + return; + } + let baseBranch = task.baseBranch; +}