Skip to content

Commit 2c3657f

Browse files
SAAS-4712 #time 2h 10m Made some small refactoring (#378)
* SAAS-4712 #time 2h 10m Made some small refactoring - moved checking existing project to the helper. * rebuild Co-authored-by: Denis Melnik <58072595+denis-codefresh@users.noreply.github.com>
1 parent a3ca46a commit 2c3657f

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

lib/interface/cli/commands/project/create.cmd.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const CFError = require('cf-errors');
33
const _ = require('lodash');
44
const { sdk } = require('../../../../logic');
55
const createRoot = require('../root/create.cmd');
6-
const { prepareKeyValueObjectsFromCLIEnvOption, ignoreHttpError } = require('../../helpers/general');
6+
const { checkOrProjectExists } = require('../../helpers/validation');
7+
const { prepareKeyValueObjectsFromCLIEnvOption } = require('../../helpers/general');
78

89
const command = new Command({
910
command: 'project <name>',
@@ -60,11 +61,7 @@ const command = new Command({
6061
variable.encrypted = true;
6162
});
6263

63-
const existing = await sdk.projects.getByName({ name: projectName }).catch(ignoreHttpError); // ignore not found error
64-
if (existing) {
65-
throw new CFError(`Project already exists: "${projectName}"`);
66-
}
67-
64+
await checkOrProjectExists(projectName);
6865
await sdk.projects.create({ projectName, tags, variables });
6966
console.log(`Project: "${projectName}" created`);
7067
},

lib/interface/cli/helpers/validation.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const _ = require('lodash');
22
const yaml = require('js-yaml');
3-
const { readFile } = require('./general');
3+
const { readFile, ignoreHttpError } = require('./general');
44
const { sdk } = require('../../../logic');
5+
const CFError = require('cf-errors');
56

67

78
function _buildFinalMessage(baseMessage, validationResult) {
@@ -46,7 +47,15 @@ async function validatePipelineYaml(filename, fileContent) {
4647
return { valid: !!result.valid, message };
4748
}
4849

50+
async function checkOrProjectExists(projectName) {
51+
const existing = await sdk.projects.getByName({ name: projectName }).catch(ignoreHttpError); // ignore not found error
52+
if (existing) {
53+
throw new CFError(`Project already exists: "${projectName}"`);
54+
}
55+
}
56+
4957
module.exports = {
5058
validatePipelineSpec,
5159
validatePipelineYaml,
60+
checkOrProjectExists,
5261
};

lib/logic/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ const sdk = require('./sdk');
33
module.exports = {
44
sdk,
55
};
6+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.39.0",
3+
"version": "0.39.1",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)