MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Create

Method Create

app/controlplane/pkg/biz/workflow.go:143–258  ·  view source on GitHub ↗
(ctx context.Context, opts *WorkflowCreateOpts)

Source from the content-addressed store, hash-verified

141}
142
143func (uc *WorkflowUseCase) Create(ctx context.Context, opts *WorkflowCreateOpts) (*Workflow, error) {
144 ctx, span := otelx.Start(ctx, workflowTracer, "WorkflowUseCase.Create")
145 defer span.End()
146
147 if opts.Name == "" {
148 return nil, errors.New("workflow name is required")
149 }
150 if opts.Project == "" {
151 return nil, errors.New("project name is required")
152 }
153 if opts.OrgID == "" {
154 return nil, errors.New("organization ID is required")
155 }
156
157 contractName := fmt.Sprintf("%s-%s", opts.Project, opts.Name)
158
159 defaultContract, err := createDefaultContract(contractName)
160 if err != nil {
161 return nil, fmt.Errorf("failed to create default contract: %w", err)
162 }
163 opts.DetectedContract = defaultContract
164
165 // Take the raw contract bytes and identify the format and validate it
166 if opts.ContractBytes != nil {
167 detectedContract, err := identifyUnMarshalAndValidateRawContract(opts.ContractBytes)
168 if err != nil {
169 return nil, fmt.Errorf("failed to load contract: %w", err)
170 }
171
172 opts.DetectedContract = detectedContract
173 }
174
175 // validate format of the name and the project
176 if err := ValidateIsDNS1123(opts.Name); err != nil {
177 return nil, NewErrValidation(err)
178 }
179
180 if err := ValidateIsDNS1123(opts.Project); err != nil {
181 return nil, NewErrValidation(err)
182 }
183
184 // Check if the project already exists to determine if we need to emit a ProjectCreated event
185 orgUUID, err := uuid.Parse(opts.OrgID)
186 if err != nil {
187 return nil, fmt.Errorf("failed to parse org ID %q: %w", opts.OrgID, err)
188 }
189
190 // Check if implicit creation is prevented by organization settings
191 if opts.ImplicitCreation {
192 org, err := uc.orgRepo.FindByID(ctx, orgUUID)
193 if err != nil {
194 return nil, fmt.Errorf("failed to find organization: %w", err)
195 }
196 if org == nil {
197 return nil, NewErrNotFound("organization")
198 }
199
200 if org.PreventImplicitWorkflowCreation {

Callers

nothing calls this directly

Calls 14

StartFunction · 0.92
createDefaultContractFunction · 0.85
ValidateIsDNS1123Function · 0.85
NewErrValidationFunction · 0.85
IsErrAlreadyExistsFunction · 0.85
NewErrAlreadyExistsStrFunction · 0.85
ParseMethod · 0.80
SetProjectOwnerMethod · 0.80
NewErrNotFoundFunction · 0.70
FindByIDMethod · 0.65

Tested by

no test coverage detected