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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
diff --git a/internal/git/repo.go b/internal/git/repo.go
index 67af17c205c3d6e21f9eae4517d17fa0bb3bb1cb..3272919e8a44c2e347f8910f9cced2b6fbefb409 100644
--- a/internal/git/repo.go
+++ b/internal/git/repo.go
@@ -15,15 +15,18 @@ "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
)
+// Repo is a git repository
type Repo struct {
path string
Meta RepoMeta
}
+// Name returns the human-friendly name, the dir name without the .git suffix
func (r Repo) Name() string {
return strings.TrimSuffix(filepath.Base(r.path), ".git")
}
+// NewRepo constructs a Repo given a dir and name
func NewRepo(dir, name string) (*Repo, error) {
if !strings.HasSuffix(name, ".git") {
name += ".git"
@@ -98,6 +101,7 @@ Signature string
Author string
Email string
When time.Time
+
// Extra
Stats CommitStats
Patch string
@@ -125,19 +129,22 @@ Path string
Commit string
}
+// Short returns the first eight characters of the SHA
func (c Commit) Short() string {
return c.SHA[:8]
}
+// Summary returns the first line of the commit, suitable for a <summary>
func (c Commit) Summary() string {
return strings.Split(c.Message, "\n")[0]
}
+// Details returns all lines *after* the first, suitable for <details>
func (c Commit) Details() string {
return strings.Join(strings.Split(c.Message, "\n")[1:], "\n")
}
-// Commit gets a specific commit by SHA
+// Commit gets a specific commit by SHA, including all commit information
func (r Repo) Commit(sha string) (Commit, error) {
repo, err := r.Git()
if err != nil {
@@ -147,7 +154,7 @@
return commit(repo, sha, true)
}
-// LastCommit returns the last commit of the repo
+// LastCommit returns the last commit of the repo without any extra information
func (r Repo) LastCommit() (Commit, error) {
repo, err := r.Git()
if err != nil {
@@ -313,15 +320,8 @@
var tags []Tag
if err := tgs.ForEach(func(tag *plumbing.Reference) error {
obj, err := repo.TagObject(tag.Hash())
- switch err {
- case nil:
- tags = append(tags, Tag{
- Name: obj.Name,
- Annotation: obj.Message,
- Signature: obj.PGPSignature,
- When: obj.Tagger.When,
- })
- case plumbing.ErrObjectNotFound:
+ switch {
+ case errors.Is(err, plumbing.ErrObjectNotFound):
commit, err := repo.CommitObject(tag.Hash())
if err != nil {
return err
@@ -331,6 +331,13 @@ Name: tag.Name().Short(),
Annotation: commit.Message,
Signature: commit.PGPSignature,
When: commit.Author.When,
+ })
+ case err == nil:
+ tags = append(tags, Tag{
+ Name: obj.Name,
+ Annotation: obj.Message,
+ Signature: obj.PGPSignature,
+ When: obj.Tagger.When,
})
default:
return err
|