Skip to content

Commit

Permalink
Improve repositores code
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Sverdlov <[email protected]>
  • Loading branch information
sverdlov93 committed Nov 7, 2024
1 parent 265fea7 commit e8f884c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions artifactory/commands/buildtoollogin/buildtoollogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion artifactory/commands/buildtoollogin/buildtoollogin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e8f884c

Please sign in to comment.