From: Sergey Matveev Date: Thu, 24 Sep 2020 19:08:04 +0000 (+0300) Subject: Find any kind of commit hash in email subject X-Git-Tag: v0.8.0~2 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e7e77af7128668262e24076741b72695f22c5236;p=sgblog.git Find any kind of commit hash in email subject --- 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) }