2019-02-15 15:39:39 +05:30
|
|
|
import * as types from './mutation_types';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { __ } from '~/locale';
|
|
|
|
import api from '~/api';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Commits a mutation to update the state while the main endpoint is being requested.
|
|
|
|
*/
|
|
|
|
export const requestReleases = ({ commit }) => commit(types.REQUEST_RELEASES);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the main endpoint.
|
|
|
|
* Will dispatch requestNamespace action before starting the request.
|
2019-05-18 00:54:41 +05:30
|
|
|
* Will dispatch receiveNamespaceSuccess if the request is successful
|
2019-02-15 15:39:39 +05:30
|
|
|
* Will dispatch receiveNamesapceError if the request returns an error
|
|
|
|
*
|
|
|
|
* @param {String} projectId
|
|
|
|
*/
|
|
|
|
export const fetchReleases = ({ dispatch }, projectId) => {
|
|
|
|
dispatch('requestReleases');
|
|
|
|
|
|
|
|
api
|
|
|
|
.releases(projectId)
|
|
|
|
.then(({ data }) => dispatch('receiveReleasesSuccess', data))
|
|
|
|
.catch(() => dispatch('receiveReleasesError'));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const receiveReleasesSuccess = ({ commit }, data) =>
|
|
|
|
commit(types.RECEIVE_RELEASES_SUCCESS, data);
|
|
|
|
|
|
|
|
export const receiveReleasesError = ({ commit }) => {
|
|
|
|
commit(types.RECEIVE_RELEASES_ERROR);
|
2019-05-18 00:54:41 +05:30
|
|
|
createFlash(__('An error occurred while fetching the releases. Please try again.'));
|
2019-02-15 15:39:39 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma tests
|
|
|
|
export default () => {};
|