mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-07-02 03:25:45 +00:00
Fix debug output for logging.
This commit is contained in:
+31
-28
@@ -32,7 +32,7 @@ import (
|
|||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||||
libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging"
|
libpack_logging "github.com/lukaszraczylo/graphql-monitoring-proxy/logging"
|
||||||
"github.com/lukaszraczylo/pandati"
|
"github.com/lukaszraczylo/pandati"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@@ -41,7 +41,7 @@ var (
|
|||||||
err error
|
err error
|
||||||
repo *Setup
|
repo *Setup
|
||||||
PKG_VERSION string
|
PKG_VERSION string
|
||||||
logger *libpack_logger.Logger
|
logger *libpack_logging.Logger
|
||||||
)
|
)
|
||||||
|
|
||||||
type Wording struct {
|
type Wording struct {
|
||||||
@@ -105,7 +105,7 @@ func checkMatches(content []string, targets []string) bool {
|
|||||||
r := fuzzy.FindNormalizedFold(tgt, content)
|
r := fuzzy.FindNormalizedFold(tgt, content)
|
||||||
if len(r) > 0 {
|
if len(r) > 0 {
|
||||||
hasMatch = true
|
hasMatch = true
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Found match",
|
Message: "Found match",
|
||||||
Pairs: map[string]interface{}{"target": tgt, "match": strings.Join(r, ","), "content": contentStr},
|
Pairs: map[string]interface{}{"target": tgt, "match": strings.Join(r, ","), "content": contentStr},
|
||||||
})
|
})
|
||||||
@@ -117,7 +117,7 @@ func checkMatches(content []string, targets []string) bool {
|
|||||||
if hasMatch {
|
if hasMatch {
|
||||||
for _, blacklistTerm := range repo.Blacklist {
|
for _, blacklistTerm := range repo.Blacklist {
|
||||||
if strings.Contains(strings.ToLower(contentStr), strings.ToLower(blacklistTerm)) {
|
if strings.Contains(strings.ToLower(contentStr), strings.ToLower(blacklistTerm)) {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Blacklisted term detected, ignoring commit",
|
Message: "Blacklisted term detected, ignoring commit",
|
||||||
Pairs: map[string]interface{}{"content": contentStr, "blacklist_term": blacklistTerm},
|
Pairs: map[string]interface{}{"content": contentStr, "blacklist_term": blacklistTerm},
|
||||||
})
|
})
|
||||||
@@ -132,13 +132,13 @@ func checkMatches(content []string, targets []string) bool {
|
|||||||
var extractNumber = regexp.MustCompile("[0-9]+")
|
var extractNumber = regexp.MustCompile("[0-9]+")
|
||||||
|
|
||||||
func parseExistingSemver(tagName string, currentSemver SemVer) (semanticVersion SemVer) {
|
func parseExistingSemver(tagName string, currentSemver SemVer) (semanticVersion SemVer) {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Parsing existing semver",
|
Message: "Parsing existing semver",
|
||||||
Pairs: map[string]interface{}{"tag": tagName},
|
Pairs: map[string]interface{}{"tag": tagName},
|
||||||
})
|
})
|
||||||
tagNameParts := strings.Split(tagName, ".")
|
tagNameParts := strings.Split(tagName, ".")
|
||||||
if len(tagNameParts) < 3 {
|
if len(tagNameParts) < 3 {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Unable to parse incompatible semver ( non x.y.z )",
|
Message: "Unable to parse incompatible semver ( non x.y.z )",
|
||||||
Pairs: map[string]interface{}{"tag": tagName},
|
Pairs: map[string]interface{}{"tag": tagName},
|
||||||
})
|
})
|
||||||
@@ -159,7 +159,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
if params.varExisting || s.Force.Existing {
|
if params.varExisting || s.Force.Existing {
|
||||||
for _, tagHash := range s.Tags {
|
for _, tagHash := range s.Tags {
|
||||||
if commit.Hash == tagHash.Hash {
|
if commit.Hash == tagHash.Hash {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Found existing tag",
|
Message: "Found existing tag",
|
||||||
Pairs: map[string]interface{}{"tag": tagHash.Name, "commit": strings.TrimSuffix(commit.Message, "\n")},
|
Pairs: map[string]interface{}{"tag": tagHash.Name, "commit": strings.TrimSuffix(commit.Message, "\n")},
|
||||||
})
|
})
|
||||||
@@ -171,7 +171,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
|
|
||||||
if !params.varStrict && !s.Force.Strict {
|
if !params.varStrict && !s.Force.Strict {
|
||||||
s.Semver.Patch++
|
s.Semver.Patch++
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Incrementing patch (DEFAULT)",
|
Message: "Incrementing patch (DEFAULT)",
|
||||||
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
||||||
})
|
})
|
||||||
@@ -187,7 +187,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
s.Semver.Patch = 1
|
s.Semver.Patch = 1
|
||||||
s.Semver.EnableReleaseCandidate = false
|
s.Semver.EnableReleaseCandidate = false
|
||||||
s.Semver.Release = 0
|
s.Semver.Release = 0
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Incrementing major (WORDING)",
|
Message: "Incrementing major (WORDING)",
|
||||||
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
||||||
})
|
})
|
||||||
@@ -198,7 +198,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
s.Semver.Patch = 1
|
s.Semver.Patch = 1
|
||||||
s.Semver.EnableReleaseCandidate = false
|
s.Semver.EnableReleaseCandidate = false
|
||||||
s.Semver.Release = 0
|
s.Semver.Release = 0
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Incrementing minor (WORDING)",
|
Message: "Incrementing minor (WORDING)",
|
||||||
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
||||||
})
|
})
|
||||||
@@ -208,7 +208,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
s.Semver.Release++
|
s.Semver.Release++
|
||||||
s.Semver.Patch = 1
|
s.Semver.Patch = 1
|
||||||
s.Semver.EnableReleaseCandidate = true
|
s.Semver.EnableReleaseCandidate = true
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Incrementing release candidate (WORDING)",
|
Message: "Incrementing release candidate (WORDING)",
|
||||||
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
||||||
})
|
})
|
||||||
@@ -216,7 +216,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
}
|
}
|
||||||
if matchPatch {
|
if matchPatch {
|
||||||
s.Semver.Patch++
|
s.Semver.Patch++
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Incrementing patch (WORDING)",
|
Message: "Incrementing patch (WORDING)",
|
||||||
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
Pairs: map[string]interface{}{"commit": strings.TrimSuffix(commit.Message, "\n"), "semver": s.getSemver()},
|
||||||
})
|
})
|
||||||
@@ -227,7 +227,7 @@ func (s *Setup) CalculateSemver() SemVer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Setup) ListExistingTags() {
|
func (s *Setup) ListExistingTags() {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Listing existing tags",
|
Message: "Listing existing tags",
|
||||||
})
|
})
|
||||||
refs, err := s.RepositoryHandler.Tags()
|
refs, err := s.RepositoryHandler.Tags()
|
||||||
@@ -236,7 +236,7 @@ func (s *Setup) ListExistingTags() {
|
|||||||
}
|
}
|
||||||
if err := refs.ForEach(func(ref *plumbing.Reference) error {
|
if err := refs.ForEach(func(ref *plumbing.Reference) error {
|
||||||
s.Tags = append(s.Tags, TagDetails{Name: ref.Name().Short(), Hash: ref.Hash().String()})
|
s.Tags = append(s.Tags, TagDetails{Name: ref.Name().Short(), Hash: ref.Hash().String()})
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Found tag",
|
Message: "Found tag",
|
||||||
Pairs: map[string]interface{}{"tag": ref.Name().Short(), "hash": ref.Hash().String()},
|
Pairs: map[string]interface{}{"tag": ref.Name().Short(), "hash": ref.Hash().String()},
|
||||||
})
|
})
|
||||||
@@ -266,13 +266,13 @@ func (s *Setup) ListCommits() ([]CommitDetails, error) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Listing commits",
|
Message: "Listing commits",
|
||||||
Pairs: map[string]interface{}{"commits": tmpResults},
|
Pairs: map[string]interface{}{"commits": tmpResults},
|
||||||
})
|
})
|
||||||
for commitId, cmt := range tmpResults {
|
for commitId, cmt := range tmpResults {
|
||||||
if s.Force.Commit != "" && cmt.Hash == s.Force.Commit {
|
if s.Force.Commit != "" && cmt.Hash == s.Force.Commit {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Found commit match",
|
Message: "Found commit match",
|
||||||
Pairs: map[string]interface{}{"commit": cmt.Hash, "index": commitId},
|
Pairs: map[string]interface{}{"commit": cmt.Hash, "index": commitId},
|
||||||
})
|
})
|
||||||
@@ -283,7 +283,7 @@ func (s *Setup) ListCommits() ([]CommitDetails, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Commits after cut",
|
Message: "Commits after cut",
|
||||||
Pairs: map[string]interface{}{"commits": s.Commits},
|
Pairs: map[string]interface{}{"commits": s.Commits},
|
||||||
})
|
})
|
||||||
@@ -294,7 +294,7 @@ func (s *Setup) Prepare() error {
|
|||||||
if !repo.UseLocal {
|
if !repo.UseLocal {
|
||||||
u, err := url.Parse(s.RepositoryName)
|
u, err := url.Parse(s.RepositoryName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(&libpack_logger.LogMessage{
|
logger.Error(&libpack_logging.LogMessage{
|
||||||
Message: "Unable to parse repository URL",
|
Message: "Unable to parse repository URL",
|
||||||
Pairs: map[string]interface{}{"error": err.Error(), "url": s.RepositoryName},
|
Pairs: map[string]interface{}{"error": err.Error(), "url": s.RepositoryName},
|
||||||
})
|
})
|
||||||
@@ -313,7 +313,7 @@ func (s *Setup) Prepare() error {
|
|||||||
Tags: git.AllTags,
|
Tags: git.AllTags,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(&libpack_logger.LogMessage{
|
logger.Error(&libpack_logging.LogMessage{
|
||||||
Message: "Unable to clone repository",
|
Message: "Unable to clone repository",
|
||||||
Pairs: map[string]interface{}{"error": err.Error(), "url": s.RepositoryName},
|
Pairs: map[string]interface{}{"error": err.Error(), "url": s.RepositoryName},
|
||||||
})
|
})
|
||||||
@@ -323,7 +323,7 @@ func (s *Setup) Prepare() error {
|
|||||||
s.RepositoryLocalPath = "./"
|
s.RepositoryLocalPath = "./"
|
||||||
s.RepositoryHandler, err = git.PlainOpen(s.RepositoryLocalPath)
|
s.RepositoryHandler, err = git.PlainOpen(s.RepositoryLocalPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(&libpack_logger.LogMessage{
|
logger.Error(&libpack_logging.LogMessage{
|
||||||
Message: "Unable to open local repository",
|
Message: "Unable to open local repository",
|
||||||
Pairs: map[string]interface{}{"error": err.Error(), "path": s.RepositoryLocalPath},
|
Pairs: map[string]interface{}{"error": err.Error(), "path": s.RepositoryLocalPath},
|
||||||
})
|
})
|
||||||
@@ -336,21 +336,21 @@ func (s *Setup) Prepare() error {
|
|||||||
|
|
||||||
func (s *Setup) ForcedVersioning() {
|
func (s *Setup) ForcedVersioning() {
|
||||||
if !pandati.IsZero(s.Force.Major) {
|
if !pandati.IsZero(s.Force.Major) {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Forced versioning (MAJOR)",
|
Message: "Forced versioning (MAJOR)",
|
||||||
Pairs: map[string]interface{}{"major": s.Force.Major},
|
Pairs: map[string]interface{}{"major": s.Force.Major},
|
||||||
})
|
})
|
||||||
s.Semver.Major = s.Force.Major
|
s.Semver.Major = s.Force.Major
|
||||||
}
|
}
|
||||||
if !pandati.IsZero(s.Force.Minor) {
|
if !pandati.IsZero(s.Force.Minor) {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Forced versioning (MINOR)",
|
Message: "Forced versioning (MINOR)",
|
||||||
Pairs: map[string]interface{}{"minor": s.Force.Minor},
|
Pairs: map[string]interface{}{"minor": s.Force.Minor},
|
||||||
})
|
})
|
||||||
s.Semver.Minor = s.Force.Minor
|
s.Semver.Minor = s.Force.Minor
|
||||||
}
|
}
|
||||||
if !pandati.IsZero(s.Force.Patch) {
|
if !pandati.IsZero(s.Force.Patch) {
|
||||||
logger.Debug(&libpack_logger.LogMessage{
|
logger.Debug(&libpack_logging.LogMessage{
|
||||||
Message: "Forced versioning (PATCH)",
|
Message: "Forced versioning (PATCH)",
|
||||||
Pairs: map[string]interface{}{"patch": s.Force.Minor},
|
Pairs: map[string]interface{}{"patch": s.Force.Minor},
|
||||||
})
|
})
|
||||||
@@ -380,19 +380,22 @@ func (s *Setup) getSemver() (semverReturned string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
logger = libpack_logger.New()
|
logger = libpack_logging.New()
|
||||||
|
if params.varDebug {
|
||||||
|
logger.SetOutput(os.Stdout).SetMinLogLevel(libpack_logging.LEVEL_DEBUG)
|
||||||
|
}
|
||||||
if params.varShowVersion {
|
if params.varShowVersion {
|
||||||
var outdatedMsg string
|
var outdatedMsg string
|
||||||
latestRelease, latestRelaseOk := checkLatestRelease()
|
latestRelease, latestRelaseOk := checkLatestRelease()
|
||||||
if PKG_VERSION != latestRelease && latestRelaseOk {
|
if PKG_VERSION != latestRelease && latestRelaseOk {
|
||||||
outdatedMsg = fmt.Sprintf("(Latest available: %s)", latestRelease)
|
outdatedMsg = fmt.Sprintf("(Latest available: %s)", latestRelease)
|
||||||
}
|
}
|
||||||
logger.Info(&libpack_logger.LogMessage{
|
logger.Info(&libpack_logging.LogMessage{
|
||||||
Message: "semver-gen",
|
Message: "semver-gen",
|
||||||
Pairs: map[string]interface{}{"version": PKG_VERSION, "outdated": outdatedMsg},
|
Pairs: map[string]interface{}{"version": PKG_VERSION, "outdated": outdatedMsg},
|
||||||
})
|
})
|
||||||
if outdatedMsg != "" {
|
if outdatedMsg != "" {
|
||||||
logger.Info(&libpack_logger.LogMessage{
|
logger.Info(&libpack_logging.LogMessage{
|
||||||
Message: "semver-gen",
|
Message: "semver-gen",
|
||||||
Pairs: map[string]interface{}{"message": "You can update automatically with: semver-gen -u"},
|
Pairs: map[string]interface{}{"message": "You can update automatically with: semver-gen -u"},
|
||||||
})
|
})
|
||||||
@@ -406,14 +409,14 @@ func main() {
|
|||||||
if repo.Generate || params.varGenerateInTest {
|
if repo.Generate || params.varGenerateInTest {
|
||||||
err := repo.ReadConfig(repo.LocalConfigFile)
|
err := repo.ReadConfig(repo.LocalConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(&libpack_logger.LogMessage{
|
logger.Error(&libpack_logging.LogMessage{
|
||||||
Message: "Unable to find config file semver.yaml. Using defaults and flags.",
|
Message: "Unable to find config file semver.yaml. Using defaults and flags.",
|
||||||
Pairs: map[string]interface{}{"file": repo.LocalConfigFile},
|
Pairs: map[string]interface{}{"file": repo.LocalConfigFile},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
err = repo.Prepare()
|
err = repo.Prepare()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Critical(&libpack_logger.LogMessage{
|
logger.Critical(&libpack_logging.LogMessage{
|
||||||
Message: "Unable to prepare repository",
|
Message: "Unable to prepare repository",
|
||||||
Pairs: map[string]interface{}{"error": err.Error()},
|
Pairs: map[string]interface{}{"error": err.Error()},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user