Created and Relations
Some checks failed
release-please / release-please (push) Has been cancelled

This commit is contained in:
2023-06-30 13:14:19 -07:00
parent 71fb44592b
commit b65befe761
2 changed files with 42 additions and 21 deletions

View File

@ -1,8 +1,8 @@
# kanbn2md
[Kanbn](https://github.com/basementuniverse/kanbn) is a CLI Kanban board. It stores
[Kanbn](https://github.com/basementuniverse/kanbn) is a CLI Kanban board. It stores
the task information in markdown format and has a [vscode extension](https://github.com/basementuniverse/vscode-kanbn)
for viewing and editing the board from vscode. What is missing is a way to render the board as a markdown table.
for viewing and editing the board from vscode. What is missing is a way to render the board as a markdown table.
This simple program takes JSON output of `kanbn board -j` on stdin and renders a markdown table on stdout.
## Installation
@ -16,12 +16,16 @@ go install github.com/tjdavis3/kanbn2md
## Usage
```bash
gofmt -w main.go
go build
kanbn board -j | kanbn2md > board.md
kanbn board -j > .kanbn/board.json
kanbn board -j | L:\Git\kanbn2md\kanbn2md.exe >.kanbn/board.md
```
## Example
| Backlog | Todo | In Progress | Done |
| --- | --- | --- | --- |
| Backlog | Todo | In Progress | Done |
| ---------------- | ------------------ | ------------------ | --------- |
| Comment the code | Create github repo | Create a README.md | Build app |
| Add tests | Add error handling | | |
| Add tests | Add error handling | | |

49
main.go
View File

@ -16,18 +16,21 @@ type KanbnColumns [][]struct {
Description string `json:"description"`
ID string `json:"id"`
Metadata struct {
Assigned string `json:"assigned"`
Created string `json:"created"`
Completed string `json:"completed"`
Progress int `json:"progress"`
Started *string `json:"started,omitempty"`
Tags []interface{} `json:"tags"`
Updated string `json:"updated"`
Assigned string `json:"assigned"`
Created string `json:"created"`
Completed string `json:"completed"`
Progress int `json:"progress"`
Started *string `json:"started,omitempty"`
Tags []interface{} `json:"tags"`
Updated string `json:"updated"`
} `json:"metadata"`
Name string `json:"name"`
Progress int `json:"progress"`
Relations []interface{} `json:"relations"`
RemainingWorkload int `json:"remainingWorkload"`
Name string `json:"name"`
Progress int `json:"progress"`
Relations []struct {
Task string `json:"task"`
Type string `json:"type"`
} `json:"relations"`
RemainingWorkload int `json:"remainingWorkload"`
SubTasks []struct {
Completed bool `json:"completed"`
Text string `json:"text"`
@ -67,6 +70,11 @@ func renderBoard(r io.Reader, w io.Writer) error {
return err
}
fmt.Fprintln(w, "<style>")
fmt.Fprintln(w, "created { color: gray }")
fmt.Fprintln(w, "relations { color: Green }")
fmt.Fprintln(w, "</style>")
// Determine how many columns exists and print the header row
columnCount := len(kanbn.Headings)
for _, col := range kanbn.Headings {
@ -90,11 +98,20 @@ func renderBoard(r io.Reader, w io.Writer) error {
// convert columns of rows into rows of columns
for curCol, column := range lane.Columns {
for colRow, task := range column {
complete := ""
if task.Progress == 1 || task.Metadata.Completed != "" {
complete="~~"
}
rows[colRow][curCol] = fmt.Sprintf("%s%s%s", complete, task.Name, complete)
complete := ""
firstRelation := ""
if task.Progress == 1 || task.Metadata.Completed != "" {
complete = "~~"
}
if len(task.Relations) > 0 {
firstRelation = task.Relations[0].Task
}
rows[colRow][curCol] = fmt.Sprintf("%s%s%s<br />%s<br />%s",
complete,
task.Name,
complete,
"<created>"+task.Metadata.Created[0:10]+"</created>",
"<relations>"+firstRelation+"</relations>")
}
}
// print the rows