refactor: avoid panic if commit len < 7#1253
refactor: avoid panic if commit len < 7#1253xcoulon wants to merge 2 commits intocodeready-toolchain:masterfrom
Conversation
ensure that the commit length is greater or equal to 7 characters before initializing the short commit variable also, fix a few lint issues Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
WalkthroughUpdates to context handling in a goroutine, linter suppression comments in tests, and refactoring of metrics initialization logic to derive and set version-related gauge metrics based on commit length. Test updates added to validate the new metrics derivation behavior with varying commit string lengths. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
controllers/usersignup/usersignup_controller.go (1)
833-852:⚠️ Potential issue | 🟠 MajorContext cancellation risk in goroutine.
The reconciliation context
ctxpassed to the goroutine will likely be cancelled when theReconcilefunction returns, which happens before this async goroutine completes. This could causerecaptcha.NewClient(ctx)orrclient.AnnotateAssessment(ctx, ...)to fail immediately with a context cancellation error.The previous approach using
context.Background()inside the goroutine was actually correct for this "fire-and-forget" pattern. Consider reverting tocontext.Background()or using a detached context with a timeout:Suggested fix
- go func(ctx context.Context) { - rclient, err := recaptcha.NewClient(ctx) + go func() { + // Use a detached context with timeout since the reconcile context + // will be cancelled when Reconcile returns + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + rclient, err := recaptcha.NewClient(ctx)- }(ctx) + }()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controllers/usersignup/usersignup_controller.go` around lines 833 - 852, The goroutine currently uses the Reconcile `ctx` which may be cancelled before the async work completes; change the goroutine to create a detached context (e.g., use context.Background() or a context.WithTimeout/WithCancel derived from context.Background()) before calling recaptcha.NewClient and rclient.AnnotateAssessment so the fire-and-forget annotate logic in the anonymous goroutine does not immediately fail due to Reconcile cancellation; update the goroutine closure to use that new context when calling recaptcha.NewClient(ctx) and rclient.AnnotateAssessment(ctx, ...), and ensure you still defer rclient.Close() and log errors/results as before (refer to the anonymous goroutine surrounding recaptcha.NewClient, AnnotateAssessment, and the logger calls).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@controllers/usersignup/usersignup_controller.go`:
- Around line 833-852: The goroutine currently uses the Reconcile `ctx` which
may be cancelled before the async work completes; change the goroutine to create
a detached context (e.g., use context.Background() or a
context.WithTimeout/WithCancel derived from context.Background()) before calling
recaptcha.NewClient and rclient.AnnotateAssessment so the fire-and-forget
annotate logic in the anonymous goroutine does not immediately fail due to
Reconcile cancellation; update the goroutine closure to use that new context
when calling recaptcha.NewClient(ctx) and rclient.AnnotateAssessment(ctx, ...),
and ensure you still defer rclient.Close() and log errors/results as before
(refer to the anonymous goroutine surrounding recaptcha.NewClient,
AnnotateAssessment, and the logger calls).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 848af4d4-ad33-448c-9ab7-015476196073
📒 Files selected for processing (4)
controllers/spacerequest/spacerequest_controller_test.gocontrollers/usersignup/usersignup_controller.gopkg/metrics/metrics.gopkg/metrics/metrics_test.go
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexeykazakov, MatousJobanek, rsoaresd, xcoulon The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest flaky test |
|
Going to dig |
|
@xcoulon: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
thanks @rsoaresd :) |


ensure that the commit length is greater or equal to 7 characters before
initializing the short commit variable
also, fix a few lint issues
Signed-off-by: Xavier Coulon xcoulon@redhat.com
Summary by CodeRabbit
Release Notes
Refactor
Tests