gitlab-org--gitlab-foss/app/assets/javascripts/pipelines/services/pipelines_service.js
Filipa Lacerda 48b98b5898 Enables Run Pipeline button to be rendered
In the Merge Request view, under pipelines tab
the user can see a run pipeline button

Adds axios post request to button click

Adds the logic to handle the user click,
refresh the table and disable the button while thee
request is being made

Updates UI for desktop and mobile

Adds specs
Regenerates potfile

Follow-up after review

Uses .finally to avoid code repetition
2019-09-11 09:06:33 +00:00

48 lines
1.2 KiB
JavaScript

import axios from '../../lib/utils/axios_utils';
import Api from '~/api';
export default class PipelinesService {
/**
* 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
*/
constructor(root) {
if (root.indexOf('.json') === -1) {
this.endpoint = `${root}.json`;
} else {
this.endpoint = root;
}
}
getPipelines(data = {}) {
const { scope, page } = data;
const { CancelToken } = axios;
this.cancelationSource = CancelToken.source();
return axios.get(this.endpoint, {
params: { scope, page },
cancelToken: this.cancelationSource.token,
});
}
/**
* Post request for all pipelines actions.
*
* @param {String} endpoint
* @return {Promise}
*/
// eslint-disable-next-line class-methods-use-this
postAction(endpoint) {
return axios.post(`${endpoint}.json`);
}
// eslint-disable-next-line class-methods-use-this
runMRPipeline({ projectId, mergeRequestId }) {
return Api.postMergeRequestPipeline(projectId, { mergeRequestId });
}
}