Documentation
¶
Overview ¶
Package handlers provides shared GitHub event types and handler logic used by both the Plan42 webhook service and the CLI runner.
Index ¶
- Variables
- type Comment
- type Config
- type Event
- type EventBase
- type HandlerRegistry
- type Installation
- type InstallationEvent
- type Issue
- type IssueCommentEvent
- type Plan42Client
- type PullRequest
- type PullRequestEvent
- type PullRequestReviewCommentEvent
- type PullRequestReviewEvent
- type Repository
- type Review
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
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.
type Installation ¶
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 ¶
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 ¶
func (*PullRequestReviewCommentEvent) EventType() string
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 ¶
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.