summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/modules/pipelines/actions.js
blob: b5d78b381ea3bff4253c038e4dba7aea5d799579 (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
54
55
56
57
58
59
60
import axios from 'axios';
import { __ } from '../../../../locale';
import Api from '../../../../api';
import flash from '../../../../flash';
import * as types from './mutation_types';

export const requestLatestPipeline = ({ commit }) => commit(types.REQUEST_LATEST_PIPELINE);
export const receiveLatestPipelineError = ({ commit }) => {
  flash(__('There was an error loading latest pipeline'));
  commit(types.RECEIVE_LASTEST_PIPELINE_ERROR);
};
export const receiveLatestPipelineSuccess = ({ commit }, pipeline) =>
  commit(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, pipeline);

export const fetchLatestPipeline = ({ dispatch, rootState }, sha) => {
  dispatch('requestLatestPipeline');

  return Api.pipelines(rootState.currentProjectId, { sha, per_page: '1' })
    .then(({ data }) => {
      dispatch('receiveLatestPipelineSuccess', data.pop());
    })
    .catch(() => dispatch('receiveLatestPipelineError'));
};

export const requestStages = ({ commit }) => commit(types.REQUEST_STAGES);
export const receiveStagesError = ({ commit }) => {
  flash(__('There was an error loading job stages'));
  commit(types.RECEIVE_STAGES_ERROR);
};
export const receiveStagesSuccess = ({ commit }, data) =>
  commit(types.RECEIVE_STAGES_SUCCESS, data);

export const fetchStages = ({ dispatch, state, rootState }) => {
  dispatch('requestStages');

  Api.pipelineJobs(rootState.currentProjectId, state.latestPipeline.id)
    .then(({ data }) => dispatch('receiveStagesSuccess', data))
    .catch(() => dispatch('receiveStagesError'));
};

export const requestJobs = ({ commit }, id) => commit(types.REQUEST_JOBS, id);
export const receiveJobsError = ({ commit }, id) => {
  flash(__('There was an error loading jobs'));
  commit(types.RECEIVE_JOBS_ERROR, id);
};
export const receiveJobsSuccess = ({ commit }, { id, data }) =>
  commit(types.RECEIVE_JOBS_SUCCESS, { id, data });

export const fetchJobs = ({ dispatch }, stage) => {
  dispatch('requestJobs', stage.id);

  axios
    .get(stage.dropdown_path)
    .then(({ data }) => {
      dispatch('receiveJobsSuccess', { id: stage.id, data });
    })
    .catch(() => dispatch('receiveJobsError', stage.id));
};

export default () => {};