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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-04 20:38:33 +05:30
import Api from '~/api';
2022-06-21 17:19:12 +05:30
import axios from '~/lib/utils/axios_utils';
2020-06-23 00:09:42 +05:30
import { validateParams } from '../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 = {}) {
2020-06-23 00:09:42 +05:30
const { scope, page } = data;
2018-11-08 19:23:39 +05:30
const { CancelToken } = axios;
2018-10-15 14:42:47 +05:30
2020-06-23 00:09:42 +05:30
const queryParams = { scope, page, ...validateParams(data) };
2020-05-24 23:13:21 +05:30
2018-10-15 14:42:47 +05:30
this.cancelationSource = CancelToken.source();
return axios.get(this.endpoint, {
2020-05-24 23:13:21 +05:30
params: queryParams,
2018-10-15 14:42:47 +05:30
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
}
2019-12-04 20:38:33 +05:30
// eslint-disable-next-line class-methods-use-this
runMRPipeline({ projectId, mergeRequestId }) {
return Api.postMergeRequestPipeline(projectId, { mergeRequestId });
}
2017-08-17 22:00:37 +05:30
}