-
Notifications
You must be signed in to change notification settings - Fork 0
fix: address legitimate review feedback #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ func Parse(diffText string) ([]File, error) { | |
| return nil, fmt.Errorf("parsing hunk header %q: %w", line, err) | ||
| } | ||
|
|
||
| lineNum := hunk.StartLine | ||
| lineNum := hunk.NewStartLine | ||
| i++ | ||
|
|
||
| for i < len(lines) && !strings.HasPrefix(lines[i], diffGitPrefix) && !strings.HasPrefix(lines[i], hunkPrefix) { | ||
|
|
@@ -109,29 +109,57 @@ func resolvePathFromHeaders(lines []string, start int, fallback string) string { | |
| return fallback | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: The refactor of |
||
| } | ||
|
|
||
| // parseHunkHeader parses "@@ -old,count +new,count @@" into a Hunk. | ||
| func parseHunkHeader(line string) (Hunk, error) { | ||
| atIdx := strings.Index(line, "+") | ||
| if atIdx < 0 { | ||
| return Hunk{}, fmt.Errorf("no + range in hunk header") | ||
| // Find the range portion between the @@ markers | ||
| // Format: @@ -old_start[,old_count] +new_start[,new_count] @@ | ||
| trimmed := strings.TrimPrefix(line, "@@ ") | ||
| if end := strings.Index(trimmed, " @@"); end >= 0 { | ||
| trimmed = trimmed[:end] | ||
| } | ||
|
|
||
| rest := line[atIdx+1:] | ||
| endIdx := strings.Index(rest, " ") | ||
| if endIdx < 0 { | ||
| endIdx = strings.Index(rest, hunkPrefix) | ||
| parts := strings.SplitN(trimmed, " ", 2) | ||
| if len(parts) < 2 { | ||
| return Hunk{}, fmt.Errorf("invalid hunk header: %q", line) | ||
| } | ||
| if endIdx < 0 { | ||
| endIdx = len(rest) | ||
|
|
||
| oldRange := strings.TrimPrefix(parts[0], "-") | ||
| newRange := strings.TrimPrefix(parts[1], "+") | ||
|
|
||
| oldStart, oldCount, err := parseRange(oldRange) | ||
| if err != nil { | ||
| return Hunk{}, fmt.Errorf("parsing old range %q: %w", oldRange, err) | ||
| } | ||
|
|
||
| newStart, newCount, err := parseRange(newRange) | ||
| if err != nil { | ||
| return Hunk{}, fmt.Errorf("parsing new range %q: %w", newRange, err) | ||
| } | ||
|
|
||
| rangeStr := rest[:endIdx] | ||
| parts := strings.SplitN(rangeStr, ",", 2) | ||
| startLine, err := strconv.Atoi(parts[0]) | ||
| return Hunk{ | ||
| OldStartLine: oldStart, | ||
| OldLineCount: oldCount, | ||
| NewStartLine: newStart, | ||
| NewLineCount: newCount, | ||
| }, nil | ||
| } | ||
|
|
||
| func parseRange(s string) (int, int, error) { | ||
| parts := strings.SplitN(s, ",", 2) | ||
| start, err := strconv.Atoi(parts[0]) | ||
| if err != nil { | ||
| return Hunk{}, fmt.Errorf("parsing start line %q: %w", parts[0], err) | ||
| return 0, 0, fmt.Errorf("parsing start: %w", err) | ||
| } | ||
|
|
||
| count := 1 | ||
| if len(parts) == 2 { | ||
| count, err = strconv.Atoi(parts[1]) | ||
| if err != nil { | ||
| return 0, 0, fmt.Errorf("parsing count: %w", err) | ||
| } | ||
| } | ||
|
|
||
| return Hunk{StartLine: startLine}, nil | ||
| return start, count, nil | ||
| } | ||
|
|
||
| func trimLeadingSpace(s string) string { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,11 @@ type Line struct { | |
| } | ||
|
|
||
| type Hunk struct { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Updating the |
||
| StartLine int | ||
| Lines []Line | ||
| OldStartLine int | ||
| OldLineCount int | ||
| NewStartLine int | ||
| NewLineCount int | ||
| Lines []Line | ||
| } | ||
|
|
||
| type File struct { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,15 @@ import ( | |
| "io" | ||
| "net/http" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/monokrome/codereview/internal/provider" | ||
| ) | ||
|
|
||
| const ( | ||
| DefaultModel = "gemini-2.5-flash" | ||
| apiBaseURL = "https://generativelanguage.googleapis.com/v1beta/models" | ||
| httpTimeout = 120 * time.Second | ||
| ) | ||
|
|
||
| type part struct { | ||
|
|
@@ -70,7 +72,8 @@ func New(apiKey string, model string) provider.ReviewFunc { | |
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Similar to the GitHub client, adding an |
||
| httpReq.Header.Set("Content-Type", "application/json") | ||
|
|
||
| resp, err := http.DefaultClient.Do(httpReq) | ||
| client := &http.Client{Timeout: httpTimeout} | ||
| resp, err := client.Do(httpReq) | ||
| if err != nil { | ||
| return provider.Response{}, fmt.Errorf("calling Gemini API: %w", err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Changing
hunk.StartLinetohunk.NewStartLineis correct. This ensures line numbers for added and context lines are tracked relative to the new file, which is essential for accurate commenting.