Skip to content

Commit ef5507f

Browse files
committed
feat: add first commit date with CreateDate
1 parent defec1e commit ef5507f

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

‎gitmap.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type GitInfo struct {
4747
AuthorEmail string `json:"authorEmail"` // The author email address, respecting .mailmap
4848
AuthorDate time.Time `json:"authorDate"` // The author date
4949
CommitDate time.Time `json:"commitDate"` // The commit date
50+
CreateDate time.Time `json:"createDate"` // The create date
5051
Body string `json:"body"` // The commit message body
5152
}
5253

@@ -116,8 +117,10 @@ func Map(opts Options) (*GitRepo, error) {
116117
if filename == "" {
117118
continue
118119
}
119-
if _, ok := m[filename]; !ok {
120+
if originGi, ok := m[filename]; !ok {
120121
m[filename] = gitInfo
122+
} else {
123+
originGi.CreateDate = gitInfo.AuthorDate
121124
}
122125
}
123126
}
@@ -166,6 +169,7 @@ func toGitInfo(entry string) (*GitInfo, error) {
166169
AuthorEmail: items[4],
167170
AuthorDate: authorDate,
168171
CommitDate: commitDate,
172+
CreateDate: authorDate,
169173
Body: strings.TrimSpace(items[7]),
170174
}, nil
171175
}

‎gitmap_test.go‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ package gitmap
77

88
import (
99
"encoding/json"
10+
"fmt"
1011
"os"
1112
"strings"
1213
"testing"
1314
)
1415

1516
var (
16-
revision = "7d46b653c9674510d808815c4c92c7dc10bedc16"
17+
revision = "acfc087e68546b364b1ae82f8847566a486c19a2"
1718
repository string
1819
)
1920

@@ -22,6 +23,36 @@ func init() {
2223
if repository, err = os.Getwd(); err != nil {
2324
panic(err)
2425
}
26+
27+
repository = "/Users/stevenobelia/Desktop/_scratch/clean/archive/docs"
28+
}
29+
30+
func TestDocs(t *testing.T) {
31+
var (
32+
gm GitMap
33+
gr *GitRepo
34+
err error
35+
gi *GitInfo
36+
ok bool
37+
)
38+
39+
if gr, err = Map(Options{Repository: repository, Revision: revision}); err != nil {
40+
t.Fatal(err)
41+
}
42+
43+
gm = gr.Files
44+
45+
if gi, ok = gm["README.md"]; !ok {
46+
t.Fatal("filename")
47+
}
48+
49+
jsonBytes, err := json.Marshal(gi)
50+
if err != nil {
51+
fmt.Println("Error marshaling:", err)
52+
return
53+
}
54+
jsonStr := string(jsonBytes)
55+
fmt.Println(jsonStr)
2556
}
2657

2758
func TestMap(t *testing.T) {

0 commit comments

Comments
 (0)