aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/patch.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2026-01-29 13:06:50 +0100
committerDmitry Vyukov <dvyukov@google.com>2026-01-30 11:03:40 +0000
commit6adbdcbe0a33024c6e70ffccd1c76f62a0179098 (patch)
treef5d07618387f400a5b56517282e0dc032d316820 /pkg/email/patch.go
parent5f1dd856122a81d1cf6bcad71da663f42484f321 (diff)
pkg/email: add patch FormatPatch function
Fixes #6673
Diffstat (limited to 'pkg/email/patch.go')
-rw-r--r--pkg/email/patch.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/pkg/email/patch.go b/pkg/email/patch.go
index 81ea9b26c..b33bb09bf 100644
--- a/pkg/email/patch.go
+++ b/pkg/email/patch.go
@@ -6,8 +6,13 @@ package email
import (
"bufio"
"bytes"
+ "fmt"
+ "net/mail"
"regexp"
"strings"
+ "text/template"
+
+ "github.com/google/syzkaller/pkg/aflow/ai"
)
func ParsePatch(message []byte) (diff string) {
@@ -50,6 +55,47 @@ func ParsePatch(message []byte) (diff string) {
return
}
+func FormatPatchDescription(description string, authors []string, recipients []ai.Recipient) string {
+ buf := new(bytes.Buffer)
+ var to, cc []mail.Address
+ for _, recipient := range recipients {
+ addr := mail.Address{Name: recipient.Name, Address: recipient.Email}
+ if recipient.To {
+ to = append(to, addr)
+ } else {
+ cc = append(cc, addr)
+ }
+ }
+ err := patchTemplate.Execute(buf, map[string]any{
+ "description": strings.TrimSpace(description),
+ "authors": authors,
+ "to": to,
+ "cc": cc,
+ })
+ if err != nil {
+ panic(err)
+ }
+ return buf.String()
+}
+
+func FormatPatch(description, diff, baseCommit string, authors []string, recipients []ai.Recipient) string {
+ return FormatPatchDescription(description, authors, recipients) +
+ fmt.Sprintf("%v\nbase-commit: %v\n", diff, baseCommit)
+}
+
+var patchTemplate = template.Must(template.New("").Parse(`{{.description}}
+{{range $addr := .authors}}
+Signed-off-by: {{$addr}}{{end}}
+{{- range $addr := .to}}
+To: {{$addr.String}}{{end}}
+{{- range $addr := .cc}}
+Cc: {{$addr.String}}{{end}}
+---
+This patch was generated by Google Gemini LLM model.
+It was pre-reviewed and Signed-off-by a human, but please review carefully.
+
+`))
+
var diffRegexps = []*regexp.Regexp{
regexp.MustCompile(`^(---|\+\+\+) [^\s]`),
regexp.MustCompile(`^diff --git`),