summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/commit/pipelines/pipelines_service.js
blob: 8ae98f9bf978fd95d197109f4c80e054227c2561 (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
/* globals Vue */
/* eslint-disable no-unused-vars, no-param-reassign */

/**
 * Pipelines service.
 *
 * Used to fetch the data used to render the pipelines table.
 * Uses Vue.Resource
 */
class PipelinesService {

  /**
   * FIXME: The url provided to request the pipelines in the new merge request
   * page already has `.json`.
   * This should be fixed when the endpoint is improved.
   *
   * @param  {String} root
   */
  constructor(root) {
    let endpoint;

    if (root.indexOf('.json') === -1) {
      endpoint = `${root}.json`;
    } else {
      endpoint = root;
    }
    this.pipelines = Vue.resource(endpoint);
  }

  /**
   * Given the root param provided when the class is initialized, will
   * make a GET request.
   *
   * @return {Promise}
   */
  all() {
    return this.pipelines.get();
  }
}

window.gl = window.gl || {};
gl.commits = gl.commits || {};
gl.commits.pipelines = gl.commits.pipelines || {};
gl.commits.pipelines.PipelinesService = PipelinesService;