Files
actions-runner-controller/pkg/hookdeliveryforwarder/hooks.go
Yusuke Kuoka f858e2e432 Add POC of GitHub Webhook Delivery Forwarder (#682)
* Add POC of GitHub Webhook Delivery Forwarder

* multi-forwarder and ctrl-c existing and fix for non-woring http post

* Rename source files

* Extract signal handling into a dedicated source file

* Faster ctrl-c handling

* Enable automatic creation of repo hook on startup

* Add support for forwarding org hook deliveries

* Set hook secret on hook creation via envvar (HOOK_SECRET)

* Fix org hook support

* Fix HOOK_SECRET for consistency

* Refactor to prepare for custom log position provider

* Refactor to extract inmemory log position provider

* Add configmap-based log position provider

* Rename githubwebhookdeliveryforwarder to hookdeliveryforwarder

* Refactor to rename LogPositionProvider to Checkpointer and extract ConfigMap checkpointer into a dedicated pkg

* Refactor to extract logger initialization

* Add hookdeliveryforwarder README and bump go-github to unreleased ver
2021-07-14 10:18:55 +09:00

47 lines
1.4 KiB
Go

package hookdeliveryforwarder
import (
"context"
gogithub "github.com/google/go-github/v37/github"
)
type hooksAPI struct {
ListHooks func(ctx context.Context, opts *gogithub.ListOptions) ([]*gogithub.Hook, *gogithub.Response, error)
CreateHook func(ctx context.Context, hook *gogithub.Hook) (*gogithub.Hook, *gogithub.Response, error)
}
func newHooksAPI(client *gogithub.Client, org, repo string) *hooksAPI {
var hooksAPI *hooksAPI
if repo != "" {
hooksAPI = repoHooksAPI(client.Repositories, org, repo)
} else {
hooksAPI = orgHooksAPI(client.Organizations, org)
}
return hooksAPI
}
func repoHooksAPI(svc *gogithub.RepositoriesService, org, repo string) *hooksAPI {
return &hooksAPI{
ListHooks: func(ctx context.Context, opts *gogithub.ListOptions) ([]*gogithub.Hook, *gogithub.Response, error) {
return svc.ListHooks(ctx, org, repo, opts)
},
CreateHook: func(ctx context.Context, hook *gogithub.Hook) (*gogithub.Hook, *gogithub.Response, error) {
return svc.CreateHook(ctx, org, repo, hook)
},
}
}
func orgHooksAPI(svc *gogithub.OrganizationsService, org string) *hooksAPI {
return &hooksAPI{
ListHooks: func(ctx context.Context, opts *gogithub.ListOptions) ([]*gogithub.Hook, *gogithub.Response, error) {
return svc.ListHooks(ctx, org, opts)
},
CreateHook: func(ctx context.Context, hook *gogithub.Hook) (*gogithub.Hook, *gogithub.Response, error) {
return svc.CreateHook(ctx, org, hook)
},
}
}