Skip to content

Commit 3f2f8fc

Browse files
committed
add ability to parse when a TODO was added, include in report
also add a spinner to the todos cmd
1 parent dd55f41 commit 3f2f8fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4754
-6
lines changed

cmd/commands/todos.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package commands
22

33
import (
4+
"fmt"
45
"os"
56
"path/filepath"
7+
"time"
68

79
"github.com/augmentable-dev/tickgit/pkg/comments"
810
"github.com/augmentable-dev/tickgit/pkg/todos"
11+
"github.com/briandowns/spinner"
912
"github.com/spf13/cobra"
1013
"gopkg.in/src-d/go-git.v4"
1114
)
@@ -20,6 +23,11 @@ var todosCmd = &cobra.Command{
2023
Long: `Scans a given git repository looking for any code comments with TODOs. Displays a report of all the TODO items found.`,
2124
Args: cobra.MaximumNArgs(1),
2225
Run: func(cmd *cobra.Command, args []string) {
26+
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
27+
s.Suffix = " finding TODOs"
28+
s.Writer = os.Stderr
29+
s.Start()
30+
2331
cwd, err := os.Getwd()
2432
handleError(err)
2533

@@ -47,6 +55,12 @@ var todosCmd = &cobra.Command{
4755
// handleError(err)
4856

4957
t := todos.NewToDos(comments)
58+
for i, todo := range t {
59+
todo.FindBlame(commit)
60+
s.Suffix = fmt.Sprintf(" (%d/%d) %s: %s", i, len(t), filepath.Base(todo.FilePath), todo.String)
61+
// time.Sleep(100 * time.Millisecond)
62+
}
63+
s.Stop()
5064
todos.WriteTodos(t, os.Stdout)
5165
},
5266
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ go 1.13
55
require (
66
github.com/agext/levenshtein v1.2.2 // indirect
77
github.com/augmentable-dev/lege v0.0.0-20191028004410-79cb985065a1
8+
github.com/briandowns/spinner v1.7.0
9+
github.com/dustin/go-humanize v1.0.0
810
github.com/google/go-cmp v0.3.1 // indirect
911
github.com/hashicorp/hcl/v2 v2.0.0
1012
github.com/mitchellh/go-wordwrap v1.0.0 // indirect

go.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
1515
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
1616
github.com/augmentable-dev/lege v0.0.0-20191028004410-79cb985065a1 h1:NBe2//2MA/Z7X4wuKnHSIN+xI/oBTLYMJVc8VCwXK4o=
1717
github.com/augmentable-dev/lege v0.0.0-20191028004410-79cb985065a1/go.mod h1:DtuvAW6+SE9e44O6eLaMJp8PFiadmk6NfXslCKYCiB0=
18+
github.com/briandowns/spinner v1.7.0 h1:aan1hBBOoscry2TXAkgtxkJiq7Se0+9pt+TUWaPrB4g=
19+
github.com/briandowns/spinner v1.7.0/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ=
1820
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
1921
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
2022
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
@@ -23,8 +25,12 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
2325
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2426
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2527
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
28+
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
29+
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
2630
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
2731
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
32+
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
33+
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
2834
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
2935
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
3036
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -60,6 +66,10 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3v
6066
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
6167
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
6268
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
69+
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
70+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
71+
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
72+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
6373
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
6474
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
6575
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
@@ -133,6 +143,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
133143
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
134144
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
135145
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
146+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
136147
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
137148
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
138149
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0=

pkg/comments/comments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var LanguageParseOptions map[Language]*lege.ParseOptions = map[Language]*lege.Pa
6161
}
6262

6363
// Comments is a list of comments
64-
type Comments []Comment
64+
type Comments []*Comment
6565

6666
// Comment represents a comment in a source code file
6767
type Comment struct {
@@ -96,7 +96,7 @@ func SearchFile(filePath string, reader io.ReadCloser) (Comments, error) {
9696
comments := make(Comments, 0)
9797
for _, c := range collections {
9898
comment := Comment{*c, filePath}
99-
comments = append(comments, comment)
99+
comments = append(comments, &comment)
100100
}
101101

102102
return comments, nil

pkg/todos/report.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
const DefaultTemplate = `
1010
{{- range $index, $todo := . }}
1111
{{ print "\u001b[33m" }}TODO{{ print "\u001b[0m" }}: {{ .String }}
12-
=> {{ with .Comment }}{{ .FilePath }}:{{ .StartLocation.Line }}:{{ .StartLocation.Pos }}{{ end }}
12+
=> {{ .Comment.FilePath }}:{{ .Comment.StartLocation.Line }}:{{ .Comment.StartLocation.Pos }}
13+
=> added {{ .TimeAgo }} by {{ .Author }}
1314
{{ else }}
1415
no todos 🎉
1516
{{- end }}

pkg/todos/todos.go

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,70 @@ package todos
33
import (
44
"regexp"
55
"strings"
6+
"time"
67

78
"github.com/augmentable-dev/tickgit/pkg/comments"
9+
"github.com/dustin/go-humanize"
10+
"gopkg.in/src-d/go-git.v4"
11+
"gopkg.in/src-d/go-git.v4/plumbing/object"
812
)
913

1014
// ToDo represents a ToDo item
1115
type ToDo struct {
1216
comments.Comment
1317
String string
18+
Added *time.Time
19+
Author string
1420
}
1521

1622
// ToDos represents a list of ToDo items
17-
type ToDos []ToDo
23+
type ToDos []*ToDo
1824

1925
// Count returns the number of todos
2026
func (t ToDos) Count() int {
2127
return len(t)
2228
}
2329

30+
// TimeAgo returns a human readable string indicating the time since the todo was added
31+
func (t *ToDo) TimeAgo() string {
32+
if t.Added == nil {
33+
return "<unknown>"
34+
}
35+
return humanize.Time(*t.Added)
36+
// dur := time.Now().Sub(*t.Added)
37+
38+
// hours := dur.Hours()
39+
// days := hours / 24
40+
// weeks := days / 7
41+
// months := days / 30
42+
// years := months / 12
43+
44+
// if hours <= 24 {
45+
// return fmt.Sprintf("~%d hours ago", int(math.Round(hours)))
46+
// } else if days <= 7 {
47+
// return fmt.Sprintf("~%d days ago", int(math.Round(days)))
48+
// } else if weeks <= 4 {
49+
// return fmt.Sprintf("~%d weeks ago", int(math.Round(weeks)))
50+
// } else if months <= 12 {
51+
// return fmt.Sprintf("~%d months ago", int(math.Round(months)))
52+
// } else {
53+
// return fmt.Sprintf("~%d years ago", int(math.Round(years)))
54+
// }
55+
}
56+
57+
// FindBlame sets the Added and Author fields on the ToDo
58+
func (t *ToDo) FindBlame(commit *object.Commit) error {
59+
blame, err := git.Blame(commit, t.FilePath)
60+
if err != nil {
61+
return err
62+
}
63+
line := blame.Lines[t.StartLocation.Line]
64+
added := line.Date
65+
t.Added = &added
66+
t.Author = line.Author
67+
return nil
68+
}
69+
2470
// NewToDo produces a pointer to a ToDo from a comment
2571
func NewToDo(comment comments.Comment) *ToDo {
2672
s := comment.String()
@@ -39,9 +85,9 @@ func NewToDo(comment comments.Comment) *ToDo {
3985
func NewToDos(comments comments.Comments) ToDos {
4086
todos := make(ToDos, 0)
4187
for _, comment := range comments {
42-
todo := NewToDo(comment)
88+
todo := NewToDo(*comment)
4389
if todo != nil {
44-
todos = append(todos, *todo)
90+
todos = append(todos, todo)
4591
}
4692
}
4793
return todos

vendor/github.com/briandowns/spinner/.gitignore

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/briandowns/spinner/.travis.yml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)