feat: add context.Context + unexport client fields #14

Merged
rodin merged 8 commits from fix/context-and-encapsulation into main 2026-05-01 21:10:37 +00:00
2 changed files with 10 additions and 2 deletions
Showing only changes of commit 69e70466fd - Show all commits
+9 -2
View File
@@ -70,8 +70,9 @@ func main() {
llmClient.WithTimeout(time.Duration(*llmTimeout) * time.Second) llmClient.WithTimeout(time.Duration(*llmTimeout) * time.Second)
} }
// Create a top-level context with a 3-minute timeout for all operations // Create a top-level context. Timeout derived from LLM timeout + 1 min for other ops.
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) overallTimeout := time.Duration(*llmTimeout)*time.Second + time.Minute
ctx, cancel := context.WithTimeout(context.Background(), overallTimeout)
defer cancel() defer cancel()
log.Printf("Reviewing PR #%d on %s/%s", prNumber, owner, repoName) log.Printf("Reviewing PR #%d on %s/%s", prNumber, owner, repoName)
@@ -178,6 +179,9 @@ func main() {
func fetchFileContext(ctx context.Context, client *gitea.Client, owner, repo, ref string, files []gitea.ChangedFile) string { func fetchFileContext(ctx context.Context, client *gitea.Client, owner, repo, ref string, files []gitea.ChangedFile) string {
var sb strings.Builder var sb strings.Builder
for _, f := range files { for _, f := range files {
if ctx.Err() != nil {
break
}
if f.Status == "removed" { if f.Status == "removed" {
continue // Skip deleted files continue // Skip deleted files
} }
@@ -205,6 +209,9 @@ func fetchPatterns(ctx context.Context, client *gitea.Client, patternsRepo, patt
paths := strings.Split(patternsFiles, ",") paths := strings.Split(patternsFiles, ",")
for _, repoRef := range repos { for _, repoRef := range repos {
if ctx.Err() != nil {
break
}
repoRef = strings.TrimSpace(repoRef) repoRef = strings.TrimSpace(repoRef)
if repoRef == "" { if repoRef == "" {
continue continue
+1
View File
@@ -13,6 +13,7 @@ import (
// Client calls an OpenAI-compatible chat completion API. // Client calls an OpenAI-compatible chat completion API.
// A Client is safe for concurrent use by multiple goroutines after construction. // A Client is safe for concurrent use by multiple goroutines after construction.
// WithTimeout and WithTemperature must be called during setup, before concurrent use.
type Client struct { type Client struct {
baseURL string baseURL string
apiKey string apiKey string