MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / materialsTable

Function materialsTable

app/cli/cmd/attestation_status.go:188–249  ·  view source on GitHub ↗
(status *action.AttestationStatusResult, w io.Writer, full bool)

Source from the content-addressed store, hash-verified

186 return nil
187}
188func materialsTable(status *action.AttestationStatusResult, w io.Writer, full bool) error {
189 if len(status.Materials) == 0 {
190 return nil
191 }
192
193 // Partition materials into standalone (ungrouped) ones and choke groups.
194 // Grouped materials are rendered together under a group header so it is
195 // clear they form an "at least one of" set rather than independent materials.
196 var ungrouped []action.AttestationStatusMaterial
197 groupedBy := make(map[string][]action.AttestationStatusMaterial)
198 var groupOrder []string
199 for _, m := range status.Materials {
200 if m.Group == "" {
201 ungrouped = append(ungrouped, m)
202 continue
203 }
204 if _, ok := groupedBy[m.Group]; !ok {
205 groupOrder = append(groupOrder, m.Group)
206 }
207 groupedBy[m.Group] = append(groupedBy[m.Group], m)
208 }
209
210 byName := func(a, b action.AttestationStatusMaterial) int { return strings.Compare(a.Name, b.Name) }
211 slices.SortFunc(ungrouped, byName)
212 slices.Sort(groupOrder)
213
214 mt := output.NewTableWriterWithWriter(w)
215 mt.SetTitle("Materials")
216
217 for _, m := range ungrouped {
218 appendMaterialRows(mt, m, status, full, false)
219 mt.AppendSeparator()
220 }
221
222 for _, g := range groupOrder {
223 members := groupedBy[g]
224 slices.SortFunc(members, byName)
225
226 // A choke group is satisfied as soon as one of its members is set.
227 satisfied := false
228 for _, m := range members {
229 if m.Set {
230 satisfied = true
231 break
232 }
233 }
234
235 mt.AppendRow(table.Row{"Group", g})
236 mt.AppendRow(table.Row{"Rule", fmt.Sprintf("at least one of %d required", len(members))})
237 mt.AppendRow(table.Row{"Satisfied", hBool(satisfied)})
238 mt.AppendSeparator()
239
240 for _, m := range members {
241 appendMaterialRows(mt, m, status, full, true)
242 mt.AppendSeparator()
243 }
244 }
245

Callers 1

Calls 4

NewTableWriterWithWriterFunction · 0.92
appendMaterialRowsFunction · 0.85
hBoolFunction · 0.85
RenderMethod · 0.80

Tested by

no test coverage detected