mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 11:41:27 +00:00
* 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
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
package hookdeliveryforwarder
|
|
|
|
import (
|
|
"context"
|
|
|
|
gogithub "github.com/google/go-github/v37/github"
|
|
)
|
|
|
|
type hookDeliveriesAPI struct {
|
|
GetHookDelivery func(ctx context.Context, id int64) (*gogithub.HookDelivery, *gogithub.Response, error)
|
|
ListHookDeliveries func(ctx context.Context, opts *gogithub.ListCursorOptions) ([]*gogithub.HookDelivery, *gogithub.Response, error)
|
|
}
|
|
|
|
func newHookDeliveriesAPI(client *gogithub.Client, org, repo string, hookID int64) *hookDeliveriesAPI {
|
|
var hookDeliveries *hookDeliveriesAPI
|
|
|
|
if repo != "" {
|
|
hookDeliveries = repoHookDeliveriesAPI(client.Repositories, org, repo, hookID)
|
|
} else {
|
|
hookDeliveries = orgHookDeliveriesAPI(client.Organizations, org, hookID)
|
|
}
|
|
|
|
return hookDeliveries
|
|
}
|
|
|
|
func repoHookDeliveriesAPI(svc *gogithub.RepositoriesService, org, repo string, hookID int64) *hookDeliveriesAPI {
|
|
return &hookDeliveriesAPI{
|
|
GetHookDelivery: func(ctx context.Context, id int64) (*gogithub.HookDelivery, *gogithub.Response, error) {
|
|
return svc.GetHookDelivery(ctx, org, repo, hookID, id)
|
|
},
|
|
ListHookDeliveries: func(ctx context.Context, opts *gogithub.ListCursorOptions) ([]*gogithub.HookDelivery, *gogithub.Response, error) {
|
|
return svc.ListHookDeliveries(ctx, org, repo, hookID, opts)
|
|
},
|
|
}
|
|
}
|
|
|
|
func orgHookDeliveriesAPI(svc *gogithub.OrganizationsService, org string, hookID int64) *hookDeliveriesAPI {
|
|
return &hookDeliveriesAPI{
|
|
GetHookDelivery: func(ctx context.Context, id int64) (*gogithub.HookDelivery, *gogithub.Response, error) {
|
|
return svc.GetHookDelivery(ctx, org, hookID, id)
|
|
},
|
|
ListHookDeliveries: func(ctx context.Context, opts *gogithub.ListCursorOptions) ([]*gogithub.HookDelivery, *gogithub.Response, error) {
|
|
return svc.ListHookDeliveries(ctx, org, hookID, opts)
|
|
},
|
|
}
|
|
}
|