Skip to content

Commit

Permalink
feat: add basic output for todo
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 25, 2019
1 parent 70071e9 commit c519f3d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/domain/gitt/README.md
Expand Up @@ -2,7 +2,7 @@
GitLogs

```
git log --all --numstat --date=short --pretty="format:[%h] %aN %ad %s" --numstat --reverse
git log --all --date=short --pretty="format:[%h] %aN %ad %s" --numstat --reverse
```

Delete
Expand Down
26 changes: 25 additions & 1 deletion core/domain/todo/todo_app.go
Expand Up @@ -2,8 +2,12 @@ package todo

import (
"fmt"
"github.com/phodal/coca/core/domain/gitt"
"github.com/phodal/coca/core/domain/todo/astitodo"
"log"
"os/exec"
"strconv"
"strings"
)

type TodoApp struct {
Expand All @@ -21,6 +25,26 @@ func (a TodoApp) AnalysisPath(path string) {
log.Fatal(err)
}
for _, todo := range todos {
fmt.Println(todo.Message, todo.Line, todo.Filename)
lineOutput := runGitGetLog(todo.Line, todo.Filename)

commitMessages := gitt.BuildMessageByInput(lineOutput)
if len(commitMessages) > 0 {
commit := commitMessages[0]
fmt.Println(commit.Date, todo.Filename, commit.Author, todo.Line)
}
}
}

func runGitGetLog(line int, fileName string) string {
// git log -1 -L2:README.md --pretty="format:[%h] %aN %ad %s" --date=short --numstat
historyArgs := []string{"log", "-1", "-L" + strconv.Itoa(line) + ":" + fileName, "--pretty=format:[%h] %aN %ad %s", "--date=short", "--numstat", "--summary"}
cmd := exec.Command("git", historyArgs...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}

split := strings.Split(string(out), "\n")
output := split[0] + "\n "
return output
}
2 changes: 1 addition & 1 deletion docs/adr/0009-git-tell-file-history.md
Expand Up @@ -13,7 +13,7 @@ Refs: https://stackoverflow.com/questions/9935379/git-show-all-of-the-various-ch
Show Line History:

```
git log -3,5:README.md
git log -L3,5:README.md
```

Show String History
Expand Down

0 comments on commit c519f3d

Please sign in to comment.