Skip to content

Commit

Permalink
Feat add support trello (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroki0525 authored Jan 14, 2024
1 parent 2e7b861 commit 2712a7f
Show file tree
Hide file tree
Showing 18 changed files with 587 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/swift-bugs-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@dandori/cli": patch
"@dandori/ui": patch
---

Add trello
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ Today's My Tasks

<img src="./media/notion_example.png" alt="notion output example" width="426">

## Example 3

### Input

```text
Today's My Tasks
* [todo] Send Email to John
* [doing] Write a blog
* [done] Report to Boss
```

### Output(Trello)

<img src="./media/trello_example.png" alt="notion output example" width="426">

## Usage

This project is monorepo. You can choose the following ways to use it.
Expand Down
Binary file added media/trello_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,31 @@ Options:
```bash
pnpm --package=@dandori/cli dlx dandori-miro your_tasks.txt -d your_database_id -o status --status 'Status' --status-todo 'ToDo' --status-doing 'Doing' --status-done 'Done 🙌'
```
### dandori-trello
This command is to execute `generateDandoriTrelloCards` of `@dandori/ui`.
```bash
% pnpm --package=@dandori/cli dlx dandori-trello -h

Usage: @dandori/cli <input-file> [options]

Options:
-V, --version output the version number
-e, --env-file <env-file> env file path
-m, --model <model> Chat GPT model which supports function_calling
-o, --optional-task-props <optional-task-props> optional output task props which delimiter is a comma
-b, --board-id <board-id> trello board id
--status-todo <status-todo> trello list status todo name
--status-doing <status-doing> trello list status doing name
--status-done <status-done> trello list status done name
-h, --help display help for command
```
#### Example of the command
```bash
pnpm --package=@dandori/cli dlx dandori-trello your_tasks.txt -d your_board_id -o status --status-todo 'Todo' --status-doing 'Doing' --status-done 'Done'
```
8 changes: 5 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
"build": "tsup --config ../../tsup.config.ts",
"test": "vitest run",
"dev:core": "tsx src/core/cli.ts",
"dev:miro": "tsx src/miro/cli.ts ./tmp/tmp.txt",
"dev:notion": "tsx src/notion/cli.ts"
"dev:miro": "tsx src/miro/cli.ts",
"dev:notion": "tsx src/notion/cli.ts",
"dev:trello": "tsx src/trello/cli.ts -h"
},
"bin": {
"dandori-core": "./dist/core/cli.js",
"dandori-miro": "./dist/miro/cli.js",
"dandori-notion": "./dist/notion/cli.js"
"dandori-notion": "./dist/notion/cli.js",
"dandori-trello": "./dist/trello/cli.js"
},
"keywords": [],
"author": "Hiroki Miyaji",
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/notion/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "vitest";
import { DandoriTask } from "@dandori/core";
import { generateDandoriNotionPages } from "@dandori/ui";
import DandoriMiroCli from "../index";
import DandoriNotionCli from "../index";
import { rm, writeFile } from "fs/promises";

const tasks: DandoriTask[] = [
Expand Down Expand Up @@ -60,7 +60,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["-d", databaseId]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with database id", () => {
Expand All @@ -75,7 +75,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["--name", name]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with databasePropertiesMap.name", () => {
Expand All @@ -92,7 +92,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["--deadline", deadline]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with databasePropertiesMap.deadline", () => {
Expand All @@ -109,7 +109,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["--status", status]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with databasePropertiesMap.status", () => {
Expand All @@ -126,7 +126,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["--status-todo", statusTodo]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with databasePropertiesMap.status.todo", () => {
Expand All @@ -143,7 +143,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["--status-doing", statusDoing]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with databasePropertiesMap.status.doing", () => {
Expand All @@ -160,7 +160,7 @@ describe("DandoriNotionCli", () => {

beforeEach(async () => {
loadProcessArgv(["--status-done", statusDone]);
await new DandoriMiroCli().run();
await new DandoriNotionCli().run();
});

it("call generateDandoriNotionPages with databasePropertiesMap.status.done", () => {
Expand Down
123 changes: 123 additions & 0 deletions packages/cli/src/trello/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import {
describe,
beforeEach,
afterEach,
vi,
expect,
it,
beforeAll,
afterAll,
Mock,
} from "vitest";
import { DandoriTask } from "@dandori/core";
import { generateDandoriTrelloCards } from "@dandori/ui";
import DandoriTrelloCli from "../index";
import { rm, writeFile } from "fs/promises";

const tasks: DandoriTask[] = [
{
id: "1",
name: "task1",
deadline: "2021-01-01",
description: "task1-description",
fromTaskIdList: [],
status: "todo",
},
];

vi.mock("@dandori/core", () => ({
default: vi.fn(() => tasks),
}));

vi.mock("@dandori/ui", () => ({
generateDandoriTrelloCards: vi.fn(),
}));

const mockGenerateDandoriTrelloCards = generateDandoriTrelloCards as Mock;

describe("DandoriTrelloCli", () => {
const inputFileName = "DandoriTrelloCli.txt";
const inputFileText = "DandoriTrelloCli";
const loadProcessArgv = (options: string[]) => {
process.argv = ["node", "cli.js", inputFileName, ...options];
};

beforeAll(async () => {
await writeFile(inputFileName, inputFileText);
});

afterAll(async () => {
await rm(inputFileName);
});

afterEach(() => {
process.argv = [];
vi.clearAllMocks();
});

describe("with -b option", () => {
const boardId = "boardId";

beforeEach(async () => {
loadProcessArgv(["-b", boardId]);
await new DandoriTrelloCli().run();
});

it("call generateDandoriTrelloCards with board id", () => {
expect(mockGenerateDandoriTrelloCards.mock.lastCall[1]).toMatchObject({
boardId,
});
});
});

describe("with --status-todo option", () => {
const statusTodo = "ToDo";

beforeEach(async () => {
loadProcessArgv(["--status-todo", statusTodo]);
await new DandoriTrelloCli().run();
});

it("call generateDandoriTrelloCards with trelloListPropertiesMap.status.todo", () => {
expect(
mockGenerateDandoriTrelloCards.mock.lastCall[1].trelloListPropertiesMap,
).toMatchObject({
"status.todo": statusTodo,
});
});
});

describe("with --status-doing option", () => {
const statusDoing = "Doing";

beforeEach(async () => {
loadProcessArgv(["--status-doing", statusDoing]);
await new DandoriTrelloCli().run();
});

it("call generateDandoriTrelloCards with trelloListPropertiesMap.status.doing", () => {
expect(
mockGenerateDandoriTrelloCards.mock.lastCall[1].trelloListPropertiesMap,
).toMatchObject({
"status.doing": statusDoing,
});
});
});

describe("with --status-done option", () => {
const statusDone = "Done";

beforeEach(async () => {
loadProcessArgv(["--status-done", statusDone]);
await new DandoriTrelloCli().run();
});

it("call generateDandoriTrelloCards with trelloListPropertiesMap.status.done", () => {
expect(
mockGenerateDandoriTrelloCards.mock.lastCall[1].trelloListPropertiesMap,
).toMatchObject({
"status.done": statusDone,
});
});
});
});
6 changes: 6 additions & 0 deletions packages/cli/src/trello/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env node

import DandoriTrelloCli from "./index";

const cli = new DandoriTrelloCli();
void cli.run();
26 changes: 26 additions & 0 deletions packages/cli/src/trello/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { generateDandoriTrelloCards } from "@dandori/ui";
import DandoriCoreCli from "../core";

export default class DandoriTrelloCli extends DandoriCoreCli {
override async run(): Promise<void> {
const tasks = await this.generateDandoriTasks();
const opts = this.program.opts();
await generateDandoriTrelloCards(tasks, {
boardId: opts.boardId,
trelloListPropertiesMap: {
"status.todo": opts.statusTodo,
"status.doing": opts.statusDoing,
"status.done": opts.statusDone,
},
});
}

protected override buildCommand() {
return super
.buildCommand()
.option("-b, --board-id <board-id>", "trello board id")
.option("--status-todo <status-todo>", "trello list status todo name")
.option("--status-doing <status-doing>", "trello list status doing name")
.option("--status-done <status-done>", "trello list status done name");
}
}
Loading

0 comments on commit 2712a7f

Please sign in to comment.