1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00
gitea/modules/util/commit_trailers.go
2024-10-25 23:34:25 -07:00

31 lines
727 B
Go

// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package util
import (
"errors"
"net/mail"
)
// ParseCommitTrailerValueWithAuthor parses a commit trailer value that contains author data.
// Note that it only parses the value and does not consider the trailer key i.e. we just
// parse something like the following:
//
// Foo Bar <foobar@example.com>
func ParseCommitTrailerValueWithAuthor(value string) (name, email string, err error) {
addr, err := mail.ParseAddress(value)
if err != nil {
return name, email, err
}
if addr.Name == "" {
return name, email, errors.New("commit trailer missing name")
}
name = addr.Name
email = addr.Address
return name, email, nil
}