Skip to content

Commit ad6490d

Browse files
committed
looks like I lost SearchDir
1 parent 2c8ebdf commit ad6490d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pkg/comments/comments.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"bytes"
55
"io"
66
"io/ioutil"
7+
"os"
78
"path/filepath"
9+
"strings"
810
"sync"
911

1012
"github.com/augmentable-dev/lege"
@@ -94,6 +96,48 @@ func SearchFile(filePath string, reader io.ReadCloser) (Comments, error) {
9496
return comments, nil
9597
}
9698

99+
// SearchDir searches a directory for comments
100+
func SearchDir(dirPath string) (Comments, error) {
101+
found := make(Comments, 0)
102+
// TODO let's see what we can do concurrently here to speed up the processing
103+
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
104+
localPath, err := filepath.Rel(dirPath, path)
105+
if err != nil {
106+
return err
107+
}
108+
pathComponents := strings.Split(localPath, string(os.PathSeparator))
109+
// let's ignore git directories TODO: figure out a more generic way to set ignores
110+
matched, err := filepath.Match(".git", pathComponents[0])
111+
if err != nil {
112+
return err
113+
}
114+
if matched {
115+
return nil
116+
}
117+
if !info.IsDir() {
118+
p, err := filepath.Abs(path)
119+
if err != nil {
120+
return err
121+
}
122+
f, err := os.Open(p)
123+
if err != nil {
124+
return err
125+
}
126+
t, err := SearchFile(p, f)
127+
if err != nil {
128+
return err
129+
}
130+
c := Comments(t)
131+
found = append(found, c...)
132+
}
133+
return nil
134+
})
135+
if err != nil {
136+
return nil, err
137+
}
138+
return found, nil
139+
}
140+
97141
// SearchCommit searches all files in the tree of a given commit
98142
func SearchCommit(commit *object.Commit) (Comments, error) {
99143
found := make(Comments, 0)

0 commit comments

Comments
 (0)