feat: add context.Context + unexport client fields #14
Reference in New Issue
Block a user
Delete Branch "fix/context-and-encapsulation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Addresses REVIEW.md findings 1-4, 14:
context.Contextas first paramcontext.Contextas first paramhttp.NewRequestWithContextfor cancellation/timeout supportbaseURL,token,apiKey, etc.)bytes.NewReaderinstead ofstrings.NewReader(string(...))Findings Addressed
Summary
Well-scoped, idiomatic changes adding context support across clients and unexporting client fields. HTTP requests now respect cancellation/timeouts, and tests were updated accordingly. CI passed.
Recommendation
APPROVE — The changes correctly introduce context.Context through the Gitea and LLM clients, use http.NewRequestWithContext, unexport client fields, and replace strings.NewReader(string(data)) with bytes.NewReader(data). main now uses a 3-minute timeout context, and tests were updated to pass contexts. Everything aligns with the repository conventions and error-handling practices, and CI is green. As a future enhancement (not required for this PR), consider allowing injection of an http.Client or setting a default timeout on the client to provide sane defaults in contexts where no timeout is provided (e.g., integration tests). Overall, this is a solid improvement—approved.
Summary
Good changes overall — context.Context propagation, request cancellation support, unexporting client fields, and switching to bytes.NewReader are implemented consistently across the codebase. Tests and integration test updates follow the API changes and CI passed.
Findings
gitea/client.gointegration_test.gollm/client.goomitempty, which is correct to omit zero. Tests rely on JSON decoding to a map and comparing the raw value — that's fine, but be cautious: if the encoder/decoder behavior changes this test may become brittle. Consider adding an explicit unit test that marshals ChatRequest and asserts presence/absence of the temperature key directly.Recommendation
APPROVE — Approve these changes. They correctly add context.Context to public methods, use http.NewRequestWithContext for cancellation, unexport client fields to encapsulate implementation details, and replace unnecessary string conversions with bytes.NewReader. The modifications to tests and integration test are consistent. Consider the minor improvements suggested: add optional debug logging when files are skipped in recursive fetching, simplify owner/repo parsing in the integration test to use strings.SplitN, and add an explicit marshal test for temperature inclusion/omission to make the behavior more robust against future changes.
Summary
Solid refactor adding context propagation throughout HTTP calls and unexporting client fields. Tests updated accordingly and CI passed. Only small readability and integration-test parity nits remain.
Findings
gitea/client.gocontinueinside theif err != nilblock in GetAllFilesInPath is misaligned. Consider gofmt-ing to keep indentation consistent.integration_test.goRecommendation
APPROVE — The changes correctly introduce context-aware HTTP requests across the Gitea and LLM clients, unexport internal client fields, and replace unnecessary string conversions with bytes.NewReader. Main now scopes all operations under a sensible timeout. Unit tests have been updated to pass contexts and verify behavior, and CI is green. Please consider tidying the minor indentation nit in gitea/client.go and updating the integration test prompt calls to reflect the current prompt builder signatures to avoid issues when running with the integration build tag. Otherwise, this is good to merge.
Summary
The PR consistently adds context.Context to client APIs, uses request-level cancellation via http.NewRequestWithContext, unexports client internals, and replaces unnecessary string conversions. Tests and integration tests were updated accordingly and CI passed.
Findings
gitea/client.gogitea/client.gollm/client.gocmd/review-bot/main.goRecommendation
APPROVE — Approve: the changes are correct and idiomatic. The main improvements (adding context, request-level cancellation, unexporting fields, and removing unnecessary string conversions) are properly implemented and tests were updated. Address the minor suggestions: consider documenting client reuse/thread-safety, optionally set a default http.Client timeout or document why it's omitted, and verify formatting/indentation around the added log + continue in GetAllFilesInPath. Other than these small improvements, the PR is ready to merge.
Summary
Solid update adding context.Context to all client methods, unexporting client fields, and improving HTTP request construction and timeouts. Tests and integration usage are updated consistently, and CI has passed.
Recommendation
APPROVE — The changes are correct and idiomatic: context propagation is implemented properly, http.NewRequestWithContext is used, client fields are unexported, and the unnecessary string conversion is removed. HTTP client timeouts were added, and tests were updated accordingly. No issues found; proceed with merge.
Summary
Solid, idiomatic changes adding context.Context to all client methods, unexporting client fields, and improving HTTP request handling. Tests and integration test were updated accordingly, and CI has passed.
Recommendation
APPROVE — The changes are correct and align with Go best practices and the repository conventions: context propagation, using http.NewRequestWithContext, unexported client internals, and better request body handling. The updates to tests and integration flow look consistent and comprehensive. With CI passing and no functional or design issues observed, this is good to merge.
Summary
Good changes: context.Context propagated throughout client APIs, HTTP requests use NewRequestWithContext, client fields are unexported, and tests updated accordingly. The modifications are correct and improve cancellation/timeout behavior; CI passed.
Findings
llm/client.gocmd/review-bot/main.goRecommendation
APPROVE — Approve. The changes are correct and idiomatic: contexts are added to public client methods, HTTP requests use NewRequestWithContext, clients have sensible per-client timeouts, fields are now unexported, and tests updated. Consider documenting that WithTemperature must be called during client setup (or change it to return an immutable copy) to avoid potential data races in concurrent scenarios. The other nits are optional stylistic suggestions.
Summary
The Go changes are solid: context propagation is correctly added throughout, client fields are unexported, HTTP requests use context-aware constructors, and tests are updated accordingly. However, the composite action YAML was corrupted with duplicated and misplaced inputs, which will likely break the action metadata.
Findings
.gitea/actions/review/action.ymlRecommendation
REQUEST_CHANGES — Overall the Go implementation and tests look correct and idiomatic: context.Context is threaded through all HTTP calls, clients use http.NewRequestWithContext, unexported fields improve encapsulation, and tests were updated to match the new signatures. However, please fix the composite action YAML before merging. The inputs block must declare temperature and timeout exactly once each, with proper descriptions/defaults, and without duplicate keys. Also ensure the environment mapping (LLM_TIMEOUT: ${{ inputs.timeout }}) aligns with the corrected inputs. Once the action.yml is corrected, this can be approved.
Summary
Overall the changes correctly add context.Context propagation, unexport client fields, proper use of http.NewRequestWithContext, and bytes.NewReader usage. However, the .gitea/actions/review/action.yml was corrupted with many duplicated/incorrect keys which will likely break the action definition and should be fixed before merge. A few minor cleanups / clarifications are also recommended.
Findings
.gitea/actions/review/action.ymlgitea/client.gollm/client.gogitea/client.gocmd/review-bot/main.goRecommendation
REQUEST_CHANGES — Fix the .gitea/actions/review/action.yml to remove duplicate/contradictory input definitions and ensure each input key appears only once (e.g. a single 'temperature' and a single 'timeout' with correct default and description). After cleaning the YAML, re-run CI to confirm no other issues. The Go changes are largely correct and idiomatic — keep the context propagation and unexported fields. Consider minor polish on logging messages and ensure callers consistently handle/chain WithTimeout/WithTemperature if desired.
Summary
Solid refactor adding context support across clients, unexporting client fields, introducing sane HTTP timeouts, and fixing minor inefficiencies. Tests and integration code are updated accordingly and CI passed.
Findings
llm/client.gogitea/client.goRecommendation
APPROVE — The changes are well-executed: context is threaded through all network operations, HTTP requests use NewRequestWithContext for proper cancellation, client fields are unexported, and the action and main package expose a configurable LLM timeout. Tests are updated to use context and still validate behavior, and CI passed. Consider aligning the doc comments in llm/client.go so each exported method has an accurate, self-referential comment, and optionally improve the error reporting in GetAllFilesInPath to surface the most relevant underlying error. Otherwise, this is ready to merge.
Summary
Changes correctly add context.Context propagation, use context-aware HTTP requests, unexport client internals, and replace unnecessary string conversions. Tests and integration tests were updated accordingly and CI passed.
Findings
gitea/client.gollm/client.gogitea/client.goRecommendation
APPROVE — Approve these changes. They improve context propagation and cancellation support and tidy up client encapsulation. Before merging, document the breaking change of unexported client fields in release notes. Optionally add a unit test for llm.WithTimeout and add a small warning log when directory recursion in GetAllFilesInPath fails to aid debugging.
Summary
Solid refactor adding context support, unexporting client fields, and improving HTTP handling. Changes are idiomatic, tests were updated accordingly, and CI passed.
Findings
cmd/review-bot/main.gollm/client.gogitea/client.gogitea/client.gocmd/review-bot/main.goRecommendation
APPROVE — The refactor is well-executed: context is threaded through all network calls, client fields are properly unexported, HTTP requests use context-aware constructors, and tests are updated and expanded (including timeouts). CI passed. I recommend merging as-is. As follow-ups, consider clarifying concurrency guarantees for the LLM client’s mutating configuration methods, making the overall timeout configurable or derived from inputs, exposing a timeout configuration for the Gitea client, and optionally breaking early in helper loops when the context is canceled to reduce unnecessary work.
Summary
The change cleanly adds context.Context propagation, request cancellation via http.NewRequestWithContext, unexports client internals, and replaces unnecessary string conversions. Tests were updated accordingly and CI passed.
Findings
.gitea/actions/review/action.ymlcmd/review-bot/main.gogitea/client.gollm/client.gollm/client_test.goRecommendation
APPROVE — Approve: The PR correctly implements context propagation across the Gitea and LLM clients, improves request cancellation support, hides internal client fields, and replaces unnecessary string conversions. The changes are well-scoped and tests were updated to match the API changes. I recommend merging as-is. As follow-ups, consider documenting the interaction between context-based cancellation and client-level timeouts in package comments, and consider whether some long-running operations should use separate child contexts with tailored timeouts to avoid a single top-level timeout cancelling unrelated operations.
Summary
Solid refactor adding context support across clients, unexporting client fields, and improving HTTP handling. Tests and integration points were updated consistently, and CI passed.
Recommendation
APPROVE — The changes are cohesive and idiomatic: context propagation is properly threaded through all HTTP calls, http.NewRequestWithContext is used, client fields are unexported, and bytes.NewReader replaces unnecessary string conversions. Timeouts are sensibly introduced for both Gitea and LLM clients, and main establishes a top-level context with a reasonable deadline. Unit and integration tests were updated accordingly and continue to validate behavior. As optional polish, consider exposing a way to configure the Gitea HTTP client timeout similar to the LLM client, and minimize logging inside the gitea package in favor of returning errors for callers to decide on logging. Otherwise, this is ready to merge.
Summary
The PR cleanly adds context.Context support across Gitea and LLM clients, unexports client internals, uses request contexts for cancellation, and replaces unnecessary string conversions with bytes.Reader. Tests and integration code have been updated accordingly and CI passed.
Findings
gitea/client.gollm/client.go.gitea/actions/review/action.ymlcmd/review-bot/main.goRecommendation
APPROVE — This PR is well implemented: context.Context has been threaded through all network calls, http.NewRequestWithContext is used correctly, client internals are unexported, and tests updated accordingly. Since CI passed and there are no blocking issues, approve the change. Consider the minor suggestions: avoid logging from library code (return warnings/errors to callers), and clarify the expectations around WithTimeout usage and the derived overall timeout in the CLI help or README to reduce surprise for users.