From 9a1d40ec9847f61caaf13c326b56afaaa8271d33 Mon Sep 17 00:00:00 2001 From: Ajita Jain Date: Fri, 4 Oct 2024 15:31:39 -0700 Subject: [PATCH] code refactor + change regex for github url validation --- internal/commands/update_release.go | 2 -- internal/commands/update_stemcell.go | 1 - internal/gh/uri.go | 2 +- pkg/cargo/kilnfile.go | 3 ++- pkg/planitest/internal/config.go | 1 - pkg/planitest/internal/om_runner.go | 2 -- 6 files changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/commands/update_release.go b/internal/commands/update_release.go index 003890f1a..d17a8445e 100644 --- a/internal/commands/update_release.go +++ b/internal/commands/update_release.go @@ -78,7 +78,6 @@ func (u UpdateRelease) Execute(args []string) error { StemcellOS: kilnfileLock.Stemcell.OS, GitHubRepository: releaseSpec.GitHubRepository, }, false) - if err != nil { if component.IsErrNotFound(err) { return fmt.Errorf("error finding the release: %w", err) @@ -99,7 +98,6 @@ func (u UpdateRelease) Execute(args []string) error { StemcellVersion: kilnfileLock.Stemcell.Version, GitHubRepository: releaseSpec.GitHubRepository, }) - if err != nil { if component.IsErrNotFound(err) { return fmt.Errorf("error finding the release: %w", err) diff --git a/internal/commands/update_stemcell.go b/internal/commands/update_stemcell.go index 128ec23f1..36992c79f 100644 --- a/internal/commands/update_stemcell.go +++ b/internal/commands/update_stemcell.go @@ -48,7 +48,6 @@ func (update UpdateStemcell) Execute(args []string) error { kilnStemcellVersion := kilnfile.Stemcell.Version releaseVersionConstraint, err = semver.NewConstraint(kilnStemcellVersion) - if err != nil { return fmt.Errorf("invalid stemcell constraint in kilnfile: %w", err) } diff --git a/internal/gh/uri.go b/internal/gh/uri.go index 5d558501b..472f5344d 100644 --- a/internal/gh/uri.go +++ b/internal/gh/uri.go @@ -20,7 +20,7 @@ func RepositoryHostOwnerAndNameFromPath(urlStr string) (string, string, string, return fmt.Errorf("failed to parse owner and repo name from URI %q: %w", urlStr, err) } if strings.HasPrefix(urlStr, "git@") { - exp := regexp.MustCompile(`git@(?P.*):(?P[^/]+)/(?P.+)\.git`) + exp := regexp.MustCompile(`git@(?P.+):(?P[^/]+)/(?P.+)\.git`) m := exp.FindStringSubmatch(urlStr) if m == nil { return "", "", "", fmt.Errorf("path missing expected parts") diff --git a/pkg/cargo/kilnfile.go b/pkg/cargo/kilnfile.go index dc9212a72..c3d6ad3b6 100644 --- a/pkg/cargo/kilnfile.go +++ b/pkg/cargo/kilnfile.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" + "strings" + "github.com/google/go-github/v50/github" "golang.org/x/oauth2" - "strings" "gopkg.in/yaml.v3" diff --git a/pkg/planitest/internal/config.go b/pkg/planitest/internal/config.go index 7e5b40463..4c3bb5cd6 100644 --- a/pkg/planitest/internal/config.go +++ b/pkg/planitest/internal/config.go @@ -43,7 +43,6 @@ func MergeAdditionalProductProperties(configFile io.Reader, additionalProperties var inputConfig ProductConfiguration err = yaml.Unmarshal(yamlInput, &inputConfig) - if err != nil { return nil, fmt.Errorf("could not parse config file: %s", err) } diff --git a/pkg/planitest/internal/om_runner.go b/pkg/planitest/internal/om_runner.go index 40fc80249..906bcb8be 100644 --- a/pkg/planitest/internal/om_runner.go +++ b/pkg/planitest/internal/om_runner.go @@ -89,7 +89,6 @@ func (o OMRunner) ResetAndConfigure(productName string, productVersion string, c "--product-name", productName, "--product-version", productVersion, ) - if err != nil { return fmt.Errorf("Unable to stage product %q, version %q: %s: %s", productName, productVersion, err, errOutput) @@ -114,7 +113,6 @@ func (o OMRunner) ResetAndConfigure(productName string, productVersion string, c "configure-product", "--config", configFile.Name(), ) - if err != nil { return fmt.Errorf("Unable to configure product %q: %s: %s", productName, err, errOutput) }