From 72b9e8328de493d2612d17c8fa70aa81b20f6e33 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Sat, 22 Feb 2025 20:35:08 -0500 Subject: [PATCH] Make commit prefixes migration only return true if it enters if statement --- pkg/config/app_config.go | 6 +++--- pkg/config/app_config_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index cfdc75e31..e7d884dbb 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -306,6 +306,7 @@ func changeElementToSequence(changedContent []byte, path []string) ([]byte, erro func changeCommitPrefixesMap(changedContent []byte) ([]byte, error) { return yaml_utils.TransformNode(changedContent, []string{"git", "commitPrefixes"}, func(prefixesNode *yaml.Node) (bool, error) { + changedAnyNodes := false if prefixesNode.Kind == yaml.MappingNode { for _, contentNode := range prefixesNode.Content { if contentNode.Kind == yaml.MappingNode { @@ -317,12 +318,11 @@ func changeCommitPrefixesMap(changedContent []byte) ([]byte, error) { Kind: yaml.MappingNode, Content: nodeContentCopy, }} - + changedAnyNodes = true } } - return true, nil } - return false, nil + return changedAnyNodes, nil }) } diff --git a/pkg/config/app_config_test.go b/pkg/config/app_config_test.go index 4a6ce0ee6..cf72f201b 100644 --- a/pkg/config/app_config_test.go +++ b/pkg/config/app_config_test.go @@ -52,6 +52,28 @@ func TestCommitPrefixMigrations(t *testing.T) { name: "Incomplete Configuration", input: "git:", expected: "git:", + }, { + // This test intentionally uses non-standard indentation to test that the migration + // does not change the input. + name: "No changes made when already migrated", + input: ` +git: + commitPrefix: + - pattern: "Hello World" + replace: "Goodbye" + commitPrefixes: + foo: + - pattern: "^\\w+-\\w+.*" + replace: '[JIRA $0] '`, + expected: ` +git: + commitPrefix: + - pattern: "Hello World" + replace: "Goodbye" + commitPrefixes: + foo: + - pattern: "^\\w+-\\w+.*" + replace: '[JIRA $0] '`, }, }