diff options
Diffstat (limited to 'app/assets/javascripts/releases')
5 files changed, 28 insertions, 33 deletions
diff --git a/app/assets/javascripts/releases/components/evidence_block.vue b/app/assets/javascripts/releases/components/evidence_block.vue index 78831ceefe9..6d415471b14 100644 --- a/app/assets/javascripts/releases/components/evidence_block.vue +++ b/app/assets/javascripts/releases/components/evidence_block.vue @@ -1,6 +1,6 @@ <script> import { GlLink, GlTooltipDirective, GlIcon } from '@gitlab/ui'; -import dateFormat from 'dateformat'; +import dateFormat from '~/lib/dateformat'; import { getTimeago } from '~/lib/utils/datetime_utility'; import { truncateSha } from '~/lib/utils/text_utility'; import { __, sprintf } from '~/locale'; diff --git a/app/assets/javascripts/releases/stores/modules/edit_new/actions.js b/app/assets/javascripts/releases/stores/modules/edit_new/actions.js index a71a8125d65..669e5928143 100644 --- a/app/assets/javascripts/releases/stores/modules/edit_new/actions.js +++ b/app/assets/javascripts/releases/stores/modules/edit_new/actions.js @@ -16,6 +16,8 @@ import { import * as types from './mutation_types'; +class GraphQLError extends Error {} + export const initializeRelease = ({ commit, dispatch, state }) => { if (state.isExistingRelease) { // When editing an existing release, @@ -110,35 +112,35 @@ export const saveRelease = ({ commit, dispatch, state }) => { * * @param {Object} gqlResponse The response object returned by the GraphQL client * @param {String} mutationName The name of the mutation that was executed - * @param {String} messageIfError An message to build into the error object if something went wrong */ -const checkForErrorsAsData = (gqlResponse, mutationName, messageIfError) => { +const checkForErrorsAsData = (gqlResponse, mutationName) => { const allErrors = gqlResponse.data[mutationName].errors; if (allErrors.length > 0) { - const allErrorMessages = JSON.stringify(allErrors); - throw new Error(`${messageIfError}: ${allErrorMessages}`); + throw new GraphQLError(allErrors[0]); } }; -export const createRelease = async ({ commit, dispatch, state, getters }) => { +export const createRelease = async ({ commit, dispatch, getters }) => { try { const response = await gqClient.mutate({ mutation: createReleaseMutation, variables: getters.releaseCreateMutatationVariables, }); - checkForErrorsAsData( - response, - 'releaseCreate', - `Something went wrong while creating a new release with projectPath "${state.projectPath}" and tagName "${state.release.tagName}"`, - ); + checkForErrorsAsData(response, 'releaseCreate'); dispatch('receiveSaveReleaseSuccess', response.data.releaseCreate.release.links.selfUrl); } catch (error) { commit(types.RECEIVE_SAVE_RELEASE_ERROR, error); - createFlash({ - message: s__('Release|Something went wrong while creating a new release.'), - }); + if (error instanceof GraphQLError) { + createFlash({ + message: error.message, + }); + } else { + createFlash({ + message: s__('Release|Something went wrong while creating a new release.'), + }); + } } }; @@ -146,7 +148,7 @@ export const createRelease = async ({ commit, dispatch, state, getters }) => { * Deletes a single release link. * Throws an error if any network or validation errors occur. */ -const deleteReleaseLinks = async ({ state, id }) => { +const deleteReleaseLinks = async ({ id }) => { const deleteResponse = await gqClient.mutate({ mutation: deleteReleaseAssetLinkMutation, variables: { @@ -154,11 +156,7 @@ const deleteReleaseLinks = async ({ state, id }) => { }, }); - checkForErrorsAsData( - deleteResponse, - 'releaseAssetLinkDelete', - `Something went wrong while deleting release asset link for release with projectPath "${state.projectPath}", tagName "${state.tagName}", and link id "${id}"`, - ); + checkForErrorsAsData(deleteResponse, 'releaseAssetLinkDelete'); }; /** @@ -180,11 +178,7 @@ const createReleaseLink = async ({ state, link }) => { }, }); - checkForErrorsAsData( - createResponse, - 'releaseAssetLinkCreate', - `Something went wrong while creating a release asset link for release with projectPath "${state.projectPath}" and tagName "${state.tagName}"`, - ); + checkForErrorsAsData(createResponse, 'releaseAssetLinkCreate'); }; export const updateRelease = async ({ commit, dispatch, state, getters }) => { @@ -210,11 +204,7 @@ export const updateRelease = async ({ commit, dispatch, state, getters }) => { variables: getters.releaseUpdateMutatationVariables, }); - checkForErrorsAsData( - updateReleaseResponse, - 'releaseUpdate', - `Something went wrong while updating release with projectPath "${state.projectPath}" and tagName "${state.tagName}"`, - ); + checkForErrorsAsData(updateReleaseResponse, 'releaseUpdate'); // Delete all links currently associated with this Release await Promise.all( @@ -266,7 +256,7 @@ export const deleteRelease = ({ commit, getters, dispatch, state }) => { mutation: deleteReleaseMutation, variables: getters.releaseDeleteMutationVariables, }) - .then((response) => checkForErrorsAsData(response, 'releaseDelete', '')) + .then((response) => checkForErrorsAsData(response, 'releaseDelete')) .then(() => { window.sessionStorage.setItem( deleteReleaseSessionKey(state.projectPath), diff --git a/app/assets/javascripts/releases/stores/modules/edit_new/getters.js b/app/assets/javascripts/releases/stores/modules/edit_new/getters.js index 62d6bd42d51..ccca9ca8250 100644 --- a/app/assets/javascripts/releases/stores/modules/edit_new/getters.js +++ b/app/assets/javascripts/releases/stores/modules/edit_new/getters.js @@ -130,7 +130,7 @@ export const releaseUpdateMutatationVariables = (state, getters) => { projectPath: state.projectPath, tagName: state.release.tagName, name, - releasedAt: state.release.releasedAt, + releasedAt: getters.releasedAtChanged ? state.release.releasedAt : null, description: state.includeTagNotes ? getters.formattedReleaseNotes : state.release.description, @@ -167,3 +167,6 @@ export const formattedReleaseNotes = ({ includeTagNotes, release: { description includeTagNotes && tagNotes ? `${description}\n\n### ${s__('Releases|Tag message')}\n\n${tagNotes}\n` : description; + +export const releasedAtChanged = ({ originalReleasedAt, release }) => + originalReleasedAt !== release.releasedAt; diff --git a/app/assets/javascripts/releases/stores/modules/edit_new/mutations.js b/app/assets/javascripts/releases/stores/modules/edit_new/mutations.js index ea794f91f66..34361f84a5a 100644 --- a/app/assets/javascripts/releases/stores/modules/edit_new/mutations.js +++ b/app/assets/javascripts/releases/stores/modules/edit_new/mutations.js @@ -14,7 +14,7 @@ export default { description: '', milestones: [], groupMilestones: [], - releasedAt: new Date(), + releasedAt: state.originalReleasedAt, assets: { links: [], }, @@ -29,6 +29,7 @@ export default { state.isFetchingRelease = false; state.release = data; state.originalRelease = Object.freeze(cloneDeep(state.release)); + state.originalReleasedAt = state.originalRelease.releasedAt; }, [types.RECEIVE_RELEASE_ERROR](state, error) { state.fetchError = error; diff --git a/app/assets/javascripts/releases/stores/modules/edit_new/state.js b/app/assets/javascripts/releases/stores/modules/edit_new/state.js index cb447cf9aaf..11a2f9df59b 100644 --- a/app/assets/javascripts/releases/stores/modules/edit_new/state.js +++ b/app/assets/javascripts/releases/stores/modules/edit_new/state.js @@ -61,4 +61,5 @@ export default ({ tagNotes: '', includeTagNotes: false, existingRelease: null, + originalReleasedAt: new Date(), }); |