summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/services/pipelines_service.js
blob: 3ec563c95bb328444cb0f11d0c9e85bc2304bd1a (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
import Api from '~/api';
import axios from '~/lib/utils/axios_utils';
import { validateParams } from '../utils';

export default class PipelinesService {
  /**
   * Commits and merge request endpoints need to be requested with `.json`.
   *
   * The url provided to request the pipelines in the new merge request
   * page already has `.json`.
   *
   * @param  {String} root
   */
  constructor(root) {
    if (root.indexOf('.json') === -1) {
      this.endpoint = `${root}.json`;
    } else {
      this.endpoint = root;
    }
  }

  getPipelines(data = {}) {
    const { scope, page } = data;
    const { CancelToken } = axios;

    const queryParams = { scope, page, ...validateParams(data) };

    this.cancelationSource = CancelToken.source();

    return axios.get(this.endpoint, {
      params: queryParams,
      cancelToken: this.cancelationSource.token,
    });
  }

  /**
   * Post request for all pipelines actions.
   *
   * @param  {String} endpoint
   * @return {Promise}
   */
  // eslint-disable-next-line class-methods-use-this
  postAction(endpoint) {
    return axios.post(`${endpoint}.json`);
  }

  // eslint-disable-next-line class-methods-use-this
  runMRPipeline({ projectId, mergeRequestId }) {
    return Api.postMergeRequestPipeline(projectId, { mergeRequestId });
  }
}