]> Sergey Matveev's repositories - sgblog.git/commitdiff
Find any kind of commit hash in email subject
authorSergey Matveev <stargrave@stargrave.org>
Thu, 24 Sep 2020 19:08:04 +0000 (22:08 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 25 Sep 2020 08:58:56 +0000 (11:58 +0300)
cmd/sgblog-comment-add/main.go

index 837666c3b8dd12a1f71b713dbefbc36c29666da4..cb270afee87d1789f2da06218ee46d4108c8976c 100644 (file)
@@ -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)
        }