2018-04-09 14:04:22 -04:00
|
|
|
import axios from '../../lib/utils/axios_utils';
|
2019-09-11 05:06:33 -04:00
|
|
|
import Api from '~/api';
|
2017-03-17 13:30:32 -04:00
|
|
|
|
|
|
|
export default class PipelinesService {
|
|
|
|
/**
|
2018-04-09 14:04:22 -04:00
|
|
|
* 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-03-17 13:30:32 -04:00
|
|
|
constructor(root) {
|
|
|
|
if (root.indexOf('.json') === -1) {
|
2018-04-09 14:04:22 -04:00
|
|
|
this.endpoint = `${root}.json`;
|
2017-03-17 13:30:32 -04:00
|
|
|
} else {
|
2018-04-09 14:04:22 -04:00
|
|
|
this.endpoint = root;
|
2017-03-17 13:30:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 14:12:21 -04:00
|
|
|
getPipelines(data = {}) {
|
2017-03-24 07:49:18 -04:00
|
|
|
const { scope, page } = data;
|
2018-06-16 17:50:13 -04:00
|
|
|
const { CancelToken } = axios;
|
2018-04-10 10:30:08 -04:00
|
|
|
|
|
|
|
this.cancelationSource = CancelToken.source();
|
|
|
|
|
2018-04-09 14:04:22 -04:00
|
|
|
return axios.get(this.endpoint, {
|
|
|
|
params: { scope, page },
|
2018-04-10 10:30:08 -04:00
|
|
|
cancelToken: this.cancelationSource.token,
|
2018-04-09 14:04:22 -04:00
|
|
|
});
|
2017-03-17 13:30:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post request for all pipelines actions.
|
|
|
|
*
|
|
|
|
* @param {String} endpoint
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
2018-04-09 14:04:22 -04:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
2017-03-17 13:30:32 -04:00
|
|
|
postAction(endpoint) {
|
2018-04-09 14:04:22 -04:00
|
|
|
return axios.post(`${endpoint}.json`);
|
2017-03-17 13:30:32 -04:00
|
|
|
}
|
2019-09-11 05:06:33 -04:00
|
|
|
|
|
|
|
// eslint-disable-next-line class-methods-use-this
|
|
|
|
runMRPipeline({ projectId, mergeRequestId }) {
|
|
|
|
return Api.postMergeRequestPipeline(projectId, { mergeRequestId });
|
|
|
|
}
|
2017-03-17 13:30:32 -04:00
|
|
|
}
|