diff --git a/.eslintrc.js b/.eslintrc.js index 4d1baef30..9ffcdfc29 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,17 @@ module.exports = { - "extends": "airbnb-base", - "rules": { - "indent": ["error", 4], + 'plugins': [ + 'mocha' + ], + 'extends': 'airbnb-base', + 'rules': { + 'indent': ['error', 4, { 'SwitchCase': 1 }], + 'no-underscore-dangle': [0], + 'max-len': ['error', { + 'code': 140, + 'ignoreComments': true + }], + }, + 'env': { + 'mocha': true, } -}; \ No newline at end of file +}; diff --git a/codefresh.yml b/codefresh.yml index d5d3fcc82..3507a4633 100644 --- a/codefresh.yml +++ b/codefresh.yml @@ -8,12 +8,12 @@ steps: commands: - yarn install --frozen-lockfile -# eslint: -# title: 'Running linting logic' -# image: codefresh/node-tester-image:8.8.0 -# commands: -# - yarn lint -# + eslint: + title: 'Running linting logic' + image: codefresh/node-tester-image:8.8.0 + commands: + - yarn eslint + # unit-tests: # title: 'Running unit tests' # image: codefresh/node-tester-image:8.8.0 @@ -48,4 +48,4 @@ steps: - NPM_TOKEN=${{NPM_TOKEN}} npm run ci-publish when: branch: - only: [ master ] \ No newline at end of file + only: [ master ] diff --git a/lib/logic/api/composition.js b/lib/logic/api/composition.js index dfe4d8731..9dc890d5b 100644 --- a/lib/logic/api/composition.js +++ b/lib/logic/api/composition.js @@ -1,17 +1,15 @@ -const _ = require('lodash'); -const CFError = require('cf-errors'); +const _ = require('lodash'); +const CFError = require('cf-errors'); // eslint-disable-line const { sendHttpRequest } = require('./helper'); -const Composition = require('../entities/Composition'); +const Composition = require('../entities/Composition'); -const _extractFieldsForCompositionwEntity = (composition) => { - return { - id: composition._id, - name: composition.name, - isAdvanced: composition.isAdvanced, - created: composition.created, - }; -}; +const _extractFieldsForCompositionwEntity = composition => ({ + id: composition._id, + name: composition.name, + isAdvanced: composition.isAdvanced, + created: composition.created, +}); const createComposition = async (data) => { @@ -21,7 +19,7 @@ const createComposition = async (data) => { body: data, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; const replaceById = async (id, data) => { @@ -33,10 +31,10 @@ const replaceById = async (id, data) => { body, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; -//TODO:need to add to cf-api +// TODO:need to add to cf-api const applyById = async (id, data) => { const body = data; @@ -46,7 +44,7 @@ const applyById = async (id, data) => { body, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; const getCompositionByIdentifier = async (id) => { @@ -83,11 +81,10 @@ const deleteCompositionById = async (id) => { method: 'DELETE', }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; - module.exports = { createComposition, replaceById, @@ -95,4 +92,4 @@ module.exports = { getCompositionByIdentifier, getCompositions, deleteCompositionById, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/context.js b/lib/logic/api/context.js index 9865100e1..3458964b7 100644 --- a/lib/logic/api/context.js +++ b/lib/logic/api/context.js @@ -1,17 +1,15 @@ -const _ = require('lodash'); -const CFError = require('cf-errors'); +const _ = require('lodash'); +const CFError = require('cf-errors'); // eslint-disable-line const { sendHttpRequest } = require('./helper'); -const Context = require('../entities/Context'); - -const _extractFieldsForContextEntity = (context) => { - return { - apiVersion: context.apiVersion, - kind: context.kind, - name: context.metadata.name, - owner: context.owner, - type: context.spec.type, - }; -}; +const Context = require('../entities/Context'); + +const _extractFieldsForContextEntity = context => ({ + apiVersion: context.apiVersion, + kind: context.kind, + name: context.metadata.name, + owner: context.owner, + type: context.spec.type, +}); const createContext = async (data) => { @@ -21,7 +19,7 @@ const createContext = async (data) => { body: data, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; const replaceByName = async (name, data) => { @@ -33,7 +31,7 @@ const replaceByName = async (name, data) => { body, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; const applyByName = async (name, data) => { @@ -45,7 +43,7 @@ const applyByName = async (name, data) => { body, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; const getContextByName = async (name, owner) => { @@ -85,7 +83,7 @@ const deleteContextByName = async (name, owner) => { body: { owner }, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; module.exports = { @@ -95,4 +93,4 @@ module.exports = { deleteContextByName, replaceByName, applyByName, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/environment.js b/lib/logic/api/environment.js index 0233504d3..55c1805d8 100644 --- a/lib/logic/api/environment.js +++ b/lib/logic/api/environment.js @@ -1,15 +1,13 @@ -const _ = require('lodash'); -const CFError = require('cf-errors'); +const _ = require('lodash'); +const CFError = require('cf-errors'); // eslint-disable-line const { sendHttpRequest } = require('./helper'); -const Environment = require('../entities/Environment'); +const Environment = require('../entities/Environment'); -const _extractFieldsForEnvironmentEntity = (environment) => { - return { - id: environment._id, - status: environment.creationStatus, - name: environment.name, - }; -}; +const _extractFieldsForEnvironmentEntity = environment => ({ + id: environment._id, + status: environment.creationStatus, + name: environment.name, +}); const getEnvironmentById = async (id) => { const endcodeUri = encodeURIComponent(id); @@ -46,7 +44,7 @@ const deleteEnvironment = async (id) => { method: 'GET', }; - return await sendHttpRequest(userOptions); + return sendHttpRequest(userOptions); }; @@ -54,4 +52,4 @@ module.exports = { getEnvironmentById, getEnvironments, deleteEnvironment, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/helper.js b/lib/logic/api/helper.js index 002e7ba00..4b1d48f7f 100644 --- a/lib/logic/api/helper.js +++ b/lib/logic/api/helper.js @@ -1,23 +1,23 @@ const debug = require('debug')('codefresh:http'); -const rp = require('request-promise'); -const _ = require('lodash'); +const rp = require('request-promise'); +const _ = require('lodash'); const sendHttpRequest = async (httpOptions, authContext) => { let finalAuthContext; if (!authContext) { - const authManager = require('../auth').manager; - finalAuthContext = authManager.getCurrentContext(); + const authManager = require('../auth').manager; // eslint-disable-line + finalAuthContext = authManager.getCurrentContext(); } else { finalAuthContext = authContext; } const finalOptions = _.assignIn(httpOptions, finalAuthContext.prepareHttpOptions(), { json: true }); - debug(`Sending http request:\n%O`, finalOptions); + debug('Sending http request:\n%O', finalOptions); const response = await rp(finalOptions); - debug(`Response:\n%O`, response); + debug('Response:\n%O', response); return response; }; module.exports = { sendHttpRequest, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/image.js b/lib/logic/api/image.js index ded25ed2a..11a67e506 100644 --- a/lib/logic/api/image.js +++ b/lib/logic/api/image.js @@ -1,21 +1,19 @@ -const _ = require('lodash'); -const CFError = require('cf-errors'); +const _ = require('lodash'); +const CFError = require('cf-errors'); const { sendHttpRequest } = require('./helper'); -const filesize = require('filesize'); -const moment = require('moment'); -const Image = require('../entities/Image'); - - -const _extractFieldsForImageEntity = (image, tag) => { - return { - name: image.imageDisplayName, - tag: tag.tag, - image_id: image.internalImageId.substring(0, 12), - created: moment(tag.created).fromNow(), - size: filesize(image.size), - pull: `${tag.registry}/${tag.repository}:${tag.tag}`, - }; -}; +const filesize = require('filesize'); +const moment = require('moment'); +const Image = require('../entities/Image'); + + +const _extractFieldsForImageEntity = (image, tag) => ({ + name: image.imageDisplayName, + tag: tag.tag, + image_id: image.internalImageId.substring(0, 12), + created: moment(tag.created).fromNow(), + size: filesize(image.size), + pull: `${tag.registry}/${tag.repository}:${tag.tag}`, +}); const getAll = async (options) => { @@ -27,7 +25,7 @@ const getAll = async (options) => { }; if (!options.volumeImages) { - qs.metadata['cf_volume'] = false; + qs.metadata.cf_volume = false; } if (options.sha) { @@ -62,12 +60,12 @@ const getImageById = async (imageId) => { url: `/api/images/${encodeURIComponent(imageId)}`, method: 'GET', }; - const image = await sendHttpRequest(options); + const image = await sendHttpRequest(options); if (_.isEmpty(image)) { throw new CFError(`Error from server (NotFound): Image ${imageId} not found`); } const res = []; - let data = {}; + let data = {}; _.forEach(image.tags, (tag) => { data = _extractFieldsForImageEntity(image, tag); res.push(new Image(data)); @@ -106,7 +104,7 @@ const annotateImage = async (dockerImageId, annotations) => { body: annotations, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; module.exports = { @@ -114,4 +112,4 @@ module.exports = { getDockerImageId, getAll, getImageById, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/index.js b/lib/logic/api/index.js index 802ca2c2c..48d687d94 100644 --- a/lib/logic/api/index.js +++ b/lib/logic/api/index.js @@ -1,12 +1,12 @@ -'use strict'; -const user = require('./user'); -const pipeline = require('./pipeline'); -const context = require('./context'); -const image = require('./image'); -const composition = require('./composition'); -const environment = require('./environment'); -const workflow = require('./workflow'); + +const user = require('./user'); +const pipeline = require('./pipeline'); +const context = require('./context'); +const image = require('./image'); +const composition = require('./composition'); +const environment = require('./environment'); +const workflow = require('./workflow'); module.exports = { user, @@ -16,4 +16,4 @@ module.exports = { composition, environment, workflow, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/pipeline.js b/lib/logic/api/pipeline.js index 30250c829..72ff6213d 100644 --- a/lib/logic/api/pipeline.js +++ b/lib/logic/api/pipeline.js @@ -1,27 +1,25 @@ -const _ = require('lodash'); -const CFError = require('cf-errors'); +const _ = require('lodash'); +const CFError = require('cf-errors'); const { sendHttpRequest } = require('./helper'); -const Pipeline = require('../entities/Pipeline'); +const Pipeline = require('../entities/Pipeline'); -const _extractFieldsForPipelineEntity = (pipeline) => { - return { - id: pipeline._id, - name: pipeline.name, - imageName: pipeline.imageName, - repoOwner: pipeline.repoOwner, - repoName: pipeline.repoName, - }; -}; +const _extractFieldsForPipelineEntity = pipeline => ({ + id: pipeline._id, + name: pipeline.name, + imageName: pipeline.imageName, + repoOwner: pipeline.repoOwner, + repoName: pipeline.repoName, +}); const getAll = async () => { const options = { - url: `/api/pipelines`, + url: '/api/pipelines', method: 'GET', }; - const result = await sendHttpRequest(options); + const result = await sendHttpRequest(options); const pipelines = []; _.forEach(result, (pipeline) => { @@ -44,7 +42,7 @@ const getAllByRepo = async (repoOwner, repoName) => { method: 'GET', }; - const result = await sendHttpRequest(options); + const result = await sendHttpRequest(options); const pipelines = []; _.forEach(result, (pipeline) => { @@ -70,10 +68,8 @@ const getAllByRepo = async (repoOwner, repoName) => { * @returns {Promise<*>} */ const getPipelineByNameAndRepo = async (name, repoOwner, repoName) => { - const pipelines = await getAllByRepo(repoOwner, repoName); - const currPipeline = _.find(pipelines, (pipeline) => { - return pipeline.info.name.toString() === name; - }); + const pipelines = await getAllByRepo(repoOwner, repoName); + const currPipeline = _.find(pipelines, pipeline => pipeline.info.name.toString() === name); if (!currPipeline) { throw new CFError(`Pipeline name: ${name} wasn't found under repository: ${repoOwner}/${repoName}`); @@ -89,7 +85,7 @@ const getPipelineById = async (id) => { }; const pipeline = await sendHttpRequest(options); - const data = _extractFieldsForPipelineEntity(pipeline); + const data = _extractFieldsForPipelineEntity(pipeline); return new Pipeline(data); }; @@ -129,7 +125,7 @@ const runPipelineById = async (id, data = {}) => { body, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; /** @@ -146,7 +142,7 @@ const patchPipelineById = async (id, pipeline) => { body: pipeline, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; const patchPipelineByNameAndRepo = async (name, repoOwner, repoName, pipeline) => { @@ -156,7 +152,7 @@ const patchPipelineByNameAndRepo = async (name, repoOwner, repoName, pipeline) = body: pipeline, }; - return await sendHttpRequest(options); + return sendHttpRequest(options); }; @@ -168,4 +164,4 @@ module.exports = { patchPipelineByNameAndRepo, getPipelineById, getAll, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/user.js b/lib/logic/api/user.js index 2f2be8f7a..e403f3e4b 100644 --- a/lib/logic/api/user.js +++ b/lib/logic/api/user.js @@ -6,10 +6,10 @@ const getByAuthContext = async (authContext) => { method: 'GET', }; - return await sendHttpRequest(options, authContext); + return sendHttpRequest(options, authContext); }; module.exports = { getByAuthContext, -}; \ No newline at end of file +}; diff --git a/lib/logic/api/workflow.js b/lib/logic/api/workflow.js index 29c73ff20..00024d1f3 100644 --- a/lib/logic/api/workflow.js +++ b/lib/logic/api/workflow.js @@ -1,14 +1,14 @@ -const _ = require('lodash'); -const CFError = require('cf-errors'); +const _ = require('lodash'); +const CFError = require('cf-errors'); // eslint-disable-line const { sendHttpRequest } = require('./helper'); -const Workflow = require('../entities/Workflow'); -const moment = require('moment'); +const Workflow = require('../entities/Workflow'); +const moment = require('moment'); const _extractFieldsForWorkflowEntity = (workflow) => { - const created = moment(workflow.created); - const finished = moment(workflow.finished); - const totalTime = moment.utc(finished.diff(created)).format("HH:mm:ss.SSS"); + const created = moment(workflow.created); + const finished = moment(workflow.finished); + const totalTime = moment.utc(finished.diff(created)).format('HH:mm:ss.SSS'); return { id: workflow.id, @@ -25,16 +25,16 @@ const _extractFieldsForWorkflowEntity = (workflow) => { const getWorkflowById = async (id) => { - const options = { + const options = { url: `/api/builds/${id}`, method: 'GET', }; const workflow = await sendHttpRequest(options); - const data = _extractFieldsForWorkflowEntity(workflow); + const data = _extractFieldsForWorkflowEntity(workflow); return new Workflow(data); }; -//TODO: need to ask itai about the total - maybe there is a better way to get the total record without to do 2 http request +// TODO: need to ask itai about the total - maybe there is a better way to get the total record without to do 2 http request const getWorkflows = async (options) => { const qs = { limit: options.limit, @@ -46,8 +46,8 @@ const getWorkflows = async (options) => { qs, method: 'GET', }; - const result = await sendHttpRequest(RequestOptions); - const workflows = []; + const result = await sendHttpRequest(RequestOptions); + const workflows = []; _.forEach(result.workflows.docs, (workflow) => { const data = _extractFieldsForWorkflowEntity(workflow); workflows.push(new Workflow(data)); @@ -59,4 +59,4 @@ const getWorkflows = async (options) => { module.exports = { getWorkflowById, getWorkflows, -}; \ No newline at end of file +}; diff --git a/lib/logic/auth/contexts/Context.js b/lib/logic/auth/contexts/Context.js index 708a869c3..db31b2141 100644 --- a/lib/logic/auth/contexts/Context.js +++ b/lib/logic/auth/contexts/Context.js @@ -1,11 +1,10 @@ const CFError = require('cf-errors'); -const uuidv4 = require('uuid/v4'); +const uuidv4 = require('uuid/v4'); class Context { - constructor(options) { this.name = options.name || uuidv4(); - this.url = options.url; + this.url = options.url; } setName(name) { @@ -23,14 +22,14 @@ class Context { /** * validates the context against codefresh */ - validate() { + validate() { // eslint-disable-line throw new CFError('Not implemented'); } /** * should prepare context for http request */ - prepareHttpOptions() { + prepareHttpOptions() { // eslint-disable-line throw new CFError('Not implemented'); } @@ -64,4 +63,4 @@ class Context { } -module.exports = Context; \ No newline at end of file +module.exports = Context; diff --git a/lib/logic/auth/contexts/JWTContext.js b/lib/logic/auth/contexts/JWTContext.js index c9d8f5ce9..68670cb31 100644 --- a/lib/logic/auth/contexts/JWTContext.js +++ b/lib/logic/auth/contexts/JWTContext.js @@ -1,27 +1,24 @@ -'use strict'; - -const _ = require('lodash'); +const _ = require('lodash'); const CFError = require('cf-errors'); const Context = require('./Context'); -const jwt = require('jsonwebtoken'); -const api = require('../../api'); +const jwt = require('jsonwebtoken'); +const api = require('../../api'); const TYPE = 'JWT'; class JWTContext extends Context { - constructor(options) { super(options); - this.type = TYPE; - this.token = options.token; - this.aclType = options.aclType; - this.userId = options.userId; - this.userName = options.userName; - this.accountId = options.accountId; + this.type = TYPE; + this.token = options.token; + this.aclType = options.aclType; + this.userId = options.userId; + this.userName = options.userName; + this.accountId = options.accountId; this.accountName = options.accountName; - this.expires = new Date(options.expires * 1000); - this.name = options.name || this.name; - this.defaultColumns = ['current','name', 'url']; + this.expires = new Date(options.expires * 1000); + this.name = options.name || this.name; + this.defaultColumns = ['current', 'name', 'url']; } _reCalculateName() { @@ -43,11 +40,9 @@ class JWTContext extends Context { async validate() { try { - const user = await api.user.getByAuthContext(this); - this.userName = user.userName; - const account = _.find(user.account, (acc) => { - return acc._id === this.accountId; - }); + const user = await api.user.getByAuthContext(this); + this.userName = user.userName; + const account = _.find(user.account, acc => acc._id === this.accountId); this.accountName = _.get(account, 'name'); this._reCalculateName(); } catch (err) { @@ -101,8 +96,7 @@ class JWTContext extends Context { let decodedToken; try { decodedToken = jwt.decode(token); - } - catch (err) { + } catch (err) { throw new CFError('Passed token is not a valid token'); } @@ -110,9 +104,9 @@ class JWTContext extends Context { throw new CFError('Passed token is not a valid token'); } - const accountId = decodedToken.accountId; - const userId = decodedToken._id; - const expires = decodedToken.exp; + const { accountId } = decodedToken; + const userId = decodedToken._id; + const expires = decodedToken.exp; return new JWTContext({ accountId, @@ -127,4 +121,4 @@ class JWTContext extends Context { JWTContext.TYPE = TYPE; -module.exports = JWTContext; \ No newline at end of file +module.exports = JWTContext; diff --git a/lib/logic/auth/contexts/index.js b/lib/logic/auth/contexts/index.js index 304b2d2ef..fe0e1f01f 100644 --- a/lib/logic/auth/contexts/index.js +++ b/lib/logic/auth/contexts/index.js @@ -2,4 +2,4 @@ const JWTContext = require('./JWTContext'); module.exports = { JWTContext, -}; \ No newline at end of file +}; diff --git a/lib/logic/auth/index.js b/lib/logic/auth/index.js index b3056d1a5..88637c06d 100644 --- a/lib/logic/auth/index.js +++ b/lib/logic/auth/index.js @@ -1,7 +1,7 @@ -const manager = require('./manager'); +const manager = require('./manager'); const contexts = require('./contexts'); module.exports = { manager, contexts, -}; \ No newline at end of file +}; diff --git a/lib/logic/auth/manager.js b/lib/logic/auth/manager.js index 76ed52e32..f01ae07dd 100644 --- a/lib/logic/auth/manager.js +++ b/lib/logic/auth/manager.js @@ -1,9 +1,7 @@ -'use strict'; - -const fs = require('fs'); -const _ = require('lodash'); +const fs = require('fs'); +const _ = require('lodash'); const CFError = require('cf-errors'); -const yaml = require('js-yaml'); +const yaml = require('js-yaml'); // context classes const { JWTContext } = require('./contexts'); @@ -13,9 +11,8 @@ const { JWTContext } = require('./contexts'); */ class Manager { - constructor() { - this.contexts = {}; + this.contexts = {}; this.currentContextName = null; } @@ -82,12 +79,14 @@ class Manager { const doc = yaml.safeLoad(fs.readFileSync(configFilePath, 'utf8')); _.forEach(doc.contexts, (rawContext) => { switch (rawContext.type) { - case JWTContext.TYPE: + case JWTContext.TYPE: { const context = JWTContext.createFromSerialized(rawContext); this.addContext(context); break; - default: + } + default: { throw new CFError(`Failed to parse context of type: ${rawContext.type}`); + } } }); @@ -95,7 +94,6 @@ class Manager { if (currentContext) { this.setCurrentContext(currentContext); } - } catch (err) { if (err.code === 'ENOENT') { const data = { @@ -122,7 +120,7 @@ class Manager { } catch (err) { throw new CFError({ cause: err, - message: `Failed to handle CF_TOKEN`, + message: 'Failed to handle CF_TOKEN', }); } } @@ -144,4 +142,4 @@ class Manager { } } -module.exports = new Manager(); \ No newline at end of file +module.exports = new Manager(); diff --git a/lib/logic/auth/manager.unit.spec.js b/lib/logic/auth/manager.unit.spec.js index 2840f77ad..fa0c358e5 100644 --- a/lib/logic/auth/manager.unit.spec.js +++ b/lib/logic/auth/manager.unit.spec.js @@ -1,25 +1,18 @@ -'use strict'; -const context = require('../index'); -describe('Contexts tests', () => { +const context = require('../index'); // eslint-disable-line +describe('Contexts tests', () => { describe('loadConfigFile', () => { - describe('positive', () => { - test('adds 1 + 2 to equal 3', () => { - expect(3).toBe(3); + expect(3).toBe(3); // eslint-disable-line }); - - }); describe('negative', () => { }); - }); - }); diff --git a/lib/logic/entities/Composition.js b/lib/logic/entities/Composition.js index 90f16861c..09fdfa3e5 100644 --- a/lib/logic/entities/Composition.js +++ b/lib/logic/entities/Composition.js @@ -5,7 +5,7 @@ class Composition extends Entity { super(); this.entityType = 'composition'; this.info = data; - this.defaultColumns = ['id','name', 'isAdvanced']; + this.defaultColumns = ['id', 'name', 'isAdvanced']; this.wideColumns = ['id', 'name', 'isAdvanced', 'created']; } } diff --git a/lib/logic/entities/Context.js b/lib/logic/entities/Context.js index 808d6ef2a..c43af8d00 100644 --- a/lib/logic/entities/Context.js +++ b/lib/logic/entities/Context.js @@ -10,4 +10,4 @@ class Context extends Entity { } } -module.exports = Context; \ No newline at end of file +module.exports = Context; diff --git a/lib/logic/entities/Entity.js b/lib/logic/entities/Entity.js index 028fa0d7e..285fd1476 100644 --- a/lib/logic/entities/Entity.js +++ b/lib/logic/entities/Entity.js @@ -1,22 +1,22 @@ -const yaml = require('js-yaml'); +const yaml = require('js-yaml'); class Entity { - //get all the information about the entity + // get all the information about the entity getInfo() { return this.info; } - //default Columns means all the fields we want to show at when using get and the user is not specify which kind of output he want (not include a lot of information) + // default Columns means all the fields we want to show at when using get and the user is not specify which kind of output he want (not include a lot of information) toDefault() { return this.extractValues(this.defaultColumns); } - //wide Columns means all the fields we want to show when using get with -o wide option (return more information then the defualt) + // wide Columns means all the fields we want to show when using get with -o wide option (return more information then the defualt) toWide() { return this.extractValues(this.wideColumns); } toJson() { - return JSON.stringify(this.info, null , '\t'); + return JSON.stringify(this.info, null, '\t'); } toYaml() { @@ -24,7 +24,7 @@ class Entity { } toName() { - return this.entityType + '/' + this.info.name; + return `${this.entityType}/${this.info.name}`; } extractValues(columns) { @@ -35,11 +35,10 @@ class Entity { return values; } - //TODO: choose which information to show when using describe command - describe(){ + // TODO: choose which information to show when using describe command + describe() { return yaml.safeDump(this.info); } - } module.exports = Entity; diff --git a/lib/logic/entities/Image.js b/lib/logic/entities/Image.js index 14bfb51de..22ba50f99 100644 --- a/lib/logic/entities/Image.js +++ b/lib/logic/entities/Image.js @@ -3,10 +3,10 @@ const Entity = require('./Entity'); class Image extends Entity { constructor(data) { super(); - this.entityType = 'image'; - this.info = data; + this.entityType = 'image'; + this.info = data; this.defaultColumns = ['image_id', 'name', 'tag', 'created', 'size', 'pull']; - this.wideColumns = this.defaultColumns.concat([]); + this.wideColumns = this.defaultColumns.concat([]); } } diff --git a/lib/logic/entities/Pipeline.js b/lib/logic/entities/Pipeline.js index 43c180eaf..7fdd973d7 100644 --- a/lib/logic/entities/Pipeline.js +++ b/lib/logic/entities/Pipeline.js @@ -5,8 +5,8 @@ class Pipeline extends Entity { super(); this.entityType = 'pipeline'; this.info = data; - this.defaultColumns = ['id','name', 'imageName', 'repoOwner']; - this.wideColumns = ['id','name', 'imageName', 'repoOwner', 'repoName']; + this.defaultColumns = ['id', 'name', 'imageName', 'repoOwner']; + this.wideColumns = ['id', 'name', 'imageName', 'repoOwner', 'repoName']; } } diff --git a/lib/logic/entities/Workflow.js b/lib/logic/entities/Workflow.js index 3e0beeda5..bfadbad68 100644 --- a/lib/logic/entities/Workflow.js +++ b/lib/logic/entities/Workflow.js @@ -3,10 +3,10 @@ const Entity = require('./Entity'); class Workflow extends Entity { constructor(data) { super(); - this.entityType = 'workflow'; - this.info = data; + this.entityType = 'workflow'; + this.info = data; this.defaultColumns = ['id', 'pipeline', 'trigger', 'status', 'created', 'totalTime']; - this.wideColumns = this.defaultColumns.concat(['finished', 'repository', 'branch']); + this.wideColumns = this.defaultColumns.concat(['finished', 'repository', 'branch']); } } diff --git a/lib/logic/index.js b/lib/logic/index.js index 7abbbbf07..1b3be18cf 100644 --- a/lib/logic/index.js +++ b/lib/logic/index.js @@ -1,4 +1,4 @@ -const api = require('./api'); +const api = require('./api'); const auth = require('./auth'); module.exports = { diff --git a/package.json b/package.json index 1d71de4c9..489f5dbb0 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "codefresh", - "version": "0.2.7", + "version": "0.2.8", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true, "scripts": { "test": "jest unit.spec.js --coverage", - "eslint": "eslint lib/**", + "eslint": "eslint lib/logic/**", "ci-publish": "ci-publish" }, "bin": { @@ -42,6 +42,7 @@ "eslint": "^4.11.0", "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "^2.8.0", + "eslint-plugin-mocha": "^4.11.0", "jest": "^21.2.1" }, "bugs": { diff --git a/yarn.lock b/yarn.lock index 02ea02035..8c1bd1e44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1041,6 +1041,12 @@ eslint-plugin-import@^2.8.0: minimatch "^3.0.3" read-pkg-up "^2.0.0" +eslint-plugin-mocha@^4.11.0: + version "4.11.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-4.11.0.tgz#91193a2f55e20a5e35974054a0089d30198ee578" + dependencies: + ramda "^0.24.1" + eslint-restricted-globals@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz#35f0d5cbc64c2e3ed62e93b4b1a7af05ba7ed4d7" @@ -2953,6 +2959,10 @@ ramda@0.15.1: version "0.15.1" resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.15.1.tgz#b227f79e9ff0acee1955d582f18681eb02c4dc2a" +ramda@^0.24.1: + version "0.24.1" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857" + randomatic@^1.1.3: version "1.1.7" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c"