Monorepo for Tangled tangled.org

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

Changed files
+26
types
+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 167 167 168 return payload.String() 168 169 } 170 + 171 + var ( 172 + coAuthorRegex = regexp.MustCompile(`(?im)^Co-authored-by:\s*(.+?)\s*<([^>]+)>`) 173 + ) 174 + 175 + func (commit *Commit) CoAuthors() []object.Signature { 176 + var coAuthors []object.Signature 177 + 178 + matches := coAuthorRegex.FindAllStringSubmatch(commit.Message, -1) 179 + 180 + for _, match := range matches { 181 + if len(match) >= 3 { 182 + name := strings.TrimSpace(match[1]) 183 + email := strings.TrimSpace(match[2]) 184 + 185 + coAuthors = append(coAuthors, object.Signature{ 186 + Name: name, 187 + Email: email, 188 + When: commit.Committer.When, 189 + }) 190 + } 191 + } 192 + 193 + return coAuthors 194 + }