From 98f6c31e9d5fc1575fd3669866cbaafbf9a377ce Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Fri, 28 Feb 2025 18:10:56 +0000 Subject: [PATCH] fixup! Update documentation. --- cmd/main.go | 25 +++++++++-------- cmd/main_test.go | 20 +++++++------- cmd/root_test.go | 6 ++--- cmd/utils/config.go | 12 ++++----- cmd/utils/config_test.go | 2 +- cmd/utils/git.go | 56 +++++++++++++++++++-------------------- cmd/utils/git_test.go | 26 +++++++++--------- cmd/utils/github.go | 38 +++++++++++++------------- cmd/utils/github_test.go | 2 +- cmd/utils/logging.go | 2 +- cmd/utils/logging_test.go | 17 ++++++------ cmd/utils/semver.go | 22 +++++++-------- cmd/utils/semver_test.go | 22 +++++++-------- cmd/utils/version.go | 26 +++++++++--------- cmd/utils/version_test.go | 20 +++++++------- main_test.go | 2 +- 16 files changed, 149 insertions(+), 149 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index f3a5f08..fa3fb73 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -26,27 +26,26 @@ import ( ) var ( - err error repo *Setup PKG_VERSION string ) // Setup represents the application setup type Setup struct { - RepositoryName string - RepositoryBranch string - LocalConfigFile string - Generate bool - UseLocal bool - GitRepo utils.GitRepository - Config *utils.Config - Semver utils.SemVer + RepositoryName string + RepositoryBranch string + LocalConfigFile string + Generate bool + UseLocal bool + GitRepo utils.GitRepository + Config *utils.Config + Semver utils.SemVer } // Initialize the fuzzy search function in the utils package func init() { utils.InitLogger(false) // Will be updated in main based on debug flag - + // Set the fuzzy search function utils.FuzzyFind = fuzzy.FindNormalizedFold } @@ -72,12 +71,12 @@ func main() { if PKG_VERSION != latestRelease && latestReleaseOk { outdatedMsg = fmt.Sprintf("(Latest available: %s)", latestRelease) } - + utils.Info("semver-gen", map[string]interface{}{ - "version": PKG_VERSION, + "version": PKG_VERSION, "outdated": outdatedMsg, }) - + if outdatedMsg != "" { utils.Info("semver-gen", map[string]interface{}{ "message": "You can update automatically with: semver-gen -u", diff --git a/cmd/main_test.go b/cmd/main_test.go index 4a80c77..49639d0 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -267,7 +267,7 @@ func (suite *Tests) Test_checkMatches() { if tt.name == "No match" { return nil } - + // For other test cases, match if the needle is in the haystack for _, h := range haystack { if strings.Contains(h, needle) || strings.Contains(needle, h) { @@ -276,7 +276,7 @@ func (suite *Tests) Test_checkMatches() { } return nil } - + got := utils.CheckMatches(tt.args.content, tt.args.targets, tt.blacklist) assertObj.Equal(tt.want, got, "Unexpected result in "+tt.name) }) @@ -382,10 +382,10 @@ func (suite *Tests) Test_parseExistingSemver() { func (suite *Tests) TestSetup_ListCommits() { type fields struct { - RepositoryName string - RepositoryBranch string - LocalConfigFile string - GitRepo utils.GitRepository + RepositoryName string + RepositoryBranch string + LocalConfigFile string + GitRepo utils.GitRepository } tests := []struct { @@ -441,23 +441,23 @@ func (suite *Tests) TestSetup_ListCommits() { if tt.name == "List commits from existing repository" { t.Skip("Skipping test that requires repository access") } - + s := &Setup{ RepositoryName: tt.fields.RepositoryName, RepositoryBranch: tt.fields.RepositoryBranch, GitRepo: tt.fields.GitRepo, } - + config, _ := utils.ReadConfig(tt.fields.LocalConfigFile) s.Config = config - + err := utils.PrepareRepository(&s.GitRepo) if err != nil && !tt.wantErr { if tt.name != "List commits starting with certain hash" { t.Fatalf("Failed to prepare repository: %v", err) } } - + if err == nil { listOfCommits, err := utils.ListCommits(&s.GitRepo) if !tt.wantErr { diff --git a/cmd/root_test.go b/cmd/root_test.go index cabdac7..acb34df 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -30,13 +30,13 @@ func TestExecute(t *testing.T) { Short: "Test command", Run: func(cmd *cobra.Command, args []string) {}, } - + // Add all the required flags to the test command testCmd.Flags().Bool("version", false, "Print version information") testCmd.Flags().String("repository", "test-repo", "Repository URL") testCmd.Flags().String("branch", "test-branch", "Repository branch") testCmd.Flags().String("config", "test-config", "Config file path") - + rootCmd = testCmd // Execute should not panic @@ -82,4 +82,4 @@ func TestSetupCobra(t *testing.T) { assertions.Equal(t, "test-branch", testRepo.RepositoryBranch, "Repository branch should be set") assertions.Equal(t, "test-config", testRepo.LocalConfigFile, "Config file should be set") assertions.True(t, testRepo.UseLocal, "UseLocal should be set to true") -} \ No newline at end of file +} diff --git a/cmd/utils/config.go b/cmd/utils/config.go index e46948b..c0ae867 100644 --- a/cmd/utils/config.go +++ b/cmd/utils/config.go @@ -34,18 +34,18 @@ type Config struct { // ReadConfig reads the configuration from a file func ReadConfig(file string) (*Config, error) { config := &Config{} - + viper.SetConfigFile(file) err := viper.ReadInConfig() if err != nil { err = fmt.Errorf("fatal error config file: %s", err) return config, err } - + viper.UnmarshalKey("wording", &config.Wording) viper.UnmarshalKey("force", &config.Force) viper.UnmarshalKey("blacklist", &config.Blacklist) - + return config, nil } @@ -55,14 +55,14 @@ func ApplyForcedVersioning(force Force, semver *SemVer) { Debug("Forced versioning (MAJOR)", map[string]interface{}{"major": force.Major}) semver.Major = force.Major } - + if force.Minor > 0 { Debug("Forced versioning (MINOR)", map[string]interface{}{"minor": force.Minor}) semver.Minor = force.Minor } - + if force.Patch > 0 { Debug("Forced versioning (PATCH)", map[string]interface{}{"patch": force.Patch}) semver.Patch = force.Patch } -} \ No newline at end of file +} diff --git a/cmd/utils/config_test.go b/cmd/utils/config_test.go index e2d5336..a5fde8c 100644 --- a/cmd/utils/config_test.go +++ b/cmd/utils/config_test.go @@ -198,4 +198,4 @@ wording: // Test reading a non-existent config _, err = ReadConfig("non-existent-file.yaml") assert.Error(t, err) -} \ No newline at end of file +} diff --git a/cmd/utils/git.go b/cmd/utils/git.go index 8af6b24..b52ae37 100644 --- a/cmd/utils/git.go +++ b/cmd/utils/git.go @@ -29,14 +29,14 @@ type TagDetails struct { // GitRepository represents a git repository type GitRepository struct { - Handler *git.Repository - Name string - Branch string - LocalPath string - UseLocal bool - Commits []CommitDetails - Tags []TagDetails - StartCommit string + Handler *git.Repository + Name string + Branch string + LocalPath string + UseLocal bool + Commits []CommitDetails + Tags []TagDetails + StartCommit string } // PrepareRepository prepares the git repository for use @@ -47,15 +47,15 @@ func PrepareRepository(repo *GitRepository) error { u, err := url.Parse(repo.Name) if err != nil { Error("Unable to parse repository URL", map[string]interface{}{ - "error": err.Error(), - "url": repo.Name, + "error": err.Error(), + "url": repo.Name, }) return err } - + repo.LocalPath = fmt.Sprintf("/tmp/semver/%s/%s", u.Path, repo.Branch) os.RemoveAll(repo.LocalPath) - + repo.Handler, err = git.PlainClone(repo.LocalPath, false, &git.CloneOptions{ URL: repo.Name, ReferenceName: plumbing.NewBranchReferenceName(repo.Branch), @@ -66,11 +66,11 @@ func PrepareRepository(repo *GitRepository) error { }, Tags: git.AllTags, }) - + if err != nil { Error("Unable to clone repository", map[string]interface{}{ - "error": err.Error(), - "url": repo.Name, + "error": err.Error(), + "url": repo.Name, }) return err } @@ -79,13 +79,13 @@ func PrepareRepository(repo *GitRepository) error { repo.Handler, err = git.PlainOpen(repo.LocalPath) if err != nil { Error("Unable to open local repository", map[string]interface{}{ - "error": err.Error(), - "path": repo.LocalPath, + "error": err.Error(), + "path": repo.LocalPath, }) return err } } - + os.Chdir(repo.LocalPath) return nil } @@ -105,7 +105,7 @@ func ListCommits(repo *GitRepository) ([]CommitDetails, error) { if err != nil { return []CommitDetails{}, err } - + commitsList, err := repo.Handler.Log(&git.LogOptions{From: ref.Hash()}) if err != nil { return []CommitDetails{}, err @@ -126,14 +126,14 @@ func ListCommits(repo *GitRepository) ([]CommitDetails, error) { }) Debug("Listing commits", map[string]interface{}{"commits": tmpResults}) - + // Filter commits starting from the specified commit if provided if repo.StartCommit != "" { for commitId, cmt := range tmpResults { if cmt.Hash == repo.StartCommit { Debug("Found commit match", map[string]interface{}{ "commit": cmt.Hash, - "index": commitId, + "index": commitId, }) repo.Commits = tmpResults[commitId:] break @@ -150,32 +150,32 @@ func ListCommits(repo *GitRepository) ([]CommitDetails, error) { // ListExistingTags lists all tags in the repository func ListExistingTags(repo *GitRepository) { Debug("Listing existing tags", nil) - + // Check if Handler is nil to avoid panic if repo.Handler == nil { Debug("Repository handler is nil, skipping tag listing", nil) return } - + refs, err := repo.Handler.Tags() if err != nil { Error("Unable to list tags", map[string]interface{}{"error": err.Error()}) return } - + if err := refs.ForEach(func(ref *plumbing.Reference) error { repo.Tags = append(repo.Tags, TagDetails{ Name: ref.Name().Short(), Hash: ref.Hash().String(), }) - + Debug("Found tag", map[string]interface{}{ - "tag": ref.Name().Short(), + "tag": ref.Name().Short(), "hash": ref.Hash().String(), }) - + return nil }); err != nil { Error("Error iterating tags", map[string]interface{}{"error": err.Error()}) } -} \ No newline at end of file +} diff --git a/cmd/utils/git_test.go b/cmd/utils/git_test.go index f711d1c..15f1dbd 100644 --- a/cmd/utils/git_test.go +++ b/cmd/utils/git_test.go @@ -64,7 +64,7 @@ func TestListCommits(t *testing.T) { t.Run("Test commit filtering logic", func(t *testing.T) { // Create a test repository with predefined commits repo := &GitRepository{} - + // Manually populate the commits for testing repo.Commits = []CommitDetails{ { @@ -83,7 +83,7 @@ func TestListCommits(t *testing.T) { // Test with StartCommit specified repo.StartCommit = "def456" - + // Instead of calling ListCommits which would try to use the nil Handler, // we'll just test the filtering logic directly if repo.StartCommit != "" { @@ -94,19 +94,19 @@ func TestListCommits(t *testing.T) { } } } - + // Verify the filtering worked correctly assert.Len(t, repo.Commits, 1, "Should filter commits starting from specified hash") assert.Equal(t, "def456", repo.Commits[0].Hash, "Commit hash should match") }) - + t.Run("Test with nil Handler", func(t *testing.T) { // Create a test repository with nil Handler repo := &GitRepository{} - + // Now we can safely call ListCommits since we've added a nil check commits, err := ListCommits(repo) - + // Verify the function returns without error assert.NoError(t, err, "Should not error with nil Handler") assert.Empty(t, commits, "Should return empty commits with nil Handler") @@ -120,10 +120,10 @@ func TestListExistingTags(t *testing.T) { t.Run("Test tag processing", func(t *testing.T) { // Create a test repository repo := &GitRepository{} - + // Since we can't test the actual git operations, we'll test the function's behavior // by manually setting up the repository state - + // Manually add tags to verify they're processed correctly repo.Tags = []TagDetails{ { @@ -131,20 +131,20 @@ func TestListExistingTags(t *testing.T) { Hash: "abc123", }, } - + assert.Len(t, repo.Tags, 1, "Should have 1 tag") assert.Equal(t, "v1.0.0", repo.Tags[0].Name, "Tag name should match") assert.Equal(t, "abc123", repo.Tags[0].Hash, "Tag hash should match") }) - + t.Run("Test with nil Handler", func(t *testing.T) { // Create a test repository with nil Handler repo := &GitRepository{} - + // Now we can safely call ListExistingTags since we've added a nil check ListExistingTags(repo) - + // Verify no tags were added assert.Empty(t, repo.Tags, "Should have no tags after calling with nil Handler") }) -} \ No newline at end of file +} diff --git a/cmd/utils/github.go b/cmd/utils/github.go index 7353b25..f18c29e 100644 --- a/cmd/utils/github.go +++ b/cmd/utils/github.go @@ -21,7 +21,7 @@ func UpdatePackage() bool { binaryName := fmt.Sprintf("semver-gen-%s-%s", runtime.GOOS, runtime.GOARCH) Info("Checking for updates", map[string]interface{}{"binaryName": binaryName}) - + gql := graphql.NewConnection() gql.SetEndpoint("https://api.github.com/graphql") gql.SetOutput("mapstring") @@ -29,11 +29,11 @@ func UpdatePackage() bool { headers := map[string]interface{}{ "Authorization": fmt.Sprintf("Bearer %s", ghToken), } - + variables := map[string]interface{}{ "binaryName": binaryName, } - + var query = `query ($binaryName: String) { repository(name: "semver-generator", owner: "lukaszraczylo") { latestRelease { @@ -48,7 +48,7 @@ func UpdatePackage() bool { } } }` - + result, err := gql.Query(query, variables, headers) if err != nil { Error("Unable to query GitHub API", map[string]interface{}{"error": err.Error()}) @@ -58,12 +58,12 @@ func UpdatePackage() bool { output, ok := ask.For(result, "repository.latestRelease.releaseAssets.edges[0].node.downloadUrl").String("") if !ok { Error("Unable to obtain download url for the binary", map[string]interface{}{ - "binary": binaryName, + "binary": binaryName, "output": output, }) return false } - + // Skip actual download in test mode if flag.Lookup("test.v") == nil && os.Getenv("CI") == "" { downloadedBinaryPath := fmt.Sprintf("/tmp/%s", binaryName) @@ -71,12 +71,12 @@ func UpdatePackage() bool { err = g.Download(output, downloadedBinaryPath) if err != nil { Error("Unable to download binary", map[string]interface{}{ - "error": err.Error(), + "error": err.Error(), "binaryPath": downloadedBinaryPath, }) return false } - + currentBinary, err := os.Executable() if err != nil { Error("Unable to obtain current binary path", map[string]interface{}{ @@ -84,7 +84,7 @@ func UpdatePackage() bool { }) return false } - + err = os.Rename(downloadedBinaryPath, currentBinary) if err != nil { Error("Unable to overwrite current binary", map[string]interface{}{ @@ -92,7 +92,7 @@ func UpdatePackage() bool { }) return false } - + err = os.Chmod(currentBinary, 0777) if err != nil { Error("Unable to make binary executable", map[string]interface{}{ @@ -101,7 +101,7 @@ func UpdatePackage() bool { return false } } - + return true } @@ -111,16 +111,16 @@ func CheckLatestRelease() (string, bool) { if !ghTokenSet { return "[no GITHUB_TOKEN set]", false } - + gql := graphql.NewConnection() gql.SetEndpoint("https://api.github.com/graphql") - + headers := map[string]interface{}{ "Authorization": fmt.Sprintf("bearer %s", ghToken), } - + variables := map[string]interface{}{} - + var query = `query { repository(name: "semver-generator", owner: "lukaszraczylo", followRenames: true) { releases(last: 2) { @@ -132,17 +132,17 @@ func CheckLatestRelease() (string, bool) { } } }` - + result, err := gql.Query(query, variables, headers) if err != nil { Error("Unable to query GitHub API", map[string]interface{}{"error": err.Error()}) return "", false } - + output, _ := ask.For(result, "repository.releases.nodes[0].tag.name").String("") if output == "v1" { output, _ = ask.For(result, "repository.releases.nodes[1].tag.name").String("") } - + return output, true -} \ No newline at end of file +} diff --git a/cmd/utils/github_test.go b/cmd/utils/github_test.go index df0ab17..de77030 100644 --- a/cmd/utils/github_test.go +++ b/cmd/utils/github_test.go @@ -63,4 +63,4 @@ func TestUpdatePackage(t *testing.T) { } // Note: We're not using mock transports for these tests to avoid -// adding complexity. The tests focus on the token presence logic and error handling. \ No newline at end of file +// adding complexity. The tests focus on the token presence logic and error handling. diff --git a/cmd/utils/logging.go b/cmd/utils/logging.go index c489cbf..dffba55 100644 --- a/cmd/utils/logging.go +++ b/cmd/utils/logging.go @@ -56,4 +56,4 @@ func Critical(message string, pairs map[string]interface{}) { Pairs: pairs, }) } -} \ No newline at end of file +} diff --git a/cmd/utils/logging_test.go b/cmd/utils/logging_test.go index febb96c..a5af45a 100644 --- a/cmd/utils/logging_test.go +++ b/cmd/utils/logging_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/assert" ) + func TestInitLogger(t *testing.T) { // Test with debug mode enabled logger := InitLogger(true) @@ -25,10 +26,10 @@ func TestLoggingFunctions(t *testing.T) { Debug("Debug message", map[string]interface{}{"key": "value"}) Info("Info message", map[string]interface{}{"key": "value"}) Error("Error message", map[string]interface{}{"key": "value"}) - + // Skip testing Critical as it might call os.Exit // Critical("Critical message", map[string]interface{}{"key": "value"}) - + // Test passes if we get here without panicking assert.True(t, true) } @@ -43,10 +44,10 @@ func TestLoggingWithNilLogger(t *testing.T) { Debug("Debug message", map[string]interface{}{"key": "value"}) Info("Info message", map[string]interface{}{"key": "value"}) Error("Error message", map[string]interface{}{"key": "value"}) - + // Skip testing Critical as it might call os.Exit // Critical("Critical message", map[string]interface{}{"key": "value"}) - + // Test passes if we get here without panicking assert.True(t, true) } @@ -56,15 +57,15 @@ func TestCriticalNilLogger(t *testing.T) { // Save original logger and restore after test originalLogger := Logger defer func() { Logger = originalLogger }() - + // Set logger to nil Logger = nil - + // This should not panic Critical("Critical message", map[string]interface{}{"key": "value"}) - + // Test passes if we get here without panicking assert.True(t, true) } -// Note: We don't test Critical with an actual logger because it calls os.Exit \ No newline at end of file +// Note: We don't test Critical with an actual logger because it calls os.Exit diff --git a/cmd/utils/semver.go b/cmd/utils/semver.go index c09cd33..516b853 100644 --- a/cmd/utils/semver.go +++ b/cmd/utils/semver.go @@ -22,7 +22,7 @@ func CalculateSemver( for _, tagHash := range tags { if commit.Hash == tagHash.Hash { Debug("Found existing tag", map[string]interface{}{ - "tag": tagHash.Name, + "tag": tagHash.Name, "commit": strings.TrimSuffix(commit.Message, "\n"), }) semver = ParseExistingSemver(tagHash.Name, semver) @@ -35,7 +35,7 @@ func CalculateSemver( if !strictMode { semver.Patch++ Debug("Incrementing patch (DEFAULT)", map[string]interface{}{ - "commit": strings.TrimSuffix(commit.Message, "\n"), + "commit": strings.TrimSuffix(commit.Message, "\n"), "semver": FormatSemver(semver), }) } @@ -55,44 +55,44 @@ func CalculateSemver( semver.EnableReleaseCandidate = false semver.Release = 0 Debug("Incrementing major (WORDING)", map[string]interface{}{ - "commit": strings.TrimSuffix(commit.Message, "\n"), + "commit": strings.TrimSuffix(commit.Message, "\n"), "semver": FormatSemver(semver), }) continue } - + if matchMinor { semver.Minor++ semver.Patch = 1 semver.EnableReleaseCandidate = false semver.Release = 0 Debug("Incrementing minor (WORDING)", map[string]interface{}{ - "commit": strings.TrimSuffix(commit.Message, "\n"), + "commit": strings.TrimSuffix(commit.Message, "\n"), "semver": FormatSemver(semver), }) continue } - + if matchReleaseCandidate { semver.Release++ semver.Patch = 1 semver.EnableReleaseCandidate = true Debug("Incrementing release candidate (WORDING)", map[string]interface{}{ - "commit": strings.TrimSuffix(commit.Message, "\n"), + "commit": strings.TrimSuffix(commit.Message, "\n"), "semver": FormatSemver(semver), }) continue } - + if matchPatch { semver.Patch++ Debug("Incrementing patch (WORDING)", map[string]interface{}{ - "commit": strings.TrimSuffix(commit.Message, "\n"), + "commit": strings.TrimSuffix(commit.Message, "\n"), "semver": FormatSemver(semver), }) continue } } - + return semver -} \ No newline at end of file +} diff --git a/cmd/utils/semver_test.go b/cmd/utils/semver_test.go index d7035aa..2e12d5a 100644 --- a/cmd/utils/semver_test.go +++ b/cmd/utils/semver_test.go @@ -19,7 +19,7 @@ func TestCalculateSemver(t *testing.T) { // More sophisticated mock implementation for testing for _, h := range haystack { // Check for substring match to better simulate fuzzy search - if h == needle || (len(h) >= 3 && len(needle) >= 3 && + if h == needle || (len(h) >= 3 && len(needle) >= 3 && (h[:3] == needle[:3] || h[len(h)-3:] == needle[len(needle)-3:])) { return []string{h} } @@ -29,7 +29,7 @@ func TestCalculateSemver(t *testing.T) { // Test data now := time.Now() - + // Common wording and blacklist for all tests wording := Wording{ Patch: []string{"update", "fix", "initial"}, @@ -77,10 +77,10 @@ func TestCalculateSemver(t *testing.T) { respectExisting: true, strictMode: false, want: SemVer{ - Major: 2, - Minor: 0, - Patch: 1, // Initial tag 2.0.0 + one patch increment - Release: 1, + Major: 2, + Minor: 0, + Patch: 1, // Initial tag 2.0.0 + one patch increment + Release: 1, EnableReleaseCandidate: true, }, }, @@ -110,10 +110,10 @@ func TestCalculateSemver(t *testing.T) { respectExisting: true, strictMode: true, want: SemVer{ - Major: 2, - Minor: 0, - Patch: 1, // Initial tag 2.0.0 + patch from "update" keyword - Release: 1, + Major: 2, + Minor: 0, + Patch: 1, // Initial tag 2.0.0 + patch from "update" keyword + Release: 1, EnableReleaseCandidate: true, }, }, @@ -254,4 +254,4 @@ func TestCalculateSemver(t *testing.T) { assert.Equal(t, tt.want.EnableReleaseCandidate, got.EnableReleaseCandidate, "EnableReleaseCandidate mismatch") }) } -} \ No newline at end of file +} diff --git a/cmd/utils/version.go b/cmd/utils/version.go index a0d05ac..ffbf9c4 100644 --- a/cmd/utils/version.go +++ b/cmd/utils/version.go @@ -54,33 +54,33 @@ var extractNumber = regexp.MustCompile("[0-9]+") // ParseExistingSemver parses a semantic version from a tag name func ParseExistingSemver(tagName string, currentSemver SemVer) SemVer { Debug("Parsing existing semver", map[string]interface{}{"tag": tagName}) - + tagNameParts := strings.Split(tagName, ".") if len(tagNameParts) < 3 { Debug("Unable to parse incompatible semver (non x.y.z)", map[string]interface{}{"tag": tagName}) return currentSemver } - + semanticVersion := SemVer{} - + // Extract major version majorMatches := extractNumber.FindAllString(tagNameParts[0], -1) if len(majorMatches) > 0 { semanticVersion.Major, _ = strconv.Atoi(majorMatches[0]) } - + // Extract minor version minorMatches := extractNumber.FindAllString(tagNameParts[1], -1) if len(minorMatches) > 0 { semanticVersion.Minor, _ = strconv.Atoi(minorMatches[0]) } - + // Extract patch version patchMatches := extractNumber.FindAllString(tagNameParts[2], -1) if len(patchMatches) > 0 { semanticVersion.Patch, _ = strconv.Atoi(patchMatches[0]) } - + // Extract release candidate version if present if len(tagNameParts) > 3 { releaseMatches := extractNumber.FindAllString(tagNameParts[3], -1) @@ -89,14 +89,14 @@ func ParseExistingSemver(tagName string, currentSemver SemVer) SemVer { semanticVersion.EnableReleaseCandidate = true } } - + return semanticVersion } // CheckMatches checks if any of the targets match the content func CheckMatches(content []string, targets []string, blacklist []string) bool { contentStr := strings.Join(content, " ") - + // First check if any target matches hasMatch := false for _, tgt := range targets { @@ -104,8 +104,8 @@ func CheckMatches(content []string, targets []string, blacklist []string) bool { if len(matches) > 0 { hasMatch = true Debug("Found match", map[string]interface{}{ - "target": tgt, - "match": strings.Join(matches, ","), + "target": tgt, + "match": strings.Join(matches, ","), "content": contentStr, }) break @@ -117,14 +117,14 @@ func CheckMatches(content []string, targets []string, blacklist []string) bool { for _, blacklistTerm := range blacklist { if strings.Contains(strings.ToLower(contentStr), strings.ToLower(blacklistTerm)) { Debug("Blacklisted term detected, ignoring commit", map[string]interface{}{ - "content": contentStr, + "content": contentStr, "blacklist_term": blacklistTerm, }) return false } } } - + return hasMatch } @@ -132,4 +132,4 @@ func CheckMatches(content []string, targets []string, blacklist []string) bool { var FuzzyFind = func(needle string, haystack []string) []string { // This will be replaced with the actual implementation in main.go return nil -} \ No newline at end of file +} diff --git a/cmd/utils/version_test.go b/cmd/utils/version_test.go index df4f394..d0c2b79 100644 --- a/cmd/utils/version_test.go +++ b/cmd/utils/version_test.go @@ -58,14 +58,14 @@ func TestParseExistingSemver(t *testing.T) { InitLogger(false) tests := []struct { - name string - tagName string + name string + tagName string currentSemver SemVer - want SemVer + want SemVer }{ { - name: "Standard semver", - tagName: "1.2.3", + name: "Standard semver", + tagName: "1.2.3", currentSemver: SemVer{}, want: SemVer{ Major: 1, @@ -74,8 +74,8 @@ func TestParseExistingSemver(t *testing.T) { }, }, { - name: "With v prefix", - tagName: "v2.3.4", + name: "With v prefix", + tagName: "v2.3.4", currentSemver: SemVer{}, want: SemVer{ Major: 2, @@ -84,8 +84,8 @@ func TestParseExistingSemver(t *testing.T) { }, }, { - name: "With release candidate", - tagName: "3.4.5-rc.2", + name: "With release candidate", + tagName: "3.4.5-rc.2", currentSemver: SemVer{}, want: SemVer{ Major: 3, @@ -196,4 +196,4 @@ func TestCheckMatches(t *testing.T) { assert.Equal(t, tt.want, got) }) } -} \ No newline at end of file +} diff --git a/main_test.go b/main_test.go index f787f92..ca567d6 100644 --- a/main_test.go +++ b/main_test.go @@ -30,4 +30,4 @@ func TestMain(t *testing.T) { // Verify that the version was set correctly assert.Equal(t, "test-version", cmd.PKG_VERSION, "PKG_VERSION should be set correctly") -} \ No newline at end of file +}