fix(webhook): create a Forgejo-native hook so /forgejo setup webhook works#8
Open
hstern wants to merge 1 commit into
Open
fix(webhook): create a Forgejo-native hook so /forgejo setup webhook works#8hstern wants to merge 1 commit into
/forgejo setup webhook works#8hstern wants to merge 1 commit into
Conversation
…` works
submitWebhook built a go-github Hook{} and called the go-github CreateHook
against Forgejo. Forgejo's API uses its own CreateHookOption shape with a
required `type` field, which go-github never sends, so the request failed with
`[Type]: Required` and the setup wizard could never create a webhook.
Build Forgejo's native payload (type=forgejo, content_type json, the plugin's
own WebhookSecret) and POST it with the user's already-authenticated client
(client.Client()). Because the hook is created with the plugin's WebhookSecret,
incoming deliveries verify against the same secret.
Also drop the post-create ping wait: Forgejo does not emit a ping event on hook
creation (unlike GitHub), so that loop only ever timed out. A successful create
is the confirmation. Switch the event list to Forgejo's event names.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
End-to-end verified on a live Forgejo + Mattermost Team 11.7.2 install with the rebuilt plugin:
So both the create fix and the dropped ping-wait check out in practice. Happy to tweak the hook |
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.
Problem
/forgejo setup webhook(and the setup wizard's webhook step) always fails against a Forgejo server with:submitWebhook(server/plugin/flows.go) builds a*github.Hook{}and calls the go-githubclient.Repositories.CreateHook/Organizations.CreateHook. Forgejo's create-hook API doesn't accept GitHub's hook shape — it uses its ownCreateHookOption, wheretypeis a required field. go-github never sendstype, so Forgejo rejects every create. The webhook can never be created, and since a channel can't be subscribed without a webhook, the notification path is unreachable.There's a second, latent issue right after: the code blocks on
pingBroker.SubscribePings()waiting for a ping event matching the new hook ID. Forgejo doesn't emit a ping on hook creation (unlike GitHub), so even if create succeeded that loop would only ever hit the 28s timeout and report failure.Fix
type: "forgejo",config.content_type: "json",config.secret= the plugin's ownWebhookSecret) andPOSTit to{baseURL}api/v1/repos/{owner}/{repo}/hooks(or…/orgs/{org}/hooks) using the user's already-authenticated client (client.Client()). Because the hook is created with the plugin'sWebhookSecret, incoming deliveries verify against the same secret (X-Hub-Signature), and the plugin already reads theX-Forgejo-Eventheader thattype: forgejohooks send.pull_request_comment,pull_request_review, …).Status / testing
go build ./...passes; the change is confined tosubmitWebhook.[Type]: Requiredfailure was reproduced live (Forgejo + Mattermost Team 11.7.2): the existing/forgejo setup webhookdialog returns{"error":"[Type]: Required"}, and a manually-createdtype: forgejohook is accepted by the same Forgejo API, confirming the missing-typediagnosis.Happy to adjust the hook
type(forgejovsgitea), event list, or add tests per your preference.🤖 Generated with Claude Code