diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-02-07 16:10:48 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2023-02-16 11:29:36 +0100 |
| commit | 6e13575de15a4d480e4edf604d5f83ca3ee1c64e (patch) | |
| tree | dc09d46db51c8f7fa7a4df1c852dea016fdb2ac2 /pkg/subsystem | |
| parent | 18376b101dad0dcfb0797275661184c753cbb2d9 (diff) | |
pkg/subsystem: extract emails list
For the subsystem itself, we take both maintainers and lists. But from
all parents we only take lists, because otherwise too many unrelated
people might be notified.
Diffstat (limited to 'pkg/subsystem')
| -rw-r--r-- | pkg/subsystem/entities.go | 13 | ||||
| -rw-r--r-- | pkg/subsystem/entities_test.go | 18 |
2 files changed, 31 insertions, 0 deletions
diff --git a/pkg/subsystem/entities.go b/pkg/subsystem/entities.go index 05032e6c2..1f7456e84 100644 --- a/pkg/subsystem/entities.go +++ b/pkg/subsystem/entities.go @@ -31,6 +31,19 @@ func (subsystem *Subsystem) ReachableParents() map[*Subsystem]struct{} { return ret } +// Emails returns the list of emails related to the subsystem. +func (subsystem *Subsystem) Emails() []string { + ret := []string{} + // For the subsystem itself, we take both lists and maintainers. + ret = append(ret, subsystem.Lists...) + ret = append(ret, subsystem.Maintainers...) + // For its parent subsystems, we only take lists. + for parent := range subsystem.ReachableParents() { + ret = append(ret, parent.Lists...) + } + return ret +} + // PathRule describes the part of the directory tree belonging to a single subsystem. type PathRule struct { IncludeRegexp string diff --git a/pkg/subsystem/entities_test.go b/pkg/subsystem/entities_test.go index df65dbd5a..58166b91b 100644 --- a/pkg/subsystem/entities_test.go +++ b/pkg/subsystem/entities_test.go @@ -21,3 +21,21 @@ func TestReachableParents(t *testing.T) { } assert.ElementsMatch(t, retParents, []*Subsystem{parentA, parentB, parentParent}) } + +func TestSubsystemEmails(t *testing.T) { + parentParent := &Subsystem{Lists: []string{"a@list.com"}, Maintainers: []string{"a@person.com"}} + parent1 := &Subsystem{Lists: []string{"b@list.com"}, Maintainers: []string{"b@person.com"}} + parent2 := &Subsystem{ + Lists: []string{"c@list.com"}, + Maintainers: []string{"c@person.com"}, + Parents: []*Subsystem{parentParent}, + } + subsystem := &Subsystem{ + Lists: []string{"d@list.com"}, + Maintainers: []string{"d@person.com"}, + Parents: []*Subsystem{parent1, parent2}, + } + assert.ElementsMatch(t, subsystem.Emails(), []string{ + "a@list.com", "b@list.com", "c@list.com", "d@list.com", "d@person.com", + }) +} |
