githubdispatch

package
v0.3.0-rc.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package githubdispatch is the "github-dispatch" sink (spec GithubDispatchSinkConfig, docs/github-dispatch.md): it triggers a repository_dispatch event or a workflow_dispatch run in one GitHub repository, through the netguard client.

repository_dispatch sends event_type (a template) and a flat client_payload of at most 10 top-level keys, the GitHub limit; every string in it is cut to 2048 bytes at a UTF-8 boundary and truncated is true when anything was cut. workflow_dispatch sends ref and inputs, each input a template cut to 1024 bytes. The subscription's template does not apply: the payload is fixed.

The sink never reads the environment or the store: the core resolves token_env and token_ref into sink.Request.Secrets. The token is sent only to api_base_url, the host the core resolved a stored token for, and the sink follows no redirect. It logs nothing, and its errors carry no token, URL path or response body.

Index

Constants

View Source
const (
	ModeRepositoryDispatch = "repository_dispatch"
	ModeWorkflowDispatch   = "workflow_dispatch"
)

The two GitHub APIs the sink can call (spec GithubDispatchSinkConfig.mode).

View Source
const (
	DefaultAPIBaseURL = "https://api.github.com"
	DefaultEventType  = "angelia.release.published"
	DefaultTimeout    = 10 * time.Second
	MinTimeout        = time.Second
	MaxTimeout        = 2 * time.Minute

	// MaxEventTypeTemplate and MaxInputTemplate bound the templates, in bytes.
	MaxEventTypeTemplate = 1024
	MaxInputTemplate     = 4096
	// MaxInputs is the number of workflow inputs GitHub accepts.
	MaxInputs = 25
	// MaxEventTypeChars is GitHub's limit on a rendered event_type.
	MaxEventTypeChars = 100
	// MaxFieldLen bounds workflow and ref (spec maxLength).
	MaxFieldLen = 255
)

Defaults and bounds of the configuration (spec GithubDispatchSinkConfig).

View Source
const (
	TokenPointer    = "/token_env"
	TokenRefPointer = "/token_ref"
)

Pointers of the token references in sink.Request.Secrets: the JSON Pointer of token_env or token_ref in the configuration.

View Source
const (
	// MaxPayloadStringBytes is the longest string of client_payload.
	MaxPayloadStringBytes = 2048
	// MaxInputBytes is the longest workflow input value.
	MaxInputBytes = 1024
	// MaxBodyBytes is the size the sink keeps the JSON body under, below
	// GitHub's 65535 characters for client_payload. The strings are cut
	// further, deterministically, when escaping would pass it.
	MaxBodyBytes = 60000
)
View Source
const Kind = "github-dispatch"

Kind is the registry key of this sink.

Variables

This section is empty.

Functions

func CheckAPIBaseURL

func CheckAPIBaseURL(s string) error

CheckAPIBaseURL checks api_base_url: an absolute https URL with no userinfo, query or fragment. The token is sent there and nowhere else. The message never echoes the URL.

func CheckEventType

func CheckEventType(s string) error

CheckEventType checks a rendered event_type: 1 to MaxEventTypeChars characters, not blank.

func CheckEventTypeTemplate

func CheckEventTypeTemplate(src string) error

CheckEventTypeTemplate checks an event_type template as CheckTemplate does, then renders it on the sample events and checks each result with CheckEventType.

func CheckInputName

func CheckInputName(k string) error

CheckInputName checks the name of a workflow input. A name ending in _env or _ref is refused: the core reads every such key of a sink configuration, at any depth, as the name of an environment variable or of a stored secret (ADR 0023 section 4, ADR 0024 section 6).

func CheckRef

func CheckRef(s string) error

CheckRef checks the ref of a workflow_dispatch sink: a branch or tag.

func CheckTemplate

func CheckTemplate(src string, limit int) error

CheckTemplate compiles an event_type or input template, the way a subscription template is checked at load: the error gives a position and a reason, never the template text. A template with no action is a literal; its length is the caller's concern.

func CheckWorkflow

func CheckWorkflow(s string) error

CheckWorkflow checks the workflow of a workflow_dispatch sink: a numeric id or a file name such as release.yml. It becomes one path segment.

func IsLiteral

func IsLiteral(src string) bool

IsLiteral reports whether a template has no action, so that its output is itself.

func ValidRepo

func ValidRepo(s string) bool

ValidRepo reports whether s is an owner/name repository. The name may not be "." or "..", which would climb out of the repository's API path.

Types

type Config

type Config struct {
	Mode       string            `json:"mode,omitempty"`
	Repo       string            `json:"repo"`
	APIBaseURL string            `json:"api_base_url,omitempty"`
	TokenEnv   string            `json:"token_env,omitempty"`
	TokenRef   string            `json:"token_ref,omitempty"`
	EventType  string            `json:"event_type,omitempty"`
	Workflow   string            `json:"workflow,omitempty"`
	Ref        string            `json:"ref,omitempty"`
	Inputs     map[string]string `json:"inputs,omitempty"`
	Timeout    string            `json:"timeout,omitempty"`
}

Config is the configuration of a github-dispatch sink (spec GithubDispatchSinkConfig, docs/github-dispatch.md). It holds the name of the variable or of the stored secret with the token, never the token.

type Options

type Options struct {
	// Now is the clock for Retry-After and x-ratelimit-reset. Default
	// time.Now.
	Now func() time.Time
}

Options configures a Sink.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink is the github-dispatch sink. It is safe for concurrent use.

func New

func New(client *http.Client, opts Options) *Sink

New returns a github-dispatch sink sending through client, which must be the netguard client (netguard.Client.HTTPClient). The sink uses a copy of it that does not follow redirects. New panics if client is nil.

func (*Sink) Deliver

func (s *Sink) Deliver(ctx context.Context, req sink.Request) (sink.Result, error)

Deliver implements sink.Sink: one POST. The request is bounded by min(timeout, the deadline of ctx).

func (*Sink) Kind

func (*Sink) Kind() string

Kind implements sink.Sink.

func (*Sink) Validate

func (*Sink) Validate(cfg sink.Config) error

Validate implements sink.Sink. It checks the configuration, including that the templates compile and render on the sample events; it does no I/O.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL