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