Skip to content

fix(webhook): create a Forgejo-native hook so /forgejo setup webhook works#8

Open
hstern wants to merge 1 commit into
hhru:masterfrom
hstern:fix/forgejo-native-webhook-setup
Open

fix(webhook): create a Forgejo-native hook so /forgejo setup webhook works#8
hstern wants to merge 1 commit into
hhru:masterfrom
hstern:fix/forgejo-native-webhook-setup

Conversation

@hstern
Copy link
Copy Markdown

@hstern hstern commented Jun 3, 2026

Problem

/forgejo setup webhook (and the setup wizard's webhook step) always fails against a Forgejo server with:

[Type]: Required

submitWebhook (server/plugin/flows.go) builds a *github.Hook{} and calls the go-github client.Repositories.CreateHook / Organizations.CreateHook. Forgejo's create-hook API doesn't accept GitHub's hook shape — it uses its own CreateHookOption, where type is a required field. go-github never sends type, 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

  • Build Forgejo's native payload (type: "forgejo", config.content_type: "json", config.secret = the plugin's own WebhookSecret) and POST it 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's WebhookSecret, incoming deliveries verify against the same secret (X-Hub-Signature), and the plugin already reads the X-Forgejo-Event header that type: forgejo hooks send.
  • Drop the post-create ping wait — a successful create is the confirmation.
  • Use Forgejo's event names for the subscription (pull_request_comment, pull_request_review, …).

Status / testing

  • go build ./... passes; the change is confined to submitWebhook.
  • The [Type]: Required failure was reproduced live (Forgejo + Mattermost Team 11.7.2): the existing /forgejo setup webhook dialog returns {"error":"[Type]: Required"}, and a manually-created type: forgejo hook is accepted by the same Forgejo API, confirming the missing-type diagnosis.
  • End-to-end verification of the rebuilt plugin (create succeeds → subscribed channel receives events) is in progress; I'll follow up here with the result.

Happy to adjust the hook type (forgejo vs gitea), event list, or add tests per your preference.

🤖 Generated with Claude Code

…` 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>
@hstern hstern requested a review from SCREEN88 as a code owner June 3, 2026 18:11
@hstern
Copy link
Copy Markdown
Author

hstern commented Jun 3, 2026

End-to-end verified on a live Forgejo + Mattermost Team 11.7.2 install with the rebuilt plugin:

  • /forgejo setup webhook → entered a repo → succeeds (no more [Type]: Required).
  • Forgejo now shows the created hook: type: forgejo, active, URL …/plugins/forgejo/webhook.
  • Subsequent issue/PR/push events on that repo are delivered, signature-verified by the plugin, and posted into the subscribed Mattermost channel.

So both the create fix and the dropped ping-wait check out in practice. Happy to tweak the hook type/event list or add a test if you'd like.

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.

1 participant