cmd/sgblog-comment-add/main.go | 8 +++++++- diff --git a/cmd/sgblog-comment-add/main.go b/cmd/sgblog-comment-add/main.go index 97408a467ebee8f6aa9a309f4c610a69599e5f99265acaf6898a644851ad66eb..e4a088eb492e9bf94acc1a299c95b5b59a11bee5e2917183d55f79ace9250a39 100644 --- a/cmd/sgblog-comment-add/main.go +++ b/cmd/sgblog-comment-add/main.go @@ -30,6 +30,7 @@ "mime" "net/mail" "os" "os/exec" + "regexp" "strconv" "strings" "syscall" @@ -38,6 +39,8 @@ "go.cypherpunks.ru/netstring/v2" "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 @@ -116,7 +119,10 @@ if err != nil { 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) }