Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).

types: add utility to extract co-authors from a commit

uses a regex to detect & extract a object.Signature from the
Co-authored-by header.

Signed-off-by: oppiliappan <me@oppi.li>

authored by oppi.li and committed by

Tangled c811f6ca b26a5eca

+26
+26
types/commit.go
··· 5 5 "encoding/json" 6 6 "fmt" 7 7 "maps" 8 + "regexp" 8 9 "strings" 9 10 10 11 "github.com/go-git/go-git/v5/plumbing" ··· 166 165 fmt.Fprintf(&payload, "\n%s", c.Message) 167 166 168 167 return payload.String() 168 + } 169 + 170 + var ( 171 + coAuthorRegex = regexp.MustCompile(`(?im)^Co-authored-by:\s*(.+?)\s*<([^>]+)>`) 172 + ) 173 + 174 + func (commit *Commit) CoAuthors() []object.Signature { 175 + var coAuthors []object.Signature 176 + 177 + matches := coAuthorRegex.FindAllStringSubmatch(commit.Message, -1) 178 + 179 + for _, match := range matches { 180 + if len(match) >= 3 { 181 + name := strings.TrimSpace(match[1]) 182 + email := strings.TrimSpace(match[2]) 183 + 184 + coAuthors = append(coAuthors, object.Signature{ 185 + Name: name, 186 + Email: email, 187 + When: commit.Committer.When, 188 + }) 189 + } 190 + } 191 + 192 + return coAuthors 169 193 }