-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgitmono.go
117 lines (99 loc) · 3.3 KB
/
gitmono.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package gitmono
import (
"fmt"
"github.com/gogs/git-module"
"github.com/hashicorp/go-version"
)
// EnvVars contains the accepted environment variables
type EnvVars struct {
CommitterName string
CommitterEmail string
GitRepoPath string
}
// Config defines generic configuration applying to multiple commands
type Config struct {
DryRun bool
CommitScheme string
VersionPrefix string
Project string
}
// Logger performs log commands on the repo
//
// Log returns the commits for the specified reference range in reverse chronological order
// CommitHashByRevision returns the commit hash matching to a revision
type Logger interface {
Log(from, to string) ([]*git.Commit, error)
CommitHashByRevision(rev string) (string, error)
}
// Tagger performs tag commands on the repo
//
// CreateTag writes the given tag to the given commit
// ListProjectVersionTags retrieves all tags for a project using the tag list pattern
type Tagger interface {
CreateTag(versionedCommit *VersionedCommit) error
ListProjectVersionTags() ([]string, error)
}
// Versioner maintains version using tags
//
// GetCurrentVersion retrieves the latest version
// ReleaseNewVersion creates and persists a new version
// InitVersion creates and persists the initial version
type Versioner interface {
GetCurrentVersion() (*VersionedCommit, error)
ReleaseNewVersion(commitID string) (*VersionedCommit, error)
InitVersion(commitID string) (*VersionedCommit, error)
}
// Differ performs diff on the repo
//
// Diff two git references and retuns a list of modified files
type Differ interface {
Diff(from, to string) ([]string, error)
}
// CommitParser parses the provided commit
//
// GetBumperFromCommit parses a commit message and decide the bumper to use for version
type CommitParser interface {
GetBumperFromCommit(*git.Commit) Bumper
}
// Bumper bumps a version to a new version
//
// Bump calculates a new version by incrementing (bumping) a version
type Bumper interface {
Bump(*version.Version) (*version.Version, error)
}
// VersionedCommit points a commit that is assigned a version
type VersionedCommit struct {
CommitID string
Project string
VersionPrefix string
Version *version.Version
}
// GetProjectTagPrefix calculates the project tag prefix for the specified project value
func GetProjectTagPrefix(project string) string {
if project == "." {
return ""
}
return fmt.Sprintf("%s/", project)
}
// GetTag returns the tag to version a commit with
func (vc *VersionedCommit) GetTag() string {
return fmt.Sprintf("%s%s", GetProjectTagPrefix(vc.Project), vc.GetVersion())
}
// GetVersion returns the version part of the tag
func (vc *VersionedCommit) GetVersion() string {
return fmt.Sprintf("%s%s", vc.VersionPrefix, vc.Version.String())
}
// GitTagger abstracts git tag operations
type GitTagger interface {
Tags(opts ...git.TagsOptions) ([]string, error)
CreateTag(name, rev string, opts ...git.CreateTagOptions) error
}
// GitLogger abstracts git log operations
type GitLogger interface {
Log(rev string, opts ...git.LogOptions) ([]*git.Commit, error)
CommitByRevision(rev string, opts ...git.CommitByRevisionOptions) (*git.Commit, error)
}
// GitDiffer abstracts git diff operations
type GitDiffer interface {
Diff(rev string, maxFiles, maxFileLines, maxLineChars int, opts ...git.DiffOptions) (*git.Diff, error)
}