-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignature.go
61 lines (51 loc) · 1.58 KB
/
signature.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gogit
import (
"fmt"
"time"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/yyle88/eroticgo"
"github.com/yyle88/tern/zerotern"
"github.com/yyle88/zaplog"
)
const packageName = "gogit"
const packagePath = "github.com/go-xlan/gogit"
type CommitInfo struct {
Name string
Eddress string
Message string
}
// NewCommitInfo creates a new CommitInfo instance with default values.
func NewCommitInfo(message string) *CommitInfo {
return &CommitInfo{
Message: message,
}
}
// WithName sets the Name field of the CommitInfo and returns the updated instance.
func (c *CommitInfo) WithName(name string) *CommitInfo {
c.Name = name
return c
}
// WithEddress sets the Eddress field of the CommitInfo and returns the updated instance.
func (c *CommitInfo) WithEddress(eddress string) *CommitInfo {
c.Eddress = eddress
return c
}
// WithMessage sets the Message field of the CommitInfo and returns the updated instance.
func (c *CommitInfo) WithMessage(message string) *CommitInfo {
c.Message = message
return c
}
func (c *CommitInfo) GetCommitMessage() string {
return zerotern.VF(c.Message, func() string {
message := fmt.Sprintf(`git commit -m "[%s](%s) %s"`, packageName, packagePath, time.Now().Format("2006-01-02 15:04:05"))
zaplog.SUG.Debugln(eroticgo.BLUE.Sprint(fmt.Sprintf(`git commit -m "%s"`, message)))
return message
})
}
func (c *CommitInfo) GetObjectSignature() *object.Signature {
return &object.Signature{
Name: zerotern.VV(c.Name, packageName),
Email: zerotern.VV(c.Eddress, fmt.Sprintf("%s@%s", packageName, packagePath)),
When: time.Now(),
}
}