oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package runnerproto
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/team"
5 "encoding/json"
6 "slices"
7)
8
9func MergeIsolation(a, b team.IsolationSnapshot) team.IsolationSnapshot {
10 a.ProfileApprovals = team.MergeProfileApprovals(a.ProfileApprovals, b.ProfileApprovals)
11 a.Trial = team.MergeTrial(a.Trial, b.Trial)
12 if a.Trial != nil {
13 a.Status = "unconfined"
14 a.RunnerTainted = true
15 }
16 if b.Status == "unconfined" {
17 a.Status = "unconfined"
18 }
19 a.RunnerTainted = a.RunnerTainted || b.RunnerTainted
20 for _, id := range b.AcknowledgementIDs {
21 if !slices.Contains(a.AcknowledgementIDs, id) {
22 a.AcknowledgementIDs = append(a.AcknowledgementIDs, id)
23 }
24 }
25 for _, tuple := range b.ObservedTuples {
26 if !slices.Contains(a.ObservedTuples, tuple) {
27 a.ObservedTuples = append(a.ObservedTuples, tuple)
28 }
29 }
30 return a
31}
32
33func WithoutApproval(iso team.IsolationSnapshot, ids ...string) team.IsolationSnapshot {
34 kept := iso.ProfileApprovals[:0]
35 for _, a := range iso.ProfileApprovals {
36 remove := false
37 for _, id := range ids {
38 if a.QuestionID == id {
39 remove = true
40 }
41 }
42 if !remove {
43 kept = append(kept, a)
44 }
45 }
46 iso.ProfileApprovals = kept
47 return iso
48}
49
50func DecodeSelection(selection, isolation string) (Selection, error) {
51 var sel Selection
52 if err := json.Unmarshal([]byte(selection), &sel); err != nil {
53 return Selection{}, err
54 }
55 var iso team.IsolationSnapshot
56 if err := json.Unmarshal([]byte(isolation), &iso); err != nil {
57 return Selection{}, err
58 }
59 sel.Isolation = iso
60 return sel, nil
61}
62