From e7e77af7128668262e24076741b72695f22c5236 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 24 Sep 2020 22:08:04 +0300 Subject: [PATCH] Find any kind of commit hash in email subject --- cmd/sgblog-comment-add/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/sgblog-comment-add/main.go b/cmd/sgblog-comment-add/main.go index 837666c..cb270af 100644 --- a/cmd/sgblog-comment-add/main.go +++ b/cmd/sgblog-comment-add/main.go @@ -30,6 +30,7 @@ import ( "net/mail" "os" "os/exec" + "regexp" "strconv" "strings" "syscall" @@ -39,6 +40,8 @@ import ( "go.stargrave.org/sgblog" ) +var hashFinder = regexp.MustCompile("([0-9a-f]{40})") + // Remove various whitespaces and excess lines, because git-notes-add // will remove and we have to know exact bytes count func cleanupBody(body string) string { @@ -116,7 +119,10 @@ func main() { log.Fatal(err) } - subj = strings.TrimPrefix(subj, "Re: ") + subj = hashFinder.FindString(subj) + if subj == "" { + log.Fatal("no commit hash found in subject") + } if h, err := hex.DecodeString(subj); err != nil || len(h) != sha1.Size { os.Exit(0) } -- 2.44.0