allow_report/artifacts/
migrate.rs1use allow_core::{AllowConfig, FindingKind};
2
3use crate::InventoryContext;
4
5#[derive(Debug, Clone, Copy)]
6pub struct MigrateReport<'a> {
7 pub inventory: InventoryContext<'a>,
8 pub input_kind: &'a str,
9 pub input_path: &'a str,
10 pub output_path: &'a str,
11 pub force: bool,
12 pub allow_entries: usize,
13 pub baseline_debt: usize,
14 pub unsafe_entries: usize,
15 pub lint_exception_entries: usize,
16 pub entries_with_evidence: usize,
17 pub weak_evidence_references: Option<usize>,
18 pub unsafe_weak_evidence_references: Option<usize>,
19 pub notes: &'a str,
20}
21
22impl<'a> MigrateReport<'a> {
23 pub fn from_config(
24 inventory: InventoryContext<'a>,
25 cfg: &AllowConfig,
26 input_kind: &'a str,
27 input_path: &'a str,
28 output_path: &'a str,
29 force: bool,
30 notes: &'a str,
31 ) -> Self {
32 let counts = MigrateSummaryCounts::from_config(cfg);
33 Self {
34 inventory,
35 input_kind,
36 input_path,
37 output_path,
38 force,
39 allow_entries: counts.allow_entries,
40 baseline_debt: counts.baseline_debt,
41 unsafe_entries: counts.unsafe_entries,
42 lint_exception_entries: counts.lint_exception_entries,
43 entries_with_evidence: counts.entries_with_evidence,
44 weak_evidence_references: None,
45 unsafe_weak_evidence_references: None,
46 notes,
47 }
48 }
49}
50
51#[derive(Debug, Clone, Copy, PartialEq, Eq)]
52struct MigrateSummaryCounts {
53 allow_entries: usize,
54 baseline_debt: usize,
55 unsafe_entries: usize,
56 lint_exception_entries: usize,
57 entries_with_evidence: usize,
58}
59
60impl MigrateSummaryCounts {
61 fn from_config(cfg: &AllowConfig) -> Self {
62 Self {
63 allow_entries: cfg.allow.len(),
64 baseline_debt: cfg
65 .allow
66 .iter()
67 .filter(|entry| entry.classification == "baseline_debt")
68 .count(),
69 unsafe_entries: cfg
70 .allow
71 .iter()
72 .filter(|entry| entry.kind == FindingKind::Unsafe)
73 .count(),
74 lint_exception_entries: cfg
75 .allow
76 .iter()
77 .filter(|entry| entry.kind == FindingKind::LintException)
78 .count(),
79 entries_with_evidence: cfg
80 .allow
81 .iter()
82 .filter(|entry| !entry.evidence.is_empty())
83 .count(),
84 }
85 }
86}