mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-24 11:10:39 +00:00
feat: git tag command
This commit is contained in:
parent
a2bb8e0712
commit
013ef66372
@ -83,3 +83,27 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func tagHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnProcessor sv.ReleaseNoteProcessor) func(c *cli.Context) error {
|
||||
return func(c *cli.Context) error {
|
||||
describe := git.Describe()
|
||||
|
||||
currentVer, err := sv.ToVersion(describe)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing version: %s from describe, message: %v", describe, err)
|
||||
}
|
||||
|
||||
commits, err := git.Log(describe)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting git log, message: %v", err)
|
||||
}
|
||||
|
||||
nextVer := semverProcessor.NextVersion(currentVer, commits)
|
||||
fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch())
|
||||
|
||||
if err := git.Tag(nextVer); err != nil {
|
||||
return fmt.Errorf("error generate tag version: %s, message: %v", nextVer.String(), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,12 @@ func main() {
|
||||
Usage: "generate release notes",
|
||||
Action: releaseNotesHandler(git, semverProcessor, releasenotesProcessor),
|
||||
},
|
||||
{
|
||||
Name: "tag",
|
||||
Aliases: []string{"tg"},
|
||||
Usage: "generate tag with version based on git commit messages",
|
||||
Action: tagHandler(git, semverProcessor, releasenotesProcessor),
|
||||
},
|
||||
}
|
||||
|
||||
apperr := app.Run(os.Args)
|
||||
|
11
sv/git.go
11
sv/git.go
@ -73,9 +73,16 @@ func (g GitImpl) Log(lastTag string) ([]GitCommitLog, error) {
|
||||
|
||||
// Tag create a git tag
|
||||
func (g GitImpl) Tag(version semver.Version) error {
|
||||
tag := fmt.Sprintf(g.tagPattern, version.Major(), version.Minor(), version.Patch())
|
||||
tagMsg := fmt.Sprintf("-v \"Version %d.%d.%d\"", version.Major(), version.Minor(), version.Patch())
|
||||
cmd := exec.Command("git", "tag", "-a "+fmt.Sprintf(g.tagPattern, version.Major(), version.Minor(), version.Patch()), tagMsg)
|
||||
return cmd.Run()
|
||||
|
||||
tagCommand := exec.Command("git", "tag", "-a "+tag, tagMsg)
|
||||
if err := tagCommand.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pushCommand := exec.Command("git", "push", "origin", tag)
|
||||
return pushCommand.Run()
|
||||
}
|
||||
|
||||
func parseLogOutput(messageMetadata map[string]string, log string) []GitCommitLog {
|
||||
|
Loading…
Reference in New Issue
Block a user