diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2023-09-01 11:27:43 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2023-09-04 16:23:28 +0000 |
| commit | 0b6286dc40e114a33a60c7fbbddbe7fcffc1bb4c (patch) | |
| tree | 74175973c29714fde8eb9968099cbd9609be00f9 | |
| parent | 86b18ba77a6ccac6f8cc7c3217d15208267cf20b (diff) | |
dashboard: support subsystems in titles for #syz dup
Use the existing email title parsing mechanism that supports a much
wider range of title prefixes. Add a test.
| -rw-r--r-- | dashboard/app/email_test.go | 17 | ||||
| -rw-r--r-- | dashboard/app/reporting_email.go | 37 |
2 files changed, 33 insertions, 21 deletions
diff --git a/dashboard/app/email_test.go b/dashboard/app/email_test.go index 5cc420f6a..5c587199e 100644 --- a/dashboard/app/email_test.go +++ b/dashboard/app/email_test.go @@ -477,12 +477,11 @@ func TestEmailDup(t *testing.T) { } func TestEmailDup2(t *testing.T) { - for i := 0; i < 3; i++ { + for i := 0; i < 4; i++ { i := i t.Run(fmt.Sprint(i), func(t *testing.T) { c := NewCtx(t) defer c.Close() - build := testBuild(1) c.client2.UploadBuild(build) @@ -507,6 +506,8 @@ func TestEmailDup2(t *testing.T) { c.incomingEmail(msg2.Sender, "#syz dup: BUG: something bad") case 1: c.incomingEmail(msg2.Sender, "#syz dup: [syzbot] BUG: something bad") + case 2: + c.incomingEmail(msg2.Sender, "#syz dup: [syzbot] [subsystemA?] BUG: something bad") default: c.incomingEmail(msg2.Sender, "#syz dup: syzbot: BUG: something bad") reply := c.pollEmailBug() @@ -890,7 +891,7 @@ func TestSubjectTitleParser(t *testing.T) { tests := []struct { inSubject string outTitle string - outSeq int + outSeq int64 }{ { inSubject: "Re: kernel BUG in blk_mq_dispatch_rq_list (4)", @@ -925,6 +926,16 @@ func TestSubjectTitleParser(t *testing.T) { outSeq: 0, }, { + inSubject: "Re: [syzbot]", + outTitle: "", + outSeq: 0, + }, + { + inSubject: "Re: [syzbot] [subsystemA?]", + outTitle: "", + outSeq: 0, + }, + { // Make sure we delete filesystem tags. inSubject: "Re: [syzbot] [ntfs3?] [ext4?] kernel BUG in blk_mq_dispatch_rq_list (4)", outTitle: "kernel BUG in blk_mq_dispatch_rq_list", diff --git a/dashboard/app/reporting_email.go b/dashboard/app/reporting_email.go index a0639e098..cb8b95e4e 100644 --- a/dashboard/app/reporting_email.go +++ b/dashboard/app/reporting_email.go @@ -631,9 +631,11 @@ func handleBugCommand(c context.Context, bugInfo *bugInfoResult, msg *email.Emai if command.Args == "" { return "no dup title" } - cmd.DupOf = command.Args - cmd.DupOf = strings.TrimSpace(strings.TrimPrefix(cmd.DupOf, replySubjectPrefix)) - cmd.DupOf = strings.TrimSpace(strings.TrimPrefix(cmd.DupOf, bugInfo.reporting.Config.(*EmailConfig).SubjectPrefix)) + var err error + cmd.DupOf, err = subjectParser.parseFullTitle(command.Args) + if err != nil { + return "failed to parse the dup title" + } case email.CmdUnCC: cmd.CC = []string{msg.Author} default: @@ -1107,7 +1109,7 @@ func matchBugFromList(c context.Context, sender, subject string) (*bugInfoResult log.Infof(c, "processing bug %v", bug.displayTitle()) // We could add it to the query, but it's probably not worth it - we already have // tons of db indexes while the number of matching bugs should not be large anyway. - if bug.Seq != int64(seq) { + if bug.Seq != seq { log.Infof(c, "bug's seq is %v, wanted %d", bug.Seq, seq) continue } @@ -1151,23 +1153,22 @@ type subjectTitleParser struct { ready sync.Once } -func (p *subjectTitleParser) parseTitle(subject string) (string, int, error) { +func (p *subjectTitleParser) parseTitle(subject string) (string, int64, error) { + rawTitle, err := p.parseFullTitle(subject) + if err != nil { + return "", 0, err + } + return splitDisplayTitle(rawTitle) +} + +func (p *subjectTitleParser) parseFullTitle(subject string) (string, error) { p.prepareRegexps() subject = strings.TrimSpace(subject) parts := p.pattern.FindStringSubmatch(subject) - if parts == nil || parts[1] == "" { - return "", 0, fmt.Errorf("failed to extract the title") - } - title := parts[1] - seq := 0 - if parts[2] != "" { - rawSeq, err := strconv.Atoi(parts[2]) - if err != nil { - return "", 0, fmt.Errorf("failed to parse seq: %w", err) - } - seq = rawSeq - 1 + if parts == nil || parts[len(parts)-1] == "" { + return "", fmt.Errorf("failed to extract the title") } - return title, seq, nil + return parts[len(parts)-1], nil } func (p *subjectTitleParser) prepareRegexps() { @@ -1186,7 +1187,7 @@ func (p *subjectTitleParser) prepareRegexps() { } } rePrefixes := `^(?:(?:` + strings.Join(stripPrefixes, "|") + `)\s*)*` - p.pattern = regexp.MustCompile(rePrefixes + `(?:\[[^\]]+\]\s*)*(.*?)(?:\s\((\d+)\))?$`) + p.pattern = regexp.MustCompile(rePrefixes + `(?:\[[^\]]+\]\s*)*\s*(.*)$`) }) } |
