Skip to content

Commit

Permalink
update: edge case for finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Ji Sang Seo committed Feb 11, 2024
1 parent c221bc3 commit 8c5fadb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
19 changes: 19 additions & 0 deletions cli/oh-my-task-finish.mjs
Original file line number Diff line number Diff line change
@@ -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));
4 changes: 4 additions & 0 deletions cli/oh-my-task.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand All @@ -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": [],
Expand Down
21 changes: 18 additions & 3 deletions src/task/Task.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
42 changes: 42 additions & 0 deletions src/task/finish.mjs
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 8c5fadb

Please sign in to comment.