From 6e13575de15a4d480e4edf604d5f83ca3ee1c64e Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 7 Feb 2023 16:10:48 +0100 Subject: 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. --- pkg/subsystem/entities.go | 13 +++++++++++++ pkg/subsystem/entities_test.go | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'pkg/subsystem') 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", + }) +} -- cgit mrf-deployment