handlers

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package handlers provides shared GitHub event types and handler logic used by both the Plan42 webhook service and the CLI runner.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownEvent = errors.New("github-event-handlers: unknown event type")

ErrUnknownEvent signals that an Event was passed to Handle whose EventType() does not match any registered handler.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	Body  string
	Login string
}

Comment carries the body and author of an issue comment or PR review comment. Login is the commenter's GitHub login.

type Config

type Config struct {
	GithubAppName     string
	GithubAppID       int64
	Plan42Client      Plan42Client
	TokenFetcher      tokens.Fetcher
	LogPayloads       bool
	CommentTriggerStr string
	UIURL             string
	UseGithubApp      bool
}

Config contains options for configuring the handler registry.

Compared to the webhook's current Config:

  • GithubClient was renamed to Plan42Client (it is a Plan42 API client, not GitHub).
  • GithubAPI was removed (now passed per-call to Handle).
  • GithubJWTSigner is removed (webhook-internal concern).

type Event

type Event interface {
	EventType() string
	GetDeliveryID() string
}

Event is the marker interface implemented by every concrete event type.

EventType returns the snake_case GitHub event type string ("issue_comment", "pull_request", etc.) and is used by HandlerRegistry to route to the registered handler.

GetDeliveryID returns a UUID used to correlate logs and traces for one event. For webhook-origin events it is the X-GitHub-Delivery header from the inbound request. For runner-origin events it is a fresh random UUID generated by the runner translator.

func ParseWebhook added in v1.0.13

func ParseWebhook(deliveryID string, messageType string, payload []byte) (Event, error)

type EventBase

type EventBase struct {
	DeliveryID string
}

EventBase carries fields common to every event. Each concrete event embeds EventBase, and the GetDeliveryID() method on EventBase satisfies that part of the Event interface for free.

func (EventBase) GetDeliveryID

func (b EventBase) GetDeliveryID() string

GetDeliveryID returns the delivery identifier for this event.

type HandlerRegistry

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

HandlerRegistry holds one handler function per supported EventType and dispatches events to the matching handler via Handle.

func NewHandlerRegistry

func NewHandlerRegistry(cfg Config) *HandlerRegistry

NewHandlerRegistry constructs a registry with the supplied configuration.

func (*HandlerRegistry) Handle

func (r *HandlerRegistry) Handle(ctx context.Context, evt Event, gh github.API) error

Handle dispatches evt to the registered handler for evt.EventType(). Returns ErrUnknownEvent if no handler is registered for that type. Returns nil on successful dispatch or when the registry is nil. Individual handler implementations log their own internal errors rather than surfacing them through this return value.

func (*HandlerRegistry) Register

func (r *HandlerRegistry) Register(eventType string, handler func(ctx context.Context, evt Event, gh github.API))

Register adds a handler for the given event type. Subsequent tasks use this to wire up concrete handler implementations.

type Installation

type Installation struct {
	ID       int64
	AppID    int64
	AppSlug  string
	OrgLogin string
	OrgID    int64
}

Installation carries GitHub App installation context. Used only by InstallationEvent. OrgLogin and OrgID identify the org or user account this installation targets - the "account" the App is installed onto.

type InstallationEvent

type InstallationEvent struct {
	EventBase
	Action       string // "created", "deleted", or one of GitHub's other installation actions
	Installation Installation
}

InstallationEvent is delivered only via webhook. The Events API does not include this event type, and the runner never constructs one.

func (*InstallationEvent) EventType

func (*InstallationEvent) EventType() string

EventType returns "installation".

type Issue

type Issue struct {
	Number        int
	State         string // "open" or "closed"
	IsPullRequest bool
}

Issue carries the issue-level fields the handlers read. IsPullRequest is true when the underlying issue is the issue-side projection of a pull request.

type IssueCommentEvent

type IssueCommentEvent struct {
	EventBase
	Action         string
	Issue          Issue
	Comment        Comment
	Repository     Repository
	InstallationID *int64
}

IssueCommentEvent is fired when a comment is created on an issue or pull request. The runner only forwards "created" actions; the handler additionally filters on Action == "created".

func (*IssueCommentEvent) EventType

func (*IssueCommentEvent) EventType() string

EventType returns "issue_comment".

type Plan42Client

type Plan42Client interface {
	ListGithubOrgs(ctx context.Context, req *p42.ListGithubOrgsRequest) (*p42.ListGithubOrgsResponse, error)
	UpdateGithubOrg(ctx context.Context, req *p42.UpdateGithubOrgRequest) (*p42.GithubOrg, error)
	DeleteGithubOrg(ctx context.Context, req *p42.DeleteGithubOrgRequest) error
	AddGithubOrg(ctx context.Context, req *p42.AddGithubOrgRequest) (*p42.GithubOrg, error)
	SearchTasks(ctx context.Context, req *p42.SearchTasksRequest) (*p42.List[p42.Task], error)
	CreateTurn(ctx context.Context, req *p42.CreateTurnRequest) (*p42.Turn, error)
	GetLastTurn(ctx context.Context, req *p42.GetLastTurnRequest) (*p42.Turn, error)
	UpdateTask(ctx context.Context, req *p42.UpdateTaskRequest) (*p42.Task, error)
	UpdateWorkstreamTask(ctx context.Context, req *p42.UpdateWorkstreamTaskRequest) (*p42.Task, error)
}

Plan42Client is the subset of the Plan42 API used by event handlers. Renamed from the webhook's "GithubClient" to avoid collision with the new Client type.

type PullRequest

type PullRequest struct {
	ID        int64
	Number    int
	State     string // "open" or "closed"
	Merged    bool
	Draft     bool
	HTMLURL   string
	UpdatedAt *time.Time
	Login     string
}

PullRequest carries the PR-level fields the handlers read. Login is the PR author's GitHub login. UpdatedAt is *time.Time so the handler can distinguish "GitHub did not provide a timestamp" (nil) from a real timestamp. The Go zero value of time.Time does not mean "not set"; translators that receive a missing or zero timestamp from go-github must store nil here.

type PullRequestEvent

type PullRequestEvent struct {
	EventBase
	Action      string
	Number      int
	PullRequest PullRequest
	Repository  Repository
}

PullRequestEvent is fired on PR state changes. The handler does not filter on Action; it reads PullRequest.State, PullRequest.Merged, and PullRequest.Draft to decide what to do.

func (*PullRequestEvent) EventType

func (*PullRequestEvent) EventType() string

EventType returns "pull_request".

type PullRequestReviewCommentEvent

type PullRequestReviewCommentEvent struct {
	EventBase
	Action      string
	Comment     Comment
	PullRequest PullRequest
	Repository  Repository
}

PullRequestReviewCommentEvent is fired when an inline review comment is created on a PR.

func (*PullRequestReviewCommentEvent) EventType

EventType returns "pull_request_review_comment".

type PullRequestReviewEvent

type PullRequestReviewEvent struct {
	EventBase
	Action      string
	Review      Review
	PullRequest PullRequest
	Repository  Repository
}

PullRequestReviewEvent is fired when a PR review is submitted, edited, or dismissed. The handler only acts on Action == "submitted".

func (*PullRequestReviewEvent) EventType

func (*PullRequestReviewEvent) EventType() string

EventType returns "pull_request_review".

type Repository

type Repository struct {
	FullName string
	Name     string
	Org      string
}

Repository identifies a repository. FullName is "owner/name", Name is the short name, Org is the owner login (a GitHub user or organization login). All three fields are populated for every event.

type Review

type Review struct {
	Body  *string
	Login string
}

Review carries a PR review's body and author. Body is *string because GitHub allows reviews with no body (e.g. an "approve" review with no comment); a nil Body causes the review handler to short-circuit before evaluating trigger commands. Login is the reviewer's GitHub login.

Jump to

Keyboard shortcuts

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