(ctx context.Context, project string, id string)
| 298 | } |
| 299 | |
| 300 | func (m *imlReleaseModule) Delete(ctx context.Context, project string, id string) error { |
| 301 | _, err := m.projectService.Check(ctx, project, projectRuleMustServer) |
| 302 | if err != nil { |
| 303 | return err |
| 304 | } |
| 305 | return m.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 306 | r, err := m.releaseService.GetRelease(ctx, id) |
| 307 | if err != nil { |
| 308 | return err |
| 309 | } |
| 310 | if r == nil { |
| 311 | return errors.New("release not found") |
| 312 | } |
| 313 | if r.Service != project { |
| 314 | return errors.New("project not match") |
| 315 | } |
| 316 | running, err := m.releaseService.GetRunning(ctx, project) |
| 317 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 318 | return err |
| 319 | } |
| 320 | if running != nil && running.UUID == id { |
| 321 | return errors.New("can not delete running release") |
| 322 | } |
| 323 | flow, err := m.publishService.GetLatest(ctx, id) |
| 324 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 325 | return err |
| 326 | } |
| 327 | if flow != nil { |
| 328 | if flow.Status == publish.StatusApply || flow.Status == publish.StatusAccept { |
| 329 | return errors.New("can not delete release in apply or approve flow") |
| 330 | } |
| 331 | } |
| 332 | return m.releaseService.DeleteRelease(ctx, id) |
| 333 | }) |
| 334 | |
| 335 | } |
| 336 | |
| 337 | func (m *imlReleaseModule) Preview(ctx context.Context, project string) (*dto.Release, *service_diff.Diff, bool, error) { |
| 338 | _, err := m.projectService.Check(ctx, project, projectRuleMustServer) |
nothing calls this directly
no test coverage detected