Skip to content

Commit

Permalink
feat: make todos works
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 25, 2019
1 parent c519f3d commit d94523d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,31 @@ early [earlyRemoveWithException earlyRemoveAllWithException earlyRemoveAll early
evict [evictAll evictWithException evict evictEarly evictAllEarly]
```

### Todo

```
coca todo
```

results:

```
+------------+--------------+--------------------------------+---------------------------------------------------+-------+
| DATE | AUTHOR | MESSAGES | FILENAME | LINE |
+------------+--------------+--------------------------------+---------------------------------------------------+-------+
| 2019-12-19 | Phodal Huang | 支持 interface 在同一个包内 | core/adapter/api/JavaApiListener.go | 200 |
| 2019-12-21 | Phodal Huang | 处理链试调用 | core/adapter/bs/BadSmellListener.go | 305 |
| 2019-12-18 | Phodal Huang | update this reflect | core/adapter/bs/BadSmellListener.go | 363 |
| 2019-12-15 | Phodal Huang | update for array | core/adapter/bs/BadSmellListener.go | 388 |
| 2019-12-24 | Phodal Huang | 支持依赖注入 | core/adapter/call/JavaCallListener.go | 108 |
| 2019-12-24 | Phodal Huang | add inner creator examples | core/adapter/call/JavaCallListener.go | 209 |
| 2019-12-24 | Phodal Huang | add inner creator examples | core/adapter/call/JavaCallListener.go | 215 |
| 2019-12-24 | Phodal Huang | | core/adapter/call/JavaCallListener.go | 270 |
| 2019-12-20 | Phodal Huang | 处理链试调用 | core/adapter/call/JavaCallListener.go | 324 |
+------------+--------------+--------------------------------+---------------------------------------------------+-------+
```


## Dev

Install Go
Expand Down
13 changes: 12 additions & 1 deletion cmd/todo.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cmd

import (
"github.com/olekukonko/tablewriter"
"github.com/phodal/coca/core/domain/todo"
"github.com/spf13/cobra"
"os"
"strings"
)

type RootCmdConfig struct {
Expand All @@ -21,7 +24,15 @@ var todoCmd = &cobra.Command{
path := cmd.Flag("path").Value.String()
if path != "" {
app := todo.NewTodoApp()
app.AnalysisPath(path)
todos := app.AnalysisPath(path)

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Date", "Author", "Messages", "FileName", "Line"})
for _, todo := range todos {
table.Append([]string{todo.Date, todo.Author, strings.Join(todo.Message, "\n"), todo.FileName, todo.Line})
}

table.Render()
}
},
}
Expand Down
28 changes: 25 additions & 3 deletions core/domain/todo/todo_app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package todo

import (
"fmt"
"github.com/phodal/coca/core/domain/gitt"
"github.com/phodal/coca/core/domain/todo/astitodo"
"log"
Expand All @@ -19,20 +18,43 @@ func NewTodoApp() TodoApp {
}
}

func (a TodoApp) AnalysisPath(path string) {
type TodoDetail struct {
Date string
FileName string
Author string
Line string
Assignee string
Message []string
}

func (a TodoApp) AnalysisPath(path string) []TodoDetail {
var todoList []TodoDetail = nil
todos, err := astitodo.Extract(path)
if err != nil {
log.Fatal(err)
}
for _, todo := range todos {
lineOutput := runGitGetLog(todo.Line, todo.Filename)

todoDetail := &TodoDetail{
Date: "",
FileName: todo.Filename,
Author: "",
Line: strconv.Itoa(todo.Line),
Assignee: todo.Assignee,
Message: todo.Message,
}
commitMessages := gitt.BuildMessageByInput(lineOutput)

if len(commitMessages) > 0 {
commit := commitMessages[0]
fmt.Println(commit.Date, todo.Filename, commit.Author, todo.Line)
todoDetail.Date = commit.Date
todoDetail.Author = commit.Author
}
todoList = append(todoList, *todoDetail)
}

return todoList
}

func runGitGetLog(line int, fileName string) string {
Expand Down

0 comments on commit d94523d

Please sign in to comment.