Skip to main content

Module policy_events

Module policy_events 

Source
Expand description

Policy events and their JSON Lines rendering. What: The events one policy pass produces, and their JSON Lines rendering. Why: Agents and scripts read these lines from wrapper standard error and from git cli-git check|fix standard output. Each event is one compact JSON object with the incumbent’s field names and field order, so existing readers parse native events unchanged. Events are numbered when rendered, so a list of events always prints with consecutive numbers in emission order.

In TS you’d write (pseudocode):

// process.stderr.write(renderPolicyEvents(result.events));

Structs§

FindingEvent
What: One policy finding as it is reported. String is owned UTF-8 text (sibling &str borrows); Option<T> is “a value or nothing”; &'static str is text baked into the program. Why: The record owns its message and path because events outlive the check that made them. The code is compiled-in text, so a shipped policy cannot emit an empty or misspelled code at run time.
FindingLocation
What: A byte range inside a candidate. A struct is a record with named fields; u64 is an unsigned 64-bit integer (siblings u32, usize). Why: Content policies point at the exact bytes of a finding. u64 holds any file offset on every platform, where usize would be 32 bits on a 32-bit system.

Enums§

PolicyEvent
What: Every event a policy pass can produce. An enum is a closed set of named alternatives; each variant carries its own fields. Vec<EventPath> is an owned list of pathnames in their event form. Why: One list of events is rendered in order, whatever mixture of kinds it holds.

Constants§

WARN_UNSAFE_CODE
The code of the warning for a warn severity on a policy whose protection warn removes.

Functions§

event_blocks
What: Whether an event blocks the command. &PolicyEvent borrows the event read-only. Why: An error finding and a fixed-transform rejection keep Git from running; a warning finding and a configuration warning do not.
render_policy_event
What: Render one event as a line-terminated JSON object. &PolicyEvent borrows the event; the result is owned text. Why: One function owns every field order, so two events of one kind can never differ in shape.
render_policy_events
What: Render a list of events, numbered consecutively from first_sequence. &[PolicyEvent] borrows the list. Why: An invocation numbers its events once: events printed before the pass (a legacy configuration notice) take the first numbers and the pass continues after them.