Skip to main content

git_policy_cli/
commit_conclusion.rs

1//! What:
2//!  The events of a settled commit with the fix summary the policies' corrections earned.
3//! Why:
4//!  The summary appears only after some pass changed candidate bytes, and a normalization that removed every change always
5//!  reports it. The conclusion that once landed the commit itself (hook dispatcher, native preparation in the shadow, the
6//!  landing loop) is gone: the resident service is the only writer of a commit.
7//!
8//! In TS you'd write (pseudocode):
9//! ```ts
10//! return withChangedFixSummary({ result: pass, trigger: 'pre-forward', passes, changedPaths });
11//! ```
12
13use super::policy_events::PolicyEvent;
14
15/// What:
16///  The settled pass's events with the fix summary the corrections earned.
17/// Why:
18///   The summary appears only after some pass changed candidate bytes, naming each changed path once in byte order.
19///
20/// In TS you'd write (pseudocode):
21/// ```ts
22/// withChangedFixSummary({ result: pass, trigger: 'pre-forward', passes, changedPaths });
23/// ```
24pub fn events_with_changed_summary(events: Vec<PolicyEvent>, passes: u64, changed_paths: &[Vec<u8>]) -> Vec<PolicyEvent> {
25    if passes == 0 {
26        return events;
27    }
28    return events_with_summary(events, passes, changed_paths);
29}
30
31/// What:
32///  The events with a fix summary appended whatever the pass count.
33/// Why:
34///   A normalization that removed every change always reports its summary.
35///
36/// In TS you'd write (pseudocode):
37/// ```ts
38/// withFixSummary({ result, trigger: 'pre-forward', passes, changedPaths });
39/// ```
40pub fn events_with_summary(mut events: Vec<PolicyEvent>, passes: u64, changed_paths: &[Vec<u8>]) -> Vec<PolicyEvent> {
41    let mut sorted: Vec<Vec<u8>> = changed_paths.to_vec();
42    sorted.sort();
43    events.push(PolicyEvent::FixSummary {
44        trigger: super::policy_trigger::Trigger::PreForward,
45        passes,
46        changed_paths: sorted
47            .iter()
48            .map(|path| { return super::event_path::EventPath::from_git_bytes(path.as_slice()); })
49            .collect(),
50    });
51    return events;
52}
53
54/// Summary controls stay out of the release executable.
55#[cfg(test)]
56#[path = "commit_conclusion_tests.rs"]
57mod tests;