Help us shape the future of Go! Take the 2026 Go Developer Survey

webhook

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const TraceparentAnnotation = "divergedev.com/traceparent"

TraceparentAnnotation is the Kubernetes annotation key used to propagate W3C Trace Context across Diverge custom resources and child workloads.

Variables

This section is empty.

Functions

func ExecuteSlashCommand added in v0.14.0

func ExecuteSlashCommand(ctx context.Context, c client.Client, ns string, cmd *SlashCommand, repoURL, branch string, prNumber int) error

ExecuteSlashCommand executes a parsed /diverge slash command against the Kubernetes cluster.

func ResolveTraceparent added in v0.16.0

func ResolveTraceparent(r *http.Request) string

ResolveTraceparent extracts or generates a valid W3C version-00 traceparent string for an incoming webhook HTTP request.

func SetTraceparentAnnotation added in v0.16.0

func SetTraceparentAnnotation(obj metav1.Object, traceparent string)

SetTraceparentAnnotation sets the divergedev.com/traceparent annotation on obj when obj is non-nil and traceparent is non-empty.

func TraceparentFromContext added in v0.16.0

func TraceparentFromContext(ctx context.Context) string

TraceparentFromContext returns the W3C traceparent stored in ctx, or resolves/generates one if absent.

func ValidateGitLabWebhookToken added in v0.4.0

func ValidateGitLabWebhookToken(r *http.Request, expectedToken string) bool

ValidateGitLabWebhookToken validates a GitLab webhook payload token.

func WithTraceparent added in v0.16.0

func WithTraceparent(ctx context.Context, traceparent string) context.Context

WithTraceparent returns a copy of ctx carrying the resolved W3C traceparent string.

Types

type ConfigFetcher

type ConfigFetcher interface {
	FetchConfig(ctx context.Context, provider, project, ref string) ([]byte, error)
}

ConfigFetcher fetches .diverge.yaml from a source code repository.

type DeliveryDedup added in v0.9.0

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

DeliveryDedup prevents webhook replay attacks by tracking delivery IDs.

func NewDeliveryDedup added in v0.9.0

func NewDeliveryDedup() *DeliveryDedup

func (*DeliveryDedup) IsDuplicate added in v0.9.0

func (d *DeliveryDedup) IsDuplicate(id string) bool

type GitHubConfigFetcher

type GitHubConfigFetcher struct {
	Token      string
	HTTPClient *http.Client
}

GitHubConfigFetcher fetches .diverge.yaml from the GitHub API.

func (*GitHubConfigFetcher) FetchConfig

func (f *GitHubConfigFetcher) FetchConfig(ctx context.Context, provider, project, ref string) ([]byte, error)

type GitHubIssueCommentPayload added in v0.14.0

type GitHubIssueCommentPayload struct {
	Action string `json:"action"`
	Issue  struct {
		Number      int `json:"number"`
		PullRequest *struct {
			URL string `json:"url"`
		} `json:"pull_request,omitempty"`
	} `json:"issue"`
	PullRequest struct {
		Number int `json:"number"`
		Head   struct {
			Ref string `json:"ref"`
		} `json:"head"`
	} `json:"pull_request"`
	Comment struct {
		Body              string `json:"body"`
		AuthorAssociation string `json:"author_association"`
	} `json:"comment"`
	Repository struct {
		FullName      string `json:"full_name"`
		CloneURL      string `json:"clone_url"`
		HTMLURL       string `json:"html_url"`
		DefaultBranch string `json:"default_branch"`
	} `json:"repository"`
}

type GitHubPRPayload

type GitHubPRPayload struct {
	Action      string `json:"action"`
	PullRequest struct {
		Number int `json:"number"`
		Head   struct {
			Ref string `json:"ref"`
			SHA string `json:"sha"`
		} `json:"head"`
		Base struct {
			Ref string `json:"ref"`
		} `json:"base"`
		State string `json:"state"`
	} `json:"pull_request"`
	Repository struct {
		FullName string `json:"full_name"`
	} `json:"repository"`
}

type GitHubWebhookHandler

type GitHubWebhookHandler struct {
	Client        client.Client
	Config        WebhookConfig
	ConfigFetcher ConfigFetcher
	HTTPClient    *http.Client
	DefaultNS     string
	Dedup         *DeliveryDedup
}

func (*GitHubWebhookHandler) ServeHTTP

func (h *GitHubWebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type GitLabConfigFetcher

type GitLabConfigFetcher struct {
	BaseURL    string
	Token      string
	HTTPClient *http.Client
}

GitLabConfigFetcher fetches .diverge.yaml from the GitLab API.

func (*GitLabConfigFetcher) FetchConfig

func (f *GitLabConfigFetcher) FetchConfig(ctx context.Context, provider, project, ref string) ([]byte, error)

type GitLabMRPayload

type GitLabMRPayload struct {
	ObjectKind       string `json:"object_kind"`
	EventType        string `json:"event_type"`
	ObjectAttributes struct {
		ID           int    `json:"id"`
		IID          int    `json:"iid"`
		TargetBranch string `json:"target_branch"`
		SourceBranch string `json:"source_branch"`
		State        string `json:"state"`
		Action       string `json:"action"`
		LastCommit   struct {
			ID string `json:"id"`
		} `json:"last_commit"`
	} `json:"object_attributes"`
	Project struct {
		Name              string `json:"name"`
		PathWithNamespace string `json:"path_with_namespace"`
	} `json:"project"`
}

GitLabMRPayload is a simple struct to decode MR webhook payloads

type GitLabNotePayload added in v0.14.0

type GitLabNotePayload struct {
	ObjectKind string `json:"object_kind"`
	User       struct {
		ID       int    `json:"id"`
		Username string `json:"username"`
	} `json:"user"`
	ObjectAttributes struct {
		IID               int    `json:"iid"`
		SourceBranch      string `json:"source_branch"`
		Note              string `json:"note"`
		NoteableType      string `json:"noteable_type"`
		AuthorAssociation string `json:"author_association,omitempty"`
	} `json:"object_attributes"`
	MergeRequest struct {
		IID          int    `json:"iid"`
		SourceBranch string `json:"source_branch"`
		TargetBranch string `json:"target_branch"`
	} `json:"merge_request"`
	Project struct {
		Name              string `json:"name"`
		PathWithNamespace string `json:"path_with_namespace"`
		WebURL            string `json:"web_url"`
		GitHTTPURL        string `json:"git_http_url"`
	} `json:"project"`
}

GitLabNotePayload decodes GitLab Note Hook (MR comment) webhook payloads.

type GitLabPreviewGroupWebhookHandler

type GitLabPreviewGroupWebhookHandler struct {
	Client        client.Client
	Config        WebhookConfig
	ConfigFetcher ConfigFetcher
}

func (*GitLabPreviewGroupWebhookHandler) ServeHTTP

type GitLabWebhookHandler

type GitLabWebhookHandler struct {
	Client        client.Client
	Config        WebhookConfig
	ConfigFetcher ConfigFetcher
	AllowedUsers  []string
	DefaultNS     string
	Dedup         *DeliveryDedup
}

func (*GitLabWebhookHandler) ServeHTTP

func (h *GitLabWebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SlashCommand added in v0.14.0

type SlashCommand struct {
	Action    string
	Objective string
	Duration  time.Duration
}

SlashCommand represents a parsed /diverge command from a PR or MR comment.

func ParseSlashCommand added in v0.14.0

func ParseSlashCommand(commentBody string) (*SlashCommand, bool)

ParseSlashCommand parses a PR/MR comment body for a /diverge slash command. Supported commands:

  • /diverge fix <objective>
  • /diverge preview
  • /diverge teardown
  • /diverge extend-ttl [duration]
  • /diverge pause
  • /diverge resume

type WebhookConfig

type WebhookConfig struct {
	SecretToken string
}

Jump to

Keyboard shortcuts

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