Skip to content

Commit a4715a8

Browse files
committed
use a scanner to find todos in a commit
1 parent 545d663 commit a4715a8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pkg/todos/todos.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package todos
22

33
import (
4+
"bufio"
45
"context"
56
"fmt"
67
"regexp"
@@ -116,12 +117,23 @@ func (t *ToDo) existsInCommit(commit *object.Commit) (bool, error) {
116117
}
117118
return false, err
118119
}
119-
c, err := f.Contents()
120+
r, err := f.Reader()
120121
if err != nil {
121122
return false, err
122123
}
123-
contains := strings.Contains(c, t.Comment.String())
124-
return contains, nil
124+
defer r.Close()
125+
s := bufio.NewScanner(r)
126+
for s.Scan() {
127+
line := s.Text()
128+
if strings.Contains(line, t.Comment.String()) {
129+
return true, nil
130+
}
131+
}
132+
err = s.Err()
133+
if err != nil {
134+
return false, err
135+
}
136+
return false, nil
125137
}
126138

127139
// FindBlame sets the blame information on each todo in a set of todos

0 commit comments

Comments
 (0)