| 108 | } |
| 109 | |
| 110 | fn collect_requests( |
| 111 | graph: &ReviewGraph, |
| 112 | regions: &[presentation::Region], |
| 113 | ) -> BTreeMap<(String, String), Request> { |
| 114 | let mut requests = BTreeMap::<(String, String), Request>::new(); |
| 115 | for region in regions { |
| 116 | let request = requests |
| 117 | .entry((region.change.clone(), region.path.clone())) |
| 118 | .or_default(); |
| 119 | request.findings |= !region.findings.is_empty(); |
| 120 | if !region.findings.is_empty() || !region.impact.is_empty() { |
| 121 | request.known.insert(region.side.clone()); |
| 122 | } |
| 123 | } |
| 124 | for node in graph.nodes.iter().filter(|node| node.kind == "metric") { |
| 125 | let (Some(change), Some(path)) = ( |
| 126 | node.properties["change"].as_str(), |
| 127 | node.properties["path"].as_str(), |
| 128 | ) else { |
| 129 | continue; |
| 130 | }; |
| 131 | let request = requests.entry((change.into(), path.into())).or_default(); |
| 132 | for side in ["before", "after"] { |
| 133 | let value = &node.properties["observation"][side]; |
| 134 | if value["status"] == "measured" |
| 135 | && presentation::metric_location(node, side).0.is_some() |
| 136 | { |
| 137 | request.known.insert(side.into()); |
| 138 | } |
| 139 | if value["status"] == "not_applicable" |
| 140 | && value["reason"] == "File is absent in this revision" |
| 141 | { |
| 142 | request.absent.insert(side.into()); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | // Explicit source locations also cover supplied findings without metrics. |
| 147 | for finding in &graph.findings { |
| 148 | for location in &finding.finding.locations { |
| 149 | requests |
| 150 | .entry((finding.finding.change.clone(), location.path.clone())) |
| 151 | .or_default() |
| 152 | .known |
| 153 | .insert( |
| 154 | match location.side { |
| 155 | SourceSide::Before => "before", |
| 156 | SourceSide::After => "after", |
| 157 | } |
| 158 | .into(), |
| 159 | ); |
| 160 | } |
| 161 | } |
| 162 | requests |
| 163 | } |
| 164 | |
| 165 | fn sources( |
| 166 | repo: &Repository, |