Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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,
}
};
};
14 changes: 7 additions & 7 deletions codefresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,4 +48,4 @@ steps:
- NPM_TOKEN=${{NPM_TOKEN}} npm run ci-publish
when:
branch:
only: [ master ]
only: [ master ]
33 changes: 15 additions & 18 deletions lib/logic/api/composition.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -21,7 +19,7 @@ const createComposition = async (data) => {
body: data,
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

const replaceById = async (id, data) => {
Expand All @@ -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;

Expand All @@ -46,7 +44,7 @@ const applyById = async (id, data) => {
body,
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

const getCompositionByIdentifier = async (id) => {
Expand Down Expand Up @@ -83,16 +81,15 @@ const deleteCompositionById = async (id) => {
method: 'DELETE',
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};



module.exports = {
createComposition,
replaceById,
applyById,
getCompositionByIdentifier,
getCompositions,
deleteCompositionById,
};
};
34 changes: 16 additions & 18 deletions lib/logic/api/context.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -21,7 +19,7 @@ const createContext = async (data) => {
body: data,
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

const replaceByName = async (name, data) => {
Expand All @@ -33,7 +31,7 @@ const replaceByName = async (name, data) => {
body,
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

const applyByName = async (name, data) => {
Expand All @@ -45,7 +43,7 @@ const applyByName = async (name, data) => {
body,
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

const getContextByName = async (name, owner) => {
Expand Down Expand Up @@ -85,7 +83,7 @@ const deleteContextByName = async (name, owner) => {
body: { owner },
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

module.exports = {
Expand All @@ -95,4 +93,4 @@ module.exports = {
deleteContextByName,
replaceByName,
applyByName,
};
};
22 changes: 10 additions & 12 deletions lib/logic/api/environment.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -46,12 +44,12 @@ const deleteEnvironment = async (id) => {
method: 'GET',
};

return await sendHttpRequest(userOptions);
return sendHttpRequest(userOptions);
};


module.exports = {
getEnvironmentById,
getEnvironments,
deleteEnvironment,
};
};
14 changes: 7 additions & 7 deletions lib/logic/api/helper.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
42 changes: 20 additions & 22 deletions lib/logic/api/image.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -27,7 +25,7 @@ const getAll = async (options) => {
};

if (!options.volumeImages) {
qs.metadata['cf_volume'] = false;
qs.metadata.cf_volume = false;
}

if (options.sha) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -106,12 +104,12 @@ const annotateImage = async (dockerImageId, annotations) => {
body: annotations,
};

return await sendHttpRequest(options);
return sendHttpRequest(options);
};

module.exports = {
annotateImage,
getDockerImageId,
getAll,
getImageById,
};
};
18 changes: 9 additions & 9 deletions lib/logic/api/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,4 +16,4 @@ module.exports = {
composition,
environment,
workflow,
};
};
Loading