normevent

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package normevent defines forge-neutral NormalizedEvent types for harness CEL dispatch (ADR 0061). Schema: docs/normative/normalized-event/v1/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeChangeProposalIsFork

func ComputeChangeProposalIsFork(headRepo, baseRepo string) bool

ComputeChangeProposalIsFork reports whether a change proposal is fork-based. Missing head or base repo metadata is treated as fork (fail-closed) so CEL guards like !event.state.change_proposal.is_fork stay trustworthy.

func IsWriteAuthorized

func IsWriteAuthorized(role ActorRole) bool

IsWriteAuthorized reports whether actor.role satisfies ADR 0054 dispatch gate.

Types

type Actor

type Actor struct {
	ID             string    `json:"id"`
	Kind           ActorKind `json:"kind"`
	Role           ActorRole `json:"role"`
	IsEntityAuthor bool      `json:"is_entity_author"`
}

Actor is the user or service account that caused the transition.

type ActorKind

type ActorKind string

ActorKind distinguishes humans from bots.

const (
	ActorHuman ActorKind = "human"
	ActorBot   ActorKind = "bot"
)

type ActorRole

type ActorRole string

ActorRole is the effective repository permission level (ADR 0054).

const (
	RoleAdmin    ActorRole = "admin"
	RoleMaintain ActorRole = "maintain"
	RoleWrite    ActorRole = "write"
	RoleTriage   ActorRole = "triage"
	RoleRead     ActorRole = "read"
	RoleNone     ActorRole = "none"
	RoleExternal ActorRole = "external"
)

func MapGitHubPermission

func MapGitHubPermission(roleName string) ActorRole

MapGitHubPermission maps GitHub collaborator API role_name to ActorRole. Custom repository roles are not resolved here; they map to RoleNone, matching the bash routing gate and keeping dispatch semantics restrictive until custom roles are handled platform-wide.

type ChangeProposal

type ChangeProposal struct {
	ID       int    `json:"id"`
	HeadRepo string `json:"head_repo"`
	BaseRepo string `json:"base_repo"`
	HeadRef  string `json:"head_ref"`
	BaseRef  string `json:"base_ref"`
	HeadSHA  string `json:"head_sha,omitempty"`
	AuthorID string `json:"author_id"`
	IsFork   bool   `json:"is_fork"`
}

ChangeProposal carries branch/repo context for PR/MR workloads.

type Comment

type Comment struct {
	Command     string `json:"command,omitempty"`
	Body        string `json:"body"`
	Instruction string `json:"instruction,omitempty"`
}

Comment describes a comment_added transition.

type Entity

type Entity struct {
	Kind                 EntityKind            `json:"kind"`
	ID                   int                   `json:"id"`
	Key                  string                `json:"key,omitempty"`
	URL                  string                `json:"url"`
	LinkedChangeProposal *LinkedChangeProposal `json:"linked_change_proposal,omitempty"`
}

Entity is the target work item or change proposal.

type EntityKind

type EntityKind string

EntityKind identifies work items vs change proposals.

const (
	EntityWorkItem       EntityKind = "work_item"
	EntityChangeProposal EntityKind = "change_proposal"
)

type Event

type Event struct {
	Repo       string     `json:"repo"`
	Entity     Entity     `json:"entity"`
	Transition Transition `json:"transition"`
	Actor      Actor      `json:"actor"`
	State      State      `json:"state"`
	Source     Source     `json:"source"`
}

Event is a forge-neutral routing input for fullsend dispatch.

func ParseJSON

func ParseJSON(data []byte) (*Event, error)

ParseJSON unmarshals and validates a NormalizedEvent from JSON.

func (*Event) ToMap

func (e *Event) ToMap() (map[string]any, error)

ToMap converts the event to a map for CEL evaluation.

func (*Event) Validate

func (e *Event) Validate() error

Validate checks required fields and cross-field consistency.

type LabelChange

type LabelChange struct {
	Name   string `json:"name"`
	Action string `json:"action"` // added | removed
}

LabelChange describes a label add/remove transition.

type LinkedChangeProposal

type LinkedChangeProposal struct {
	ID  int    `json:"id"`
	URL string `json:"url"`
}

LinkedChangeProposal links a work item to an associated change proposal.

type Review

type Review struct {
	State      string `json:"state"`
	ReviewerID string `json:"reviewer_id"`
}

Review describes a review_submitted transition.

type Source

type Source struct {
	System    SourceSystem `json:"system"`
	RawType   string       `json:"raw_type"`
	RawAction string       `json:"raw_action,omitempty"`
}

Source describes the native forge event.

type SourceSystem

type SourceSystem string

SourceSystem identifies event provenance.

const (
	SystemGitHub   SourceSystem = "github"
	SystemGitLab   SourceSystem = "gitlab"
	SystemJira     SourceSystem = "jira"
	SystemManual   SourceSystem = "manual"
	SystemSchedule SourceSystem = "schedule"
)

type State

type State struct {
	Labels         []string        `json:"labels"`
	ChangeProposal *ChangeProposal `json:"change_proposal,omitempty"`
}

State is a snapshot of entity metadata at event time.

type Transition

type Transition struct {
	Kind    TransitionKind `json:"kind"`
	Label   *LabelChange   `json:"label,omitempty"`
	Comment *Comment       `json:"comment,omitempty"`
	Review  *Review        `json:"review,omitempty"`
}

Transition describes what changed on the entity.

type TransitionKind

type TransitionKind string

TransitionKind is the semantic lifecycle transition.

const (
	TransitionOpened          TransitionKind = "opened"
	TransitionReopened        TransitionKind = "reopened"
	TransitionEdited          TransitionKind = "edited"
	TransitionSynchronized    TransitionKind = "synchronized"
	TransitionUpdated         TransitionKind = "updated"
	TransitionClosed          TransitionKind = "closed"
	TransitionMerged          TransitionKind = "merged"
	TransitionMarkedReady     TransitionKind = "marked_ready"
	TransitionLabelChanged    TransitionKind = "label_changed"
	TransitionCommentAdded    TransitionKind = "comment_added"
	TransitionCommentEdited   TransitionKind = "comment_edited"
	TransitionCommentDeleted  TransitionKind = "comment_deleted"
	TransitionReviewSubmitted TransitionKind = "review_submitted"
)

Jump to

Keyboard shortcuts

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