0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-24 21:20:40 +00:00

feat: git tag command

This commit is contained in:
Beatriz Vieira 2019-12-04 19:37:50 -03:00
parent a2bb8e0712
commit 013ef66372
3 changed files with 39 additions and 2 deletions

View File

@ -83,3 +83,27 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
return nil 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
}
}

View File

@ -43,6 +43,12 @@ func main() {
Usage: "generate release notes", Usage: "generate release notes",
Action: releaseNotesHandler(git, semverProcessor, releasenotesProcessor), 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) apperr := app.Run(os.Args)

View File

@ -73,9 +73,16 @@ func (g GitImpl) Log(lastTag string) ([]GitCommitLog, error) {
// Tag create a git tag // Tag create a git tag
func (g GitImpl) Tag(version semver.Version) error { 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()) 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 { func parseLogOutput(messageMetadata map[string]string, log string) []GitCommitLog {