fix: address PR #62 review findings
CI / test (pull_request) Successful in 16s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 27s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 1m5s
CI / review (gpt-5, security, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 1m40s
CI / test (pull_request) Successful in 16s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 27s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 1m5s
CI / review (gpt-5, security, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 1m40s
- Remove duplicate flag.Parse() call - Fix nil map panic in LoadRemotePersonas error path by assigning empty map when LoadRemotePersonas returns an error - Tighten isNotFoundError to only check HTTP 404 (remove broad 'not found' substring check to avoid false positives) - Clean up personaErr variable scope using narrower-scoped err variables - Add proper doc comment to LoadRemotePersonasFromPath (Go convention) - Add file count cap (50 files) in LoadRemotePersonasFromPath to prevent resource exhaustion from repos with thousands of small files - Update test expectation for tightened isNotFoundError
This commit is contained in:
@@ -40,7 +40,9 @@ func LoadRemotePersonas(ctx context.Context, fetcher PersonaFetcher, owner, repo
|
||||
return LoadRemotePersonasFromPath(ctx, fetcher, owner, repo, DefaultPersonasPath)
|
||||
}
|
||||
|
||||
// LoadRemotePersonasFromPath is like LoadRemotePersonas but allows specifying a custom path.
|
||||
// LoadRemotePersonasFromPath loads personas from a custom path in a remote repository.
|
||||
// It behaves the same as LoadRemotePersonas but allows specifying a path other than
|
||||
// the default .review-bot/personas directory.
|
||||
func LoadRemotePersonasFromPath(ctx context.Context, fetcher PersonaFetcher, owner, repo, path string) (map[string]*Persona, error) {
|
||||
entries, err := fetcher.ListContents(ctx, owner, repo, path)
|
||||
if err != nil {
|
||||
@@ -52,8 +54,17 @@ func LoadRemotePersonasFromPath(ctx context.Context, fetcher PersonaFetcher, own
|
||||
return nil, fmt.Errorf("list remote personas: %w", err)
|
||||
}
|
||||
|
||||
// Cap the number of files to process to prevent resource exhaustion
|
||||
// from repos with thousands of small files.
|
||||
const maxPersonaFiles = 50
|
||||
|
||||
result := make(map[string]*Persona)
|
||||
processed := 0
|
||||
for _, entry := range entries {
|
||||
if processed >= maxPersonaFiles {
|
||||
slog.Warn("persona file limit reached", "limit", maxPersonaFiles, "repo", fmt.Sprintf("%s/%s", owner, repo))
|
||||
break
|
||||
}
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
@@ -85,6 +96,7 @@ func LoadRemotePersonasFromPath(ctx context.Context, fetcher PersonaFetcher, own
|
||||
}
|
||||
|
||||
result[persona.Name] = persona
|
||||
processed++
|
||||
slog.Debug("loaded remote persona", "name", persona.Name, "file", entry.Path)
|
||||
}
|
||||
|
||||
@@ -148,5 +160,5 @@ func isNotFoundError(err error) bool {
|
||||
return false
|
||||
}
|
||||
errStr := err.Error()
|
||||
return strings.Contains(errStr, "HTTP 404") || strings.Contains(errStr, "not found")
|
||||
return strings.Contains(errStr, "HTTP 404")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user