Skip to content

Commit

Permalink
fix: askx upgrade-project -> remove skill.json and other v1 artifacts (
Browse files Browse the repository at this point in the history
  • Loading branch information
Chih-Ying authored Apr 2, 2020
1 parent 2da4326 commit 936e197
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
25 changes: 18 additions & 7 deletions lib/commands/util/upgrade-project/hosted-skill-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');

const HostedSkillController = require('@src/controllers/hosted-skill-controller');
const SkillMetadataController = require('@src/controllers/skill-metadata-controller');
const CLiError = require('@src/exceptions/cli-error');
const CliError = require('@src/exceptions/cli-error');
const ResourcesConfig = require('@src/model/resources-config');
const AskResources = require('@src/model/resources-config/ask-resources');
const AskStates = require('@src/model/resources-config/ask-states');
Expand All @@ -27,13 +27,24 @@ function checkIfDevBranchClean(gitClient) {
gitClient.checkoutBranch('dev');
const statusOutput = gitClient.shortStatus();
if (statusOutput.toString()) {
throw new CLiError(`Commit the following files in the dev branch before upgrading project:\n${statusOutput}`);
throw new CliError(`Commit the following files in the dev branch before upgrading project:\n${statusOutput}`);
}
const countOutput = gitClient.countCommitDifference('origin/dev', 'dev');
const counter = countOutput.toString().replace(/\D/g, '');
if (stringUtils.isNonBlankString(counter) && counter !== '0') {
throw new CLiError('Upgrade project failed, as your dev branch is ahead of the remote.\nPlease follow the project upgrade instruction from '
+ 'https://github.com/alexa-labs/ask-cli/blob/develop/docs/Upgrade-Project-From-V1.md#upgrade-steps to change to ask-cli v2 structure.');
try {
_compareCommitsWithDev(gitClient, 'origin/dev');
_compareCommitsWithDev(gitClient, 'master');
} catch (error) {
throw error.message;
}
}

function _compareCommitsWithDev(gitClient, branch) {
const upgradeInstruction = 'Please follow the project upgrade instruction from '
+ 'https://github.com/alexa-labs/ask-cli/blob/develop/docs/Upgrade-Project-From-V1.md#upgrade-steps '
+ 'to clean your working branch before upgrading project.';
let diffCount = gitClient.countCommitDifference(branch, 'dev');
diffCount = diffCount.toString().replace(/\D/g, '');
if (stringUtils.isNonBlankString(diffCount) && diffCount !== '0') {
throw new CliError(`Upgrade project failed. Your branch is ahead of ${branch} by ${diffCount} commit(s), ${upgradeInstruction}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ describe('Commands upgrade-project test - hosted skill helper test', () => {

describe('# test helper method - checkIfDevBranchClean', () => {
let gitClient;
let commitDiffStub;
beforeEach(() => {
gitClient = new GitClient(TEST_PROJECT_PATH, TEST_VERBOSITY_OPTIONS);
commitDiffStub = sinon.stub(gitClient, 'countCommitDifference');
});

afterEach(() => {
Expand All @@ -52,24 +54,40 @@ describe('Commands upgrade-project test - hosted skill helper test', () => {
.throw(CliError, `Commit the following files in the dev branch before upgrading project:\n${TEST_OUTPUT}`);
});

it('| dev branch commits difference is not zero , expect error thrown', () => {
it('| origin branch commits difference is not zero , expect error thrown', () => {
// setup
sinon.stub(gitClient, 'checkoutBranch');
sinon.stub(gitClient, 'shortStatus').returns('');
sinon.stub(gitClient, 'countCommitDifference').returns('1');
commitDiffStub.onCall(0).returns('1');
commitDiffStub.onCall(1).returns('1');
// call & verify
expect(() => hostedSkillHelper.checkIfDevBranchClean(gitClient))
.throw(CliError, 'Upgrade project failed, as your dev branch is ahead of the remote.\n'
.throw('Upgrade project failed. Your branch is ahead of origin/dev by 1 commit(s), '
+ 'Please follow the project upgrade instruction from '
+ 'https://github.com/alexa-labs/ask-cli/blob/develop/docs/Upgrade-Project-From-V1.md#upgrade-steps '
+ 'to change to ask-cli v2 structure.');
+ 'to clean your working branch before upgrading project.');
});

it('| dev branch commits difference is zero , expect noe error thrown', () => {
it('| master branch commits difference is not zero , expect error thrown', () => {
// setup
sinon.stub(gitClient, 'checkoutBranch');
sinon.stub(gitClient, 'shortStatus').returns('');
sinon.stub(gitClient, 'countCommitDifference').returns('0');
commitDiffStub.onCall(0).returns('0');
commitDiffStub.onCall(1).returns('1');
// call & verify
expect(() => hostedSkillHelper.checkIfDevBranchClean(gitClient))
.throw('Upgrade project failed. Your branch is ahead of master by 1 commit(s), '
+ 'Please follow the project upgrade instruction from '
+ 'https://github.com/alexa-labs/ask-cli/blob/develop/docs/Upgrade-Project-From-V1.md#upgrade-steps '
+ 'to clean your working branch before upgrading project.');
});

it('| origin and master branch commits difference is zero , expect noe error thrown', () => {
// setup
sinon.stub(gitClient, 'checkoutBranch');
sinon.stub(gitClient, 'shortStatus').returns('');
commitDiffStub.onCall(0).returns('0');
commitDiffStub.onCall(1).returns('0');
// call
hostedSkillHelper.checkIfDevBranchClean(gitClient);
});
Expand Down

0 comments on commit 936e197

Please sign in to comment.