Refactor duplicate JSONL-from-git parsing code (bd-y2v)

Extract readFromGitRef helper function to eliminate duplicate code for
running git show <ref>:<path> commands. The helper is now used by:
- checkGitForIssues() in autoimport.go
- importFromGit() in autoimport.go
- readFirstIssueFromGit() in init.go

The scanning/parsing logic is intentionally kept separate since each
function has different requirements (error handling, SetDefaults, etc).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-23 22:37:08 -08:00
parent 091b4b8f35
commit 9354dbd9f2
2 changed files with 19 additions and 14 deletions

View File

@@ -1333,12 +1333,9 @@ func readFirstIssueFromJSONL(path string) (*types.Issue, error) {
// readFirstIssueFromGit reads the first issue from a git ref (bd-0is: supports sync-branch)
func readFirstIssueFromGit(jsonlPath, gitRef string) (*types.Issue, error) {
// Get content from git (use ToSlash for Windows compatibility)
gitPath := filepath.ToSlash(jsonlPath)
cmd := exec.Command("git", "show", fmt.Sprintf("%s:%s", gitRef, gitPath)) // #nosec G204
output, err := cmd.Output()
output, err := readFromGitRef(jsonlPath, gitRef)
if err != nil {
return nil, fmt.Errorf("failed to read from git: %w", err)
return nil, err
}
scanner := bufio.NewScanner(bytes.NewReader(output))