From ed75c0a7f1b7d6758be3942746675ff94071d154 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 11 Apr 2023 16:53:24 +0200 Subject: pkg/email/lore: skip syzbot-started subthreads Adjust tests. --- pkg/email/lore/parse.go | 25 +++++++++++++----- pkg/email/lore/parse_test.go | 63 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 10 deletions(-) (limited to 'pkg/email/lore') diff --git a/pkg/email/lore/parse.go b/pkg/email/lore/parse.go index 6d90f9ee5..84bb56352 100644 --- a/pkg/email/lore/parse.go +++ b/pkg/email/lore/parse.go @@ -36,22 +36,33 @@ func (c *parseCtx) record(msg *email.Email) { func (c *parseCtx) threads() []*Thread { threads := map[string]*Thread{} threadsList := []*Thread{} + + newThread := func(msg *email.Email) { + thread := &Thread{ + MessageID: msg.MessageID, + Subject: msg.Subject, + } + threads[msg.MessageID] = thread + threadsList = append(threadsList, thread) + } + // Detect threads, i.e. messages without In-Reply-To. for _, msg := range c.messages { if msg.InReplyTo == "" { - thread := &Thread{ - MessageID: msg.MessageID, - Subject: msg.Subject, - } - threads[msg.MessageID] = thread - threadsList = append(threadsList, thread) + newThread(msg) } } // Assign messages to threads. for _, msg := range c.messages { base := c.first(msg) if base == nil { - continue + if msg.OwnEmail { + // Likely bot's reply to a non-public command. Ignore. + continue + } + // Pretend it's a separate discussion. + newThread(msg) + base = msg } thread := threads[base.MessageID] thread.BugIDs = append(thread.BugIDs, msg.BugIDs...) diff --git a/pkg/email/lore/parse_test.go b/pkg/email/lore/parse_test.go index 90be05200..86e2b51b7 100644 --- a/pkg/email/lore/parse_test.go +++ b/pkg/email/lore/parse_test.go @@ -83,6 +83,28 @@ Content-Type: text/plain Patch`, + // An orphaned reply from a human. + `Date: Sun, 7 May 2017 19:57:00 -0700 +Subject: [syzbot] Some bug 2 +In-Reply-To: +Message-ID: +From: person@email.com +Cc: syzbot +Content-Type: text/plain + + +Bug report`, + // An orphaned reply from a bot. + `Date: Sun, 7 May 2017 19:57:00 -0700 +Subject: Re: [syzbot] Some bug 3 +In-Reply-To: +Message-ID: +From: syzbot+4564456@bar.com +To: all@email.com +Content-Type: text/plain + + +Bug report`, } zone := time.FixedZone("", -7*60*60) @@ -130,6 +152,7 @@ Patch`, Subject: "[syzbot] Some bug", Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone), Author: "syzbot@bar.com", + OwnEmail: true, Command: email.CmdNone, }, { @@ -142,6 +165,16 @@ Patch`, InReplyTo: "", Command: email.CmdNone, }, + { + MessageID: "", + BugIDs: []string{"4564456"}, + Subject: "Re: [syzbot] Some bug", + Date: time.Date(2017, time.May, 7, 19, 58, 1, 0, zone), + Author: "d@user.com", + Cc: []string{"d@user.com"}, + InReplyTo: "", + Command: email.CmdNone, + }, }, }, "": { @@ -160,6 +193,24 @@ Patch`, }, }, }, + "": { + Subject: "[syzbot] Some bug 2", + MessageID: "", + BugIDs: []string{"4564456"}, + Messages: []*email.Email{ + { + MessageID: "", + InReplyTo: "", + Date: time.Date(2017, time.May, 7, 19, 57, 0, 0, zone), + BugIDs: []string{"4564456"}, + Cc: []string{"person@email.com"}, + Subject: "[syzbot] Some bug 2", + Author: "person@email.com", + Command: email.CmdNone, + }, + }, + }, + "": nil, } emails := []*email.Email{} @@ -174,16 +225,22 @@ Patch`, } threads := Threads(emails) + got := map[string]*Thread{} + for _, d := range threads { sort.Slice(d.Messages, func(i, j int) bool { return d.Messages[i].Date.Before(d.Messages[j].Date) }) - if diff := cmp.Diff(expected[d.MessageID], d); diff != "" { - t.Fatalf("%s: %s", d.MessageID, diff) + got[d.MessageID] = d + } + + for key, val := range expected { + if diff := cmp.Diff(val, got[key]); diff != "" { + t.Fatalf("%s: %s", key, diff) } } - if len(threads) != len(expected) { + if len(threads) > len(expected) { t.Fatalf("Expected %d threads, got %d", len(expected), len(threads)) } } -- cgit mrf-deployment