diff options
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | cmd/kdev/main.go | 7 | ||||
| -rw-r--r-- | cmd/kdev/record_extractor.go | 23 |
3 files changed, 21 insertions, 16 deletions
@@ -4,11 +4,12 @@ - Once the pipeline is green, `git tag vx.x.x` - `git push --tags` -## kdev +## kdev - [ ] Ignore bin files -- [ ] Ignore regex -- [ ] All config from CLI or file +- [ ] Ignore regex +- [ ] All config from CLI or file + - panic: Error opening config file: open .kdev.yaml: no such file or directory ## gettext diff --git a/cmd/kdev/main.go b/cmd/kdev/main.go index bbf06d7..44d5c5c 100644 --- a/cmd/kdev/main.go +++ b/cmd/kdev/main.go @@ -152,7 +152,12 @@ func processFile(repoPath string, relativePath string, keywords []string, record return nil } for _, line := range matchingLines { - *records = append(*records, recordExtractor.Extract(line.keyword, relativePath, line.line)) + record, err := recordExtractor.Extract(line.keyword, relativePath, line.line) + if err != nil { + slog.Warn("Error extracting record", "err", err) + } else { + *records = append(*records, record) + } } return nil diff --git a/cmd/kdev/record_extractor.go b/cmd/kdev/record_extractor.go index 5781077..a44d6c6 100644 --- a/cmd/kdev/record_extractor.go +++ b/cmd/kdev/record_extractor.go @@ -15,7 +15,7 @@ import ( ) type RecordExtractor interface { - Extract(keyword string, path string, line int) Record + Extract(keyword string, path string, line int) (Record, error) } type StatRecordExtractor struct { @@ -31,13 +31,13 @@ func NewStatRecordExtractor(absolutePath string) *StatRecordExtractor { } } -func (re *StatRecordExtractor) Extract(keyword string, path string, line int) Record { +func (re *StatRecordExtractor) Extract(keyword string, path string, line int) (Record, error) { return Record{ keyword: keyword, path: path, line: line, date: re.fileInfo.ModTime(), - } + }, nil } type GoGitRecordExtractor struct { @@ -54,24 +54,22 @@ func NewGoGitRecordExtractor(head *object.Commit, path string) *GoGitRecordExtra } } -func (re *GoGitRecordExtractor) Extract(keyword string, path string, line int) Record { +func (re *GoGitRecordExtractor) Extract(keyword string, path string, line int) (Record, error) { record := Record{ keyword: keyword, path: path, line: line, } - if re != nil { - record.date = re.blame.Lines[line-1].Date - } + record.date = re.blame.Lines[line-1].Date - return record + return record, nil } type GitRecordExtractor struct { repoPath string } -func (re *GitRecordExtractor) Extract(keyword string, path string, line int) Record { +func (re *GitRecordExtractor) Extract(keyword string, path string, line int) (Record, error) { record := Record{ keyword: keyword, path: path, @@ -83,7 +81,7 @@ func (re *GitRecordExtractor) Extract(keyword string, path string, line int) Rec output, err := cmd.Output() if err != nil { - panic(kcore.Wrap(err, fmt.Sprintf("Error running: git %s", strings.Join(gitArgs, " ")))) + return record, kcore.Wrap(err, fmt.Sprintf("Error running: git %s", strings.Join(gitArgs, " "))) } for _, blameLine := range strings.Split(string(output), "\n") { @@ -91,9 +89,10 @@ func (re *GitRecordExtractor) Extract(keyword string, path string, line int) Rec timestamp, err := strconv.ParseInt(strings.TrimPrefix(blameLine, "author-time "), 10, 64) kcore.Expect(err, "Error parsing timestamp") record.date = time.Unix(timestamp, 0) - return record + return record, nil } } kcore.Assert(false, "No date found in git blame output") - return Record{} + + return Record{}, nil } |
