summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/modules/pipelines/mutations.js
blob: 2b16e57b3863d2cff64d0a9f3a7e115c4f305f3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable no-param-reassign */
import * as types from './mutation_types';

export default {
  [types.REQUEST_LATEST_PIPELINE](state) {
    state.isLoadingPipeline = true;
  },
  [types.RECEIVE_LASTEST_PIPELINE_ERROR](state) {
    state.isLoadingPipeline = false;
  },
  [types.RECEIVE_LASTEST_PIPELINE_SUCCESS](state, pipeline) {
    state.isLoadingPipeline = false;

    if (pipeline) {
      state.latestPipeline = {
        id: pipeline.id,
        status: pipeline.status,
      };
    }
  },
  [types.REQUEST_JOBS](state) {
    state.isLoadingJobs = true;
  },
  [types.RECEIVE_JOBS_ERROR](state) {
    state.isLoadingJobs = false;
  },
  [types.RECEIVE_JOBS_SUCCESS](state, jobs) {
    state.isLoadingJobs = false;

    state.stages = jobs.reduce((acc, job) => {
      let stage = acc.find(s => s.title === job.stage);

      if (!stage) {
        stage = {
          title: job.stage,
          jobs: [],
        };

        acc.push(stage);
      }

      stage.jobs = stage.jobs.concat({
        id: job.id,
        name: job.name,
        status: job.status,
        stage: job.stage,
        duration: job.duration,
      });

      return acc;
    }, state.stages);
  },
};