Skip to content

fix(webhook): store the first post by project name and reload the blueprint - #9426

Open
shaynhornik wants to merge 1 commit into
apache:mainfrom
shaynhornik:fix/webhook-project-connection
Open

shaynhornik wants to merge 1 commit into
apache:mainfrom
shaynhornik:fix/webhook-project-connection

Conversation

@shaynhornik

Copy link
Copy Markdown

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 new err inside 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 outer err, and the function returns nil once 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 new services.ReloadBlueprintById, which loads the blueprint and re-registers its job, the same way saving it does. I kept the direct insert instead of going through PatchBlueprint, 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):
    • On the first call, the connection is created and attached, no error is returned, and the blueprint is reloaded.
    • An existing connection is returned without a reload.
    • A failed reload returns its error.
  • server/services/blueprint_test.go: ReloadBlueprintById replaces 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. getOrCreateConnection calls services through three package variables so the tests can replace them.

Run locally: go test ./plugins/webhook/... ./server/..., go vet, and golangci-lint v2.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

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Webhook] Posting by project name: the first call returns 404 and drops the payload, and the scheduled sync ignores the new connection

1 participant