(ctx context.Context, project string)
| 234 | } |
| 235 | |
| 236 | func (m *imlReleaseModule) List(ctx context.Context, project string) ([]*dto.Release, error) { |
| 237 | _, err := m.projectService.Check(ctx, project, projectRuleMustServer) |
| 238 | if err != nil { |
| 239 | return nil, err |
| 240 | } |
| 241 | list, err := m.releaseService.List(ctx, project) |
| 242 | if err != nil { |
| 243 | return nil, err |
| 244 | } |
| 245 | running, err := m.releaseService.GetRunning(ctx, project) |
| 246 | if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { |
| 247 | return nil, err |
| 248 | } |
| 249 | |
| 250 | releaseIds := utils.SliceToSlice(list, func(s *release.Release) string { |
| 251 | return s.UUID |
| 252 | }) |
| 253 | flows, err := m.publishService.Latest(ctx, releaseIds...) |
| 254 | if err != nil { |
| 255 | return nil, err |
| 256 | } |
| 257 | flowMap := utils.SliceToMap(flows, func(s *publish.Publish) string { |
| 258 | return s.Release |
| 259 | }) |
| 260 | |
| 261 | return utils.SliceToSlice(list, func(s *release.Release) *dto.Release { |
| 262 | |
| 263 | r := &dto.Release{ |
| 264 | Id: s.UUID, |
| 265 | Service: auto.UUID(s.Service), |
| 266 | Version: s.Version, |
| 267 | Remark: s.Remark, |
| 268 | Status: dto.StatusNone, |
| 269 | CanRollback: false, |
| 270 | CanDelete: true, |
| 271 | Creator: auto.UUID(s.Creator), |
| 272 | CreateTime: auto.TimeLabel(s.CreateAt), |
| 273 | } |
| 274 | |
| 275 | if running != nil && running.UUID == s.UUID { |
| 276 | r.Status = dto.StatusRunning |
| 277 | r.CanRollback = true |
| 278 | r.CanDelete = false |
| 279 | } |
| 280 | flow, has := flowMap[s.UUID] |
| 281 | if has { |
| 282 | r.FlowId = flow.Id |
| 283 | |
| 284 | if flow.Status == publish.StatusApply { |
| 285 | r.Status = dto.StatusApply |
| 286 | r.CanDelete = false |
| 287 | } else if flow.Status == publish.StatusAccept { |
| 288 | |
| 289 | r.Status = dto.StatusAccept |
| 290 | r.CanDelete = false |
| 291 | } else if flow.Status == publish.StatusPublishError { |
| 292 | r.Status = dto.StatusError |
| 293 | r.CanDelete = false |
nothing calls this directly
no test coverage detected