From 7b35018b9f4a0a69cfd4190875eb55f2338ec56f Mon Sep 17 00:00:00 2001
From: Johan de Klerk <jdeklerk00@gmail.com>
Date: Mon, 8 Nov 2021 10:38:08 +0200
Subject: [PATCH] release notes: git commands

---
 go.mod              |  1 +
 go.sum              |  5 ++++-
 mage_helpers/git.go | 44 +++++++++++++++++++++++++++-----------------
 3 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/go.mod b/go.mod
index 1415e66..b912719 100644
--- a/go.mod
+++ b/go.mod
@@ -8,6 +8,7 @@ require (
 	github.com/aws/aws-sdk-go v1.40.53
 	github.com/docker/docker v20.10.8+incompatible
 	github.com/magefile/mage v1.11.0
+	github.com/rfyiamcool/go-shell v1.0.0
 	github.com/thoas/go-funk v0.9.1
 	gopkg.in/yaml.v2 v2.4.0
 )
diff --git a/go.sum b/go.sum
index 920780a..8bd2565 100644
--- a/go.sum
+++ b/go.sum
@@ -544,6 +544,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
 github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
+github.com/rfyiamcool/go-shell v1.0.0 h1:pbUQWtimUKZUt94XnTU1Rj0QX2Y2QnKUSKsVYBjtPWM=
+github.com/rfyiamcool/go-shell v1.0.0/go.mod h1:bHchDSJTQQnvHlSz12O/40WDsKezUHIKbYDX2g5TgnU=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -956,8 +958,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
+gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
 gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
 gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
diff --git a/mage_helpers/git.go b/mage_helpers/git.go
index 4c57941..91828f9 100644
--- a/mage_helpers/git.go
+++ b/mage_helpers/git.go
@@ -5,6 +5,7 @@ import (
 	"github.com/Masterminds/semver"
 	"os/exec"
 	"strings"
+	"github.com/rfyiamcool/go-shell"
 )
 
 func HasChanges(previousCommit string, folder string) bool {
@@ -45,17 +46,24 @@ func CurrentCommit() string {
 	return string(output)
 }
 
-func CreateReleaseTag() {
+func CommitsFromPreviousTag() string {
+	cmd := shell.NewCommand(`git log "$(git describe --tags --abbrev=0)..HEAD" --pretty=format:"%s"`)
+	err := cmd.Run() // start and wait
+	if err != nil {
+		panic(err)
+	}
+	output := cmd.Status.Output
+	return output
+}
 
+func CreateReleaseTag() string {
 	// Get version and increase version number
 	previousVersion, err := semver.NewVersion(GetLatestGitTag())
 	if err != nil {
 		fmt.Println(err)
 	}
-	fmt.Println(previousVersion)
 
 	newVersion := previousVersion.IncMinor()
-	fmt.Println(newVersion)
 
 	// Create git tag
 	newTagName := newVersion.Original()
@@ -69,19 +77,7 @@ func CreateReleaseTag() {
 		fmt.Println(err)
 	}
 
-	// Push new tag
-	commandArgs = []string{
-		`push`,
-		`origin`,
-		newTagName,
-	}
-	cmd = exec.Command("git", commandArgs...)
-	output, err := cmd.CombinedOutput()
-	if err != nil {
-		fmt.Println(err)
-	}
-	fmt.Println(string(output))
-	return
+	return newTagName
 }
 
 func GetLatestGitTag() string {
@@ -96,6 +92,20 @@ func GetLatestGitTag() string {
 	}
 	tag := string(output)
 	tag = strings.TrimSuffix(tag, "\n")
-	fmt.Println(tag)
 	return tag
 }
+
+func PushTag(tagName string) {
+	commandArgs := []string{
+		`push`,
+		`origin`,
+		tagName,
+	}
+	cmd := exec.Command("git", commandArgs...)
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		fmt.Println(err)
+	}
+	fmt.Println(string(output))
+	return
+}
-- 
GitLab