Skip to content

Commit

Permalink
fix: MERC-8592 Check if a theme is deleted before pushing a new theme
Browse files Browse the repository at this point in the history
  • Loading branch information
powerwlsl committed Jun 2, 2022
1 parent 887a2f8 commit ce5b6cc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/stencil-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function stencilPush(options = {}, callback) {
utils.notifyUserOfThemeLimitReachedIfNecessary,
utils.promptUserToDeleteThemesIfNecessary,
utils.deleteThemesIfNecessary,
utils.checkIfDeletionIsComplete(),
utils.uploadBundleAgainIfNecessary,
utils.notifyUserOfThemeUploadCompletion,
utils.pollForJobCompletion((data) => ({ themeId: data.theme_id })),
Expand Down
42 changes: 42 additions & 0 deletions lib/stencil-push.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,48 @@ utils.deleteThemesIfNecessary = async (options) => {
return options;
};

utils.checkIfDeletionIsComplete = () => {
return async.retryable(
{
interval: 1000,
errorFilter: (err) => {
if (err.message === 'ThemeStillExists') {
console.log(`${'warning'.yellow} -- Theme still exists;Retrying ...`);
return true;
}
return false;
},
times: 5,
},
utils.checkIfThemeIsDeleted(),
);
};

utils.checkIfThemeIsDeleted = () => async (options) => {
const {
themeLimitReached,
config: { accessToken },
storeHash,
themeIdsToDelete,
} = options;

if (!themeLimitReached) {
return options;
}

const apiHost = options.apiHost || options.config.apiHost;

const result = await themeApiClient.getThemes({ accessToken, apiHost, storeHash });

const themeStillExists = result.some((theme) => themeIdsToDelete.includes(theme.uuid));

if (themeStillExists) {
throw new Error('ThemeStillExists');
}

return { ...options, ...result };
};

utils.uploadBundleAgainIfNecessary = async (options) => {
if (!options.themeLimitReached) {
return options;
Expand Down

0 comments on commit ce5b6cc

Please sign in to comment.