github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/model/buildrequest.go (about)

     1  package model
     2  
     3  import (
     4  	"github.com/ActiveState/cli/internal/constants"
     5  	"github.com/ActiveState/cli/internal/locale"
     6  	"github.com/ActiveState/cli/pkg/platform/api/headchef"
     7  	"github.com/ActiveState/cli/pkg/platform/api/headchef/headchef_models"
     8  	"github.com/ActiveState/cli/pkg/platform/api/mono/mono_models"
     9  	"github.com/ActiveState/cli/pkg/platform/authentication"
    10  	"github.com/go-openapi/strfmt"
    11  )
    12  
    13  func RequestBuild(auth *authentication.Auth, recipeID, commitID strfmt.UUID, owner, project string) (headchef.BuildStatusEnum, *headchef_models.V1BuildStatusResponse, error) {
    14  	var platProj *mono_models.Project
    15  	if owner != "" && project != "" {
    16  		var err error
    17  		platProj, err = LegacyFetchProjectByName(owner, project)
    18  		if err != nil {
    19  			return headchef.Error, nil, locale.WrapError(err, "build_request_get_project_err", "Could not find project {{.V0}}/{{.V1}} on ActiveState Platform.", owner, project)
    20  		}
    21  	}
    22  
    23  	buildAnnotations := headchef.BuildAnnotations{
    24  		CommitID:     commitID.String(),
    25  		Project:      project,
    26  		Organization: owner,
    27  	}
    28  
    29  	orgID := strfmt.UUID(constants.ValidZeroUUID)
    30  	projectID := strfmt.UUID(constants.ValidZeroUUID)
    31  	if platProj != nil {
    32  		orgID = platProj.OrganizationID
    33  		projectID = platProj.ProjectID
    34  	}
    35  
    36  	return requestBuild(auth, recipeID, orgID, projectID, buildAnnotations)
    37  }
    38  
    39  func requestBuild(auth *authentication.Auth, recipeID, orgID, projID strfmt.UUID, annotations headchef.BuildAnnotations) (headchef.BuildStatusEnum, *headchef_models.V1BuildStatusResponse, error) {
    40  	buildRequest, err := headchef.NewBuildRequest(recipeID, orgID, projID, annotations)
    41  	if err != nil {
    42  		return headchef.Error, nil, err
    43  	}
    44  	return headchef.InitClient(auth).RequestBuildSync(buildRequest)
    45  }