2
0
Эх сурвалжийг харах

sanitize all instances of repo name (#3385)

ianedwards 2 жил өмнө
parent
commit
da69bab851

+ 2 - 1
cli/cmd/apply.go

@@ -26,6 +26,7 @@ import (
 	porter_app "github.com/porter-dev/porter/cli/cmd/porter_app"
 	"github.com/porter-dev/porter/cli/cmd/preview"
 	previewV2Beta1 "github.com/porter-dev/porter/cli/cmd/preview/v2beta1"
+	cliUtils "github.com/porter-dev/porter/cli/cmd/utils"
 	previewInt "github.com/porter-dev/porter/internal/integrations/preview"
 	"github.com/porter-dev/porter/internal/templater/utils"
 	"github.com/porter-dev/switchboard/pkg/drivers"
@@ -669,7 +670,7 @@ func (d *DeployDriver) createApplication(resource *switchboardModels.Resource, c
 
 	if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 		if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-			repoSuffix = strings.ToLower(strings.ReplaceAll(fmt.Sprintf("%s-%s", repoOwner, repoName), "_", "-"))
+			repoSuffix = cliUtils.SlugifyRepoSuffix(repoOwner, repoName)
 		}
 	}
 

+ 2 - 1
cli/cmd/preview/build_image_driver.go

@@ -15,6 +15,7 @@ import (
 	"github.com/porter-dev/porter/cli/cmd/config"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
 	"github.com/porter-dev/porter/cli/cmd/docker"
+	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/porter-dev/porter/internal/integrations/preview"
 	"github.com/porter-dev/switchboard/pkg/drivers"
 	"github.com/porter-dev/switchboard/pkg/models"
@@ -105,7 +106,7 @@ func (d *BuildDriver) Apply(resource *models.Resource) (*models.Resource, error)
 
 	if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 		if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-			repoSuffix = sanitizedRepoSuffix(repoOwner, repoName)
+			repoSuffix = utils.SlugifyRepoSuffix(repoOwner, repoName)
 		}
 	}
 

+ 2 - 1
cli/cmd/preview/push_image_driver.go

@@ -10,6 +10,7 @@ import (
 	"github.com/porter-dev/porter/cli/cmd/config"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
 	"github.com/porter-dev/porter/cli/cmd/docker"
+	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/porter-dev/porter/internal/integrations/preview"
 	"github.com/porter-dev/switchboard/pkg/drivers"
 	"github.com/porter-dev/switchboard/pkg/models"
@@ -91,7 +92,7 @@ func (d *PushDriver) Apply(resource *models.Resource) (*models.Resource, error)
 
 		if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 			if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-				repoSuffix = sanitizedRepoSuffix(repoOwner, repoName)
+				repoSuffix = utils.SlugifyRepoSuffix(repoOwner, repoName)
 			}
 		}
 

+ 2 - 1
cli/cmd/preview/update_config_driver.go

@@ -13,6 +13,7 @@ import (
 	"github.com/porter-dev/porter/cli/cmd/config"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
 	"github.com/porter-dev/porter/cli/cmd/deploy/wait"
+	cliUtils "github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/porter-dev/porter/internal/integrations/preview"
 	"github.com/porter-dev/porter/internal/templater/utils"
 	"github.com/porter-dev/switchboard/pkg/drivers"
@@ -114,7 +115,7 @@ func (d *UpdateConfigDriver) Apply(resource *models.Resource) (*models.Resource,
 
 	if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 		if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-			repoSuffix = sanitizedRepoSuffix(repoOwner, repoName)
+			repoSuffix = cliUtils.SlugifyRepoSuffix(repoOwner, repoName)
 		}
 	}
 

+ 3 - 2
cli/cmd/preview/util.go → cli/cmd/utils/sanitize.go

@@ -1,11 +1,12 @@
-package preview
+package utils
 
 import (
 	"fmt"
 	"strings"
 )
 
-func sanitizedRepoSuffix(repoOwner, repoName string) string {
+// SlugifyRepoSuffix return a sanitized repository name based on a Git repo owner and name.
+func SlugifyRepoSuffix(repoOwner, repoName string) string {
 	initialSuffix := fmt.Sprintf("%s-%s", repoOwner, repoName)
 	sanitizedSuffix := strings.ReplaceAll(strings.ReplaceAll(initialSuffix, "_", "-"), ".", "-")
 	return strings.ToLower(sanitizedSuffix)