MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Apply

Method Apply

module/publish/iml.go:369–412  ·  view source on GitHub ↗

Apply applies the changes to the imlPublishModule. ctx context.Context, serviceId string, input *dto.ApplyInput *dto.Publish, error

(ctx context.Context, serviceId string, input *dto.ApplyInput)

Source from the content-addressed store, hash-verified

367// ctx context.Context, serviceId string, input *dto.ApplyInput
368// *dto.Publish, error
369func (i *imlPublishModule) Apply(ctx context.Context, serviceId string, input *dto.ApplyInput) (*dto.Publish, error) {
370 _, err := i.serviceService.Check(ctx, serviceId, asServer)
371 if err != nil {
372 return nil, err
373 }
374 err = i.checkPublish(ctx, serviceId, input.Release)
375 if err != nil {
376 return nil, err
377 }
378
379 previous := ""
380 running, err := i.releaseService.GetRunning(ctx, serviceId)
381 if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
382
383 return nil, err
384 }
385 if running != nil {
386 previous = running.UUID
387 }
388
389 releaseToPublish, err := i.releaseService.GetRelease(ctx, input.Release)
390 if err != nil {
391 // 目标版本不存在
392 return nil, err
393 }
394
395 newPublishId := uuid.NewString()
396 diff, ok, err := i.projectDiffModule.DiffForLatest(ctx, serviceId, previous)
397 if err != nil {
398 return nil, err
399 }
400 if !ok {
401 return nil, errors.New("latest completeness check failed")
402 }
403 err = i.publishService.Create(ctx, newPublishId, serviceId, releaseToPublish.UUID, previous, releaseToPublish.Version, input.Remark, diff)
404 if err != nil {
405 return nil, err
406 }
407 np, err := i.publishService.Get(ctx, newPublishId)
408 if err != nil {
409 return nil, err
410 }
411 return dto.FromModel(np, releaseToPublish.Remark), nil
412}
413
414func (i *imlPublishModule) CheckPublish(ctx context.Context, serviceId string, releaseId string) (*dto.DiffOut, error) {
415 _, err := i.serviceService.Check(ctx, serviceId, asServer)

Callers

nothing calls this directly

Calls 8

checkPublishMethod · 0.95
FromModelFunction · 0.92
CheckMethod · 0.65
GetRunningMethod · 0.65
GetReleaseMethod · 0.65
DiffForLatestMethod · 0.65
CreateMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected