Repository: apache/camel-k
Pull request #4366 (2023-05-11 14:26:57)

chore(deps): remove camelcase dependency
Ref #4326

<!-- Description -->




<!--
Enter your extended release note in the below block. If the PR requires
additional action from users switching to the new release, include the string
"action required". If no release note is required, write "NONE". 

You can (optionally) mark this PR with labels "kind/bug" or "kind/feature" to make sure
the text is added to the right section of the release notes. 
-->

**Release Note**
```release-note
chore(deps): remove camelcase dependency
```



Patch:
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index a2585e009..b279babc9 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -23,7 +23,7 @@ updates:
     schedule:
       interval: "daily"
     ignore:
-      - dependency-name: "k8s.io/api"      
+      - dependency-name: "k8s.io/api"
       - dependency-name: "k8s.io/apiextensions-apiserver"
       - dependency-name: "k8s.io/apimachinery"
       - dependency-name: "k8s.io/cli-runtime"
diff --git a/go.mod b/go.mod
index c868ddf1e..e54220e82 100644
--- a/go.mod
+++ b/go.mod
@@ -9,7 +9,6 @@ require (
 	github.com/apache/camel-k/v2/pkg/kamelet/repository v0.0.0
 	github.com/container-tools/spectrum v0.6.12
 	github.com/evanphx/json-patch v4.12.0+incompatible
-	github.com/fatih/camelcase v1.0.0
 	github.com/fatih/structs v1.1.0
 	github.com/gertd/go-pluralize v0.2.1
 	github.com/go-logr/logr v1.2.4
diff --git a/go.sum b/go.sum
index 29321d182..dbb4d838a 100644
--- a/go.sum
+++ b/go.sum
@@ -414,8 +414,6 @@ github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH
 github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
 github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
 github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
-github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
-github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
 github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
 github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
 github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go
index 3314e1274..94607b4f1 100644
--- a/pkg/cmd/version.go
+++ b/pkg/cmd/version.go
@@ -20,25 +20,18 @@ package cmd
 import (
 	"context"
 	"fmt"
-	"regexp"
-	"strings"
 
 	v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/v2/pkg/util/camel"
 
-	"golang.org/x/text/cases"
-	"golang.org/x/text/language"
-
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 
 	"github.com/Masterminds/semver"
-	"github.com/fatih/camelcase"
 	"github.com/spf13/cobra"
 
 	"github.com/apache/camel-k/v2/pkg/client"
 	platformutil "github.com/apache/camel-k/v2/pkg/platform"
 	"github.com/apache/camel-k/v2/pkg/util/defaults"
-	"github.com/apache/camel-k/v2/pkg/util/log"
 )
 
 // VersionVariant may be overridden at build time.
@@ -48,8 +41,6 @@ const (
 	infoVersion = "Version"
 )
 
-var replaceRegexp = regexp.MustCompile(`(\s+\.\s*)|(\s+-\s*)`)
-
 func newCmdVersion(rootCmdOptions *RootCmdOptions) (*cobra.Command, *versionCmdOptions) {
 	options := versionCmdOptions{
 		RootCmdOptions: rootCmdOptions,
@@ -150,18 +141,12 @@ func operatorInfo(ctx context.Context, c client.Client, namespace string) (map[s
 		return nil, err
 	}
 
-	// Useful information
-	infos["name"] = platform.Name
-	infos["version"] = platform.Status.Version
-	infos["publishStrategy"] = string(platform.Status.Build.PublishStrategy)
-	infos["runtimeVersion"] = platform.Status.Build.RuntimeVersion
-	infos["registryAddress"] = platform.Status.Build.Registry.Address
-
-	if platform.Status.Info != nil {
-		for k, v := range platform.Status.Info {
-			infos[k] = v
-		}
-	}
+	infos["Name"] = platform.Name
+	infos["Version"] = platform.Status.Version
+	infos["Publish strategy"] = string(platform.Status.Build.PublishStrategy)
+	infos["Runtime version"] = platform.Status.Build.RuntimeVersion
+	infos["Registry address"] = platform.Status.Build.Registry.Address
+	infos["Git commit"] = platform.Status.Info["gitCommit"]
 
 	catalog, err := camel.LoadCatalog(ctx, c, namespace, v1.RuntimeSpec{Version: platform.Status.Build.RuntimeVersion, Provider: platform.Status.Build.RuntimeProvider})
 	if err != nil {
@@ -170,25 +155,12 @@ func operatorInfo(ctx context.Context, c client.Client, namespace string) (map[s
 	if catalog == nil {
 		return nil, fmt.Errorf("CamelCatalog can't be found in %s namespace", platform.Namespace)
 	}
-	for k, v := range catalog.CamelCatalogSpec.Runtime.Metadata {
-		infos[k] = v
-	}
-
-	ccInfo := fromCamelCase(infos)
-	log.Debugf("Operator Info for namespace %s: %v", namespace, ccInfo)
-	return ccInfo, nil
-}
 
-func fromCamelCase(infos map[string]string) map[string]string {
-	textKeys := make(map[string]string)
-
-	for k, v := range infos {
-		key := cases.Title(language.English).String(strings.Join(camelcase.Split(k), " "))
-		key = replaceRegexp.ReplaceAllString(key, " ")
-		textKeys[key] = v
-	}
+	infos["Camel Quarkus version"] = catalog.CamelCatalogSpec.Runtime.Metadata["camel-quarkus.version"]
+	infos["Camel version"] = catalog.CamelCatalogSpec.Runtime.Metadata["camel.version"]
+	infos["Quarkus version"] = catalog.CamelCatalogSpec.Runtime.Metadata["quarkus.version"]
 
-	return textKeys
+	return infos, nil
 }
 
 func operatorVersion(ctx context.Context, c client.Client, namespace string) (string, error) {


Test patch:
diff --git a/pkg/cmd/version_test.go b/pkg/cmd/version_test.go
index 6dda7f1b6..053e0dae8 100644
--- a/pkg/cmd/version_test.go
+++ b/pkg/cmd/version_test.go
@@ -101,9 +101,9 @@ func TestOperatorVersionVerbose(t *testing.T) {
 	assert.Nil(t, err)
 	assert.Equal(t, true, versionCmdOptions.Verbose)
 	assert.Contains(t, output, fmt.Sprintf("Camel K Operator %s\n", defaults.Version))
-	assert.Contains(t, output, fmt.Sprintf("Camel Version: %s\n", catalog.Spec.Runtime.Metadata["camel.version"]))
-	assert.Contains(t, output, fmt.Sprintf("Camel Quarkus Version: %s\n", catalog.Spec.Runtime.Metadata["camel-quarkus.version"]))
-	assert.Contains(t, output, fmt.Sprintf("Quarkus Version: %s\n", catalog.Spec.Runtime.Metadata["quarkus.version"]))
+	assert.Contains(t, output, fmt.Sprintf("Camel version: %s\n", catalog.Spec.Runtime.Metadata["camel.version"]))
+	assert.Contains(t, output, fmt.Sprintf("Camel Quarkus version: %s\n", catalog.Spec.Runtime.Metadata["camel-quarkus.version"]))
+	assert.Contains(t, output, fmt.Sprintf("Quarkus version: %s\n", catalog.Spec.Runtime.Metadata["quarkus.version"]))
 }
 
 func TestCompatibleVersions(t *testing.T) {