From e8f884c57d39ad6be37a305908f62bc37ad7b853 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Thu, 7 Nov 2024 14:23:36 +0200 Subject: [PATCH] Improve repositores code Signed-off-by: Michael Sverdlov --- artifactory/commands/buildtoollogin/buildtoollogin.go | 10 ++++++---- .../commands/buildtoollogin/buildtoollogin_test.go | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/artifactory/commands/buildtoollogin/buildtoollogin.go b/artifactory/commands/buildtoollogin/buildtoollogin.go index 1cb35ac31..24cb45212 100644 --- a/artifactory/commands/buildtoollogin/buildtoollogin.go +++ b/artifactory/commands/buildtoollogin/buildtoollogin.go @@ -46,6 +46,8 @@ func buildToolToPackageType(buildTool project.ProjectType) (string, error) { return repository.Npm, nil case project.Pip, project.Pipenv, project.Poetry: return repository.Pypi, nil + case project.Go: + return repository.Go, nil default: return "", errorutils.CheckError(fmt.Errorf("unsupported build tool: %s", buildTool)) } @@ -69,9 +71,9 @@ func (btlc *BuildToolLoginCommand) ServerDetails() (*config.ServerDetails, error // Run executes the configuration method corresponding to the project type specified for the command. func (btlc *BuildToolLoginCommand) Run() (err error) { - // Prompt the user to select a repository if none has been specified. if btlc.repoName == "" { - if err = btlc.SetVirtualRepoNameInteractively(); err != nil { + // Prompt the user to select a virtual repository that matches the project type. + if err = btlc.GetRepositoryNameFromUserInteractively(); err != nil { return err } } @@ -99,8 +101,8 @@ func (btlc *BuildToolLoginCommand) Run() (err error) { return nil } -// SetVirtualRepoNameInteractively prompts the user to select a compatible virtual repository. -func (btlc *BuildToolLoginCommand) SetVirtualRepoNameInteractively() error { +// GetRepositoryNameFromUserInteractively prompts the user to select a compatible virtual repository. +func (btlc *BuildToolLoginCommand) GetRepositoryNameFromUserInteractively() error { // Map the build tool to its corresponding package type. packageType, err := buildToolToPackageType(btlc.buildTool) if err != nil { diff --git a/artifactory/commands/buildtoollogin/buildtoollogin_test.go b/artifactory/commands/buildtoollogin/buildtoollogin_test.go index f52e604f9..8e68dcf91 100644 --- a/artifactory/commands/buildtoollogin/buildtoollogin_test.go +++ b/artifactory/commands/buildtoollogin/buildtoollogin_test.go @@ -44,7 +44,8 @@ var testCases = []struct { func createTestBuildToolLoginCommand(buildTool project.ProjectType) *BuildToolLoginCommand { cmd := NewBuildToolLoginCommand(buildTool) cmd.repoName = "test-repo" - cmd.serverDetails = &config.ServerDetails{ArtifactoryUrl: "https://acme.jfrog.io/artifactory"} + dummyUrl := "https://acme.jfrog.io" + cmd.serverDetails = &config.ServerDetails{Url: dummyUrl, ArtifactoryUrl: dummyUrl + "/artifactory"} return cmd }