pipelines_service.js 1002 字节
Newer Older
1
import axios from '../../lib/utils/axios_utils';
2 3 4

export default class PipelinesService {
  /**
5 6 7 8 9 10 11
   * 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
   */
12 13
  constructor(root) {
    if (root.indexOf('.json') === -1) {
14
      this.endpoint = `${root}.json`;
15
    } else {
16
      this.endpoint = root;
17 18 19
    }
  }

20
  getPipelines(data = {}) {
21
    const { scope, page } = data;
22 23 24 25
    const CancelToken = axios.CancelToken;

    this.cancelationSource = CancelToken.source();

26 27
    return axios.get(this.endpoint, {
      params: { scope, page },
28
      cancelToken: this.cancelationSource.token,
29
    });
30 31 32 33 34 35 36 37
  }

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