github.com/jfrog/jfrog-cli-core/v2@v2.52.0/artifactory/commands/buildinfo/promote.go (about)

     1  package buildinfo
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
     5  	"github.com/jfrog/jfrog-cli-core/v2/common/build"
     6  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     7  	"github.com/jfrog/jfrog-client-go/artifactory/services"
     8  )
     9  
    10  type BuildPromotionCommand struct {
    11  	services.PromotionParams
    12  	buildConfiguration *build.BuildConfiguration
    13  	serverDetails      *config.ServerDetails
    14  	dryRun             bool
    15  }
    16  
    17  func NewBuildPromotionCommand() *BuildPromotionCommand {
    18  	return &BuildPromotionCommand{}
    19  }
    20  
    21  func (bpc *BuildPromotionCommand) SetDryRun(dryRun bool) *BuildPromotionCommand {
    22  	bpc.dryRun = dryRun
    23  	return bpc
    24  }
    25  
    26  func (bpc *BuildPromotionCommand) SetServerDetails(serverDetails *config.ServerDetails) *BuildPromotionCommand {
    27  	bpc.serverDetails = serverDetails
    28  	return bpc
    29  }
    30  
    31  func (bpc *BuildPromotionCommand) SetPromotionParams(params services.PromotionParams) *BuildPromotionCommand {
    32  	bpc.PromotionParams = params
    33  	return bpc
    34  }
    35  
    36  func (bpc *BuildPromotionCommand) SetBuildConfiguration(buildConfiguration *build.BuildConfiguration) *BuildPromotionCommand {
    37  	bpc.buildConfiguration = buildConfiguration
    38  	return bpc
    39  }
    40  
    41  func (bpc *BuildPromotionCommand) Run() error {
    42  	servicesManager, err := utils.CreateServiceManager(bpc.serverDetails, -1, 0, bpc.dryRun)
    43  	if err != nil {
    44  		return err
    45  	}
    46  	if err := bpc.buildConfiguration.ValidateBuildParams(); err != nil {
    47  		return err
    48  	}
    49  	buildName, err := bpc.buildConfiguration.GetBuildName()
    50  	if err != nil {
    51  		return err
    52  	}
    53  	buildNumber, err := bpc.buildConfiguration.GetBuildNumber()
    54  	if err != nil {
    55  		return err
    56  	}
    57  	bpc.BuildName, bpc.BuildNumber, bpc.ProjectKey = buildName, buildNumber, bpc.buildConfiguration.GetProject()
    58  	return servicesManager.PromoteBuild(bpc.PromotionParams)
    59  }
    60  
    61  func (bpc *BuildPromotionCommand) ServerDetails() (*config.ServerDetails, error) {
    62  	return bpc.serverDetails, nil
    63  }
    64  
    65  func (bpc *BuildPromotionCommand) CommandName() string {
    66  	return "rt_build_promote"
    67  }