debian-mirror-gitlab/app/assets/javascripts/pipelines/services/pipelines_service.js

43 lines
994 B
JavaScript
Raw Normal View History

2018-10-15 14:42:47 +05:30
import axios from '../../lib/utils/axios_utils';
2017-08-17 22:00:37 +05:30
export default class PipelinesService {
/**
2018-10-15 14:42:47 +05:30
* 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
*/
2017-08-17 22:00:37 +05:30
constructor(root) {
if (root.indexOf('.json') === -1) {
2018-10-15 14:42:47 +05:30
this.endpoint = `${root}.json`;
2017-08-17 22:00:37 +05:30
} else {
2018-10-15 14:42:47 +05:30
this.endpoint = root;
2017-08-17 22:00:37 +05:30
}
}
getPipelines(data = {}) {
const { scope, page } = data;
2018-11-08 19:23:39 +05:30
const { CancelToken } = axios;
2018-10-15 14:42:47 +05:30
this.cancelationSource = CancelToken.source();
return axios.get(this.endpoint, {
params: { scope, page },
cancelToken: this.cancelationSource.token,
});
2017-08-17 22:00:37 +05:30
}
/**
* Post request for all pipelines actions.
*
* @param {String} endpoint
* @return {Promise}
*/
2018-10-15 14:42:47 +05:30
// eslint-disable-next-line class-methods-use-this
2017-08-17 22:00:37 +05:30
postAction(endpoint) {
2018-10-15 14:42:47 +05:30
return axios.post(`${endpoint}.json`);
2017-08-17 22:00:37 +05:30
}
}