Repository navigation
fix(webhook): store the first post by project name and reload the blueprint - #9426
Open
shaynhornik wants to merge 1 commit into
Open
shaynhornik wants to merge 1 commit into
shaynhornik wants to merge 1 commit into
Conversation
…eprint getOrCreateConnection declared a new err inside the not-found branch, so after creating the connection it still returned the not-found error from the lookup: the first call to a by-project-name endpoint answered 404 and dropped its payload. The inner calls now assign to the outer err and the function returns nil once the connection exists. The connection is attached with a direct insert, but the scheduled job runs the copy of the blueprint it was scheduled with, so scheduled runs left the webhook out until the blueprint was saved or the server restarted. The blueprint's job is now reloaded from the database after the connection is attached, through the new services.ReloadBlueprintById. Closes apache#9418 Generated-by: Claude Code (Claude Fable 5.2) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the two problems in #9418, both in
getOrCreateConnection(backend/plugins/webhook/api/deployments.go), which the by-project-name endpoints for deployments, issues and pull requests share.1. The first call returned 404 and dropped the payload.
projectOutput, err := services.GetProject(projectName)declared a newerrinside the not-found branch. After the connection was created, the function still returned the not-found error from the lookup, so the caller got a 404 and the payload was not stored. The inner calls now assign to the outererr, and the function returnsnilonce the connection exists.2. Scheduled runs ignored the new connection.
The connection is attached with a direct
dal.Create(blueprintConnection), but the cron job runs the copy of the blueprint it was scheduled with. After the insert, the blueprint's job is now reloaded from the database through a newservices.ReloadBlueprintById, which loads the blueprint and re-registers its job, the same way saving it does. I kept the direct insert instead of going throughPatchBlueprint, so attaching a webhook does not depend on the rest of the blueprint passing validation again.If the reload fails, the call returns the error, like the other steps of the function. The connection exists by then, so a retry finds it and stores the payload.
Does this close any open issues?
Closes #9418
Tests
plugins/webhook/api/deployments_test.go(new):server/services/blueprint_test.go:ReloadBlueprintByIdreplaces a stale cron job with one that holds the blueprint as stored, including the attached webhook connection.With the old code restored, the first-call test fails with the not-found error.
getOrCreateConnectioncallsservicesthrough three package variables so the tests can replace them.Run locally:
go test ./plugins/webhook/... ./server/...,go vet, andgolangci-lintv2.15.0 on the changed packages. I did not run the e2e suite, since nothing here has an e2e test.Other Information
Not covered: with several DevLake server instances, only the instance that handles the request reloads its job.
Generated-by: Claude Code (Claude Fable 5.2). I reviewed and tested the change.
🤖 Generated with Claude Code