Repository navigation
Add webhook management service - #182
abhinavgautam01 wants to merge 4 commits into
Conversation
andrew
left a comment
There was a problem hiding this comment.
Please address these two points:
- In
internal/cli/webhook.go:140,fmt.Sscanfaccepts a numeric prefix without consuming the entire argument. Runningforge webhook delete 7oops --yesagainst a local mock server sentDELETE /api/v1/repos/owner/repo/hooks/7, printedDeleted webhook 7, and exited successfully. Parse the entire ID, reject malformed values, and add a command-execution test asserting that invalid input sends no delete request. - In
gitea/webhooks.go:76-92, event names pass through unchanged despite the public API promising GitHub event names. For example,gollumcannot subscribe to Gitea'swikievent, and reads returnwikiwithout normalization. Translate names on create and read, reject unsupported events, and add tests for the mapping. Gitea documents thewikievent here: https://docs.gitea.com/usage/repository/webhooks/
|
Thanks, both fixed.
|
# Conflicts: # internal/cli/pr_checkout_test.go
andrew
left a comment
There was a problem hiding this comment.
Both earlier points are fixed, thanks.
One more. status, workflow_run and workflow_job in gitea/webhooks.go don't reliably reach the server. Forgejo's addHook has no status event, and only has granular workflow_run_* and workflow_job_* events. Gitea added status in late 2024 and the workflow events in 1.25.0. Both servers silently ignore any event name they don't know. So forge webhook add -e workflow_run against Forgejo or an older Gitea returns 201 and creates a hook that subscribes to nothing, which contradicts the "reject names they cannot map" contract on Webhook.
Please remove those three entries from giteaWebhookEvents so toGiteaEvents rejects them before any request is sent, and add a test that covers the rejection. They can be added back once the backend can tell Gitea and Forgejo versions apart.
|
Thanks, fixed. I removed status, workflow_run and workflow_job from giteaWebhookEvents, so toGiteaEvents now rejects them before any request is sent. The table comment explains why. A new test covers the rejection both directly and through Create against a mock server that fails if a request arrives. I also checked Forgejo's addHook and every remaining name in the table is accepted by both servers. |
Closes #175
Adds a
WebhookServiceto theForgeinterface so consumers can create, list, get and delete repository webhooks through the same normalized API used for the other services. Parsing incoming webhook payloads stays separate in #50.API
The shape mirrors
DeployKeyService, including theLimit/Page/PerPagelist options andErrNotFoundon 404.Backend support
ErrNotSupported)ErrNotSupportedDesign notes
push,issues,issue_comment,pull_request,releaseand so on). GitHub receives them as is. Gitea/Forgejo and GitLab translate them to and from their own events and reject names they cannot map, before any request is sent.push,create,delete,fork,release,repository,packagegollumwikiwikiissuesissues_only,issue_assign,issue_label,issue_milestoneissues,issue_assign,issue_label,issue_milestoneissue_commentissue_comment,pull_request_commentissue_comment,pull_request_commentpull_requestpull_request_only,pull_request_assign,pull_request_label,pull_request_milestone,pull_request_sync,pull_request_review_requestpull_requestplus the same sub-eventspull_request_reviewpull_request_reviewpull_request_review,pull_request_review_approved,pull_request_review_rejected,pull_request_review_commentissuesandpull_requeston create as groups that also enable their comment and review events, so the*_onlyforms plus explicit sub-events keep GitHub's narrower meaning. Reads fold the granular events back into normalized names in a stable order. Any reported event with no normalized name is kept as reported.status,workflow_runandworkflow_jobare rejected on Gitea/Forgejo for now. Forgejo has nostatusevent and only granularworkflow_run_*/workflow_job_*events. Older Gitea lacks them too. Both silently ignore unknown names. They can come back once the backend can tell Gitea and Forgejo versions apart.pushpush_eventstag_push(GitLab only)tag_push_eventsissuesissues_eventsissue_commentnote_eventspull_requestmerge_requests_eventsreleasereleases_eventsdeploymentdeployment_eventsgollumwiki_page_eventsworkflow_runpipeline_eventsworkflow_jobjob_eventsalert_statusdrivesActive.ContentTypedefaults tojson. GitLab always sends JSON, so it is ignored there.InsecureSSLmaps toinsecure_sslon GitHub andenable_ssl_verificationon GitLab. Gitea/Forgejo have no per-hook setting, so it is ignored there.CLI
webhook deleteparses the whole ID and rejects malformed or non-positive values such as7oops,7.5and0without sending a request.Tests
webhook deleteIDs send no delete request.go test -race ./...,go test -tags=tinygo ./gitlab, the js/wasip1 WebAssembly builds andgolangci-lintv2.14.0 all pass locally.🤖 Generated with Claude Code