From e8410370330f72b1ac5f44b8489b0ce7b9c87054 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Sun, 19 Aug 2018 13:48:19 +0200 Subject: [PATCH 01/21] Add npm run rules --- Makefile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0b1ee22..060c5df 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,19 @@ .PHONY: test deps: - npm i + npm install -lint: - node_modules/.bin/eslint . +run: + npm run start -test: - make lint - make cover +lint: + npm run lint cover: - node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- test --recursive --timeout=10000 + npm run cover + +test: + npm run test sonar: sed '/sonar.projectVersion/d' ./sonar-project.properties > tmp && mv tmp sonar-project.properties @@ -19,7 +21,7 @@ sonar: wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.8.zip unzip sonar-scanner-2.8.zip ifdef CI_PULL_REQUEST - @sonar-scanner-2.8/bin/sonar-runner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) + @sonar-scanner-2.8/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) endif ifeq ($(CIRCLE_BRANCH),develop) @sonar-scanner-2.8/bin/sonar-runner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) From 6493c7edbd3756a41bdfb7ea74a9a29afaa0240e Mon Sep 17 00:00:00 2001 From: steven-heng Date: Sun, 19 Aug 2018 13:48:21 +0200 Subject: [PATCH 02/21] Add badges --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 238a519..74f2a7e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ -## Catchie +## node-catchie + [![CircleCI](https://circleci.com/gh/dial-once/node-catchie.svg?style=svg)](https://circleci.com/gh/dial-once/node-catchie) +[![Sonar](http://proxy.dialonce.net/sonar/api/badges/gate?key=node-node-catchie)](http://sonar.dialonce.net/dashboard?id=node-node-catchie) +[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-node-catchie&metric=ncloc)](http://sonar.dialonce.net/dashboard?id=node-node-catchie) +[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-node-catchie&metric=coverage)](http://sonar.dialonce.net/dashboard?id=node-node-catchie) +[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-node-catchie&metric=code_smells)](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-node-catchie&metric=coverage) +[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-node-catchie&metric=bugs)](http://sonar.dialonce.net/dashboard?id=node-node-catchie) +[![Sonar](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-node-catchie&metric=sqale_debt_ratio)](http://sonar.dialonce.net/dashboard?id=node-node-catchie) + Repeats the provided function (sync and async) n times if an error occurs during its execution. @@ -24,7 +32,7 @@ By default, a __console__ will be used as a logger You can also silence the module and not let it log info about retries if you pass the boolean value: ```js // 2nd parameter is silence { boolean } -const catchie = require('catchie')(new winston.Logger(), true); +const catchie = require('catchie')(new winston.Logger(), true); ``` ## Usage From 9b924b327fb0deda30c8317bc65cb298316a8e31 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Sun, 19 Aug 2018 13:48:24 +0200 Subject: [PATCH 03/21] Update npm rule and dependencies --- package.json | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 4cc3c10..ba240ba 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "description": "Retries a provided function n times on error", "main": "src/index.js", "scripts": { - "test": "node_modules/.bin/eslint . && node_modules/.bin/_mocha --recursive test", "start": "node src/index.js", - "cover": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- test --recursive" + "lint": "./node_modules/.bin/eslint .", + "cover": "CONSOLE_LOGGING=false node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- test --recursive --timeout=20000 --exit", + "test": "npm run lint && npm run cover" }, "repository": { "type": "git", @@ -27,13 +28,13 @@ }, "homepage": "https://github.com/dial-once/node-catchie#readme", "devDependencies": { - "eslint": "^3.19.0", - "eslint-config-airbnb": "^15.0.1", - "eslint-plugin-import": "^2.3.0", - "eslint-plugin-jsx-a11y": "^5.0.3", - "eslint-plugin-react": "^7.0.1", - "istanbul": "^0.4.5", - "mocha": "^5.2.0", + "eslint": "^4.9.0", + "eslint-config-airbnb": "^16.1.0", + "eslint-plugin-import": "^2.8.0", + "eslint-plugin-jsx-a11y": "^6.0.2", + "eslint-plugin-react": "^7.4.0", + "istanbul": "^1.1.0-alpha.1", + "mocha": "^4.0.1", "sinon": "^2.3.1" } } From 0fc7312edb5dcff8e82ea03a0ed735d139cb6db8 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Sun, 19 Aug 2018 13:48:27 +0200 Subject: [PATCH 04/21] Update file --- sonar-project.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index f7fd29b..d58c910 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,6 @@ sonar.projectName=node-catchie sonar.sources=src sonar.tests=test -sonar.language=js sonar.dynamicAnalysis=reuseReports sonar.javascript.jstest.reportsPath=coverage From 8046ae1f10643800f7d0cfc4c96159c5872f2c88 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Wed, 22 Aug 2018 18:08:21 +0200 Subject: [PATCH 05/21] Replace istanbul by nyc --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index aee5b0b..6cc8ed5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,9 @@ pids # Directory for instrumented libs generated by jscoverage/JSCover lib-cov -# Coverage directory used by tools like istanbul +# Coverage directory used by tools like nyc coverage -.sonar/ +.nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt From 79f82d7445a5bd40231947340f92f2d06d94be3e Mon Sep 17 00:00:00 2001 From: steven-heng Date: Wed, 22 Aug 2018 18:08:23 +0200 Subject: [PATCH 06/21] Add npm start --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 060c5df..6c714e2 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ deps: npm install run: - npm run start + npm start lint: npm run lint @@ -24,6 +24,6 @@ ifdef CI_PULL_REQUEST @sonar-scanner-2.8/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) endif ifeq ($(CIRCLE_BRANCH),develop) - @sonar-scanner-2.8/bin/sonar-runner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) + @sonar-scanner-2.8/bin/sonar-scanner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) endif rm -rf sonar-scanner-2.8 sonar-scanner-2.8.zip From 2a2a720c228954da435e6fc65cf7bb7e1288d6f9 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Wed, 22 Aug 2018 18:08:25 +0200 Subject: [PATCH 07/21] Update eslint dependencies, replace istanbul by nyc, update npm start and cover --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ba240ba..25cdcb9 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "start": "node src/index.js", "lint": "./node_modules/.bin/eslint .", - "cover": "CONSOLE_LOGGING=false node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- test --recursive --timeout=20000 --exit", + "cover": "CONSOLE_LOGGING=false ./node_modules/.bin/nyc --reporter=lcov ./node_modules/.bin/_mocha test --recursive --timeout=10000 --exit", "test": "npm run lint && npm run cover" }, "repository": { @@ -28,13 +28,13 @@ }, "homepage": "https://github.com/dial-once/node-catchie#readme", "devDependencies": { - "eslint": "^4.9.0", - "eslint-config-airbnb": "^16.1.0", - "eslint-plugin-import": "^2.8.0", - "eslint-plugin-jsx-a11y": "^6.0.2", - "eslint-plugin-react": "^7.4.0", - "istanbul": "^1.1.0-alpha.1", - "mocha": "^4.0.1", + "eslint": "^5.4.0", + "eslint-config-airbnb": "^17.1.0", + "eslint-plugin-import": "^2.14.0", + "eslint-plugin-jsx-a11y": "^6.1.1", + "eslint-plugin-react": "^7.11.1", + "mocha": "^5.2.0", + "nyc": "^12.0.2", "sinon": "^2.3.1" } } From 8c99501b04e3c47c3b3fb7cc477f680e470cc9a0 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Mon, 8 Oct 2018 23:53:28 +0800 Subject: [PATCH 08/21] Add ignore folder of nyc_output --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6cc8ed5..61231b3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,8 @@ pids # Directory for instrumented libs generated by jscoverage/JSCover lib-cov -# Coverage directory used by tools like nyc +# Coverage directory used by tools like nyc or sonar +.sonar/ coverage .nyc_output From 1bb585264c72ae7cd1fc9d3902072a6be596cb70 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Mon, 8 Oct 2018 23:54:06 +0800 Subject: [PATCH 09/21] Adding sinon from dev to depedencies --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 25cdcb9..2dc486c 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,9 @@ "url": "https://github.com/dial-once/node-catchie/issues" }, "homepage": "https://github.com/dial-once/node-catchie#readme", + "dependencies": { + "sinon": "^2.3.1" + }, "devDependencies": { "eslint": "^5.4.0", "eslint-config-airbnb": "^17.1.0", @@ -34,7 +37,6 @@ "eslint-plugin-jsx-a11y": "^6.1.1", "eslint-plugin-react": "^7.11.1", "mocha": "^5.2.0", - "nyc": "^12.0.2", - "sinon": "^2.3.1" + "nyc": "^12.0.2" } } From 8ffcdb52235f45484d874927c9fbbf567b76aca7 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Mon, 8 Oct 2018 23:54:43 +0800 Subject: [PATCH 10/21] Fix indent --- src/index.js | 90 ++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/index.js b/src/index.js index 9af39f2..81d9553 100644 --- a/src/index.js +++ b/src/index.js @@ -1,19 +1,19 @@ let defaultLogger = console; /** - @class Catchie - Consume errors and retry the function execution given times - - Supported environment variables: - CATCHIE_MAX_RETRY - cap amount of function retry -**/ + * @class Catchie + * Consume errors and retry the function execution given times + * + * Supported environment variables: + * CATCHIE_MAX_RETRY - cap amount of function retry + * */ class Catchie { /** - @constructor - Construct instance of the module - @param logger {Object} - logger instnace - @param silent {boolean} - log or not the info about retries - **/ + * @constructor + * Construct instance of the module + * @param logger {Object} - logger instnace + * @param silent {boolean} - log or not the info about retries + * */ constructor(logger, silent) { this.logger = logger || defaultLogger; this.successCount = 0; @@ -22,39 +22,39 @@ class Catchie { } /** - @function clear - Reset the values of successCount and failureCount - **/ + * @function clear + * Reset the values of successCount and failureCount + * */ clear() { this.successCount = 0; this.failureCount = 0; } /** - @function callCount - Get the total amount of given function calls - @return {number} - total amount of function calls - **/ + * @function callCount + * Get the total amount of given function calls + * @return {number} - total amount of function calls + * */ get callCount() { return this.successCount + this.failureCount; } /** - @function retry - Execute the function given amount of times - @param fn { Function } - a function returning value / Promise - @retryCount { string|number } - amount of times to repeat a function on error - @return - { any } - if function is sync - { Promise } - if function is async - @throws if after the retryCount times of function execution the function still ended up with an error - @throws if fn param is not a function - **/ + * @function retry + * Execute the function given amount of times + * @param fn { Function } - a function returning value / Promise + * @retryCount { string|number } - amount of times to repeat a function on error + * @return + * { any } - if function is sync + * { Promise } - if function is async + * @throws if after the retryCount times of function execution the function still ended up with an error + * @throws if fn param is not a function + * */ retry(fn, retryCount = 1) { this.clear(); let timesToRetry = parseInt(retryCount || process.env.CATCHIE_MAX_RETRY, 10); - if (isNaN(timesToRetry)) { + if (Number.isNaN(timesToRetry)) { timesToRetry = 0; } @@ -84,21 +84,21 @@ class Catchie { if (value instanceof Promise) { // for promises a plain-old-catch does not work return Promise.resolve() - .then(() => value) - .then((result) => { - this.successCount ++; - return result; - }) - .catch((e) => { - this.failureCount ++; - return loopCheck(e, arguments); - }); + .then(() => value) + .then((result) => { + this.successCount++; + return result; + }) + .catch((e) => { + this.failureCount++; + return loopCheck(e, arguments); + }); } // if did not throw -> return either a Promise or an actual value - this.successCount ++; + this.successCount++; return value; } catch (e) { - this.failureCount ++; + this.failureCount++; return loopCheck(e, arguments); } }; @@ -108,11 +108,11 @@ class Catchie { } /** - @function - @param loggerInstance {object} - instance of a logger to use - @param silet {boolean} - log or not log the info about retries - @return {Object} - new instance of the module -**/ + * @function + * @param loggerInstance {object} - instance of a logger to use + * @param silet {boolean} - log or not log the info about retries + * @return {Object} - new instance of the module + * */ module.exports = (loggerInstance, silent = false) => { if (![null, undefined].includes(loggerInstance)) { defaultLogger = loggerInstance; From be98961de412498d50aa1b29dbcf412a9b695e34 Mon Sep 17 00:00:00 2001 From: steven-heng Date: Mon, 8 Oct 2018 23:56:11 +0800 Subject: [PATCH 11/21] Fix indentation of arrow function --- test/catch-loop-spec.js | 81 +++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/test/catch-loop-spec.js b/test/catch-loop-spec.js index eb5372e..9899f72 100644 --- a/test/catch-loop-spec.js +++ b/test/catch-loop-spec.js @@ -13,7 +13,7 @@ describe('Repeater module tests', () => { it('Should retry the function on error', (done) => { let toThrow = true; - const functionToRepeat = function () { + const functionToRepeat = () => { if (toThrow) { toThrow = false; throw new Error(); @@ -66,7 +66,7 @@ describe('Repeater module tests', () => { it('Should not loose args passed to the function during retrys [no promise]', (done) => { let toThrow = true; - const functionToRepeat = function (arg1, arg2) { + const functionToRepeat = (arg1, arg2) => { if (toThrow) { toThrow = false; throw new Error(); @@ -102,17 +102,15 @@ describe('Repeater module tests', () => { it('Should not loose args passed to the function during retrys [promise]', () => { let toThrow = true; - const functionToRepeat = function (arg1, arg2) { - return new Promise((resolve, reject) => { - if (toThrow) { - toThrow = false; - reject(); - } - assert.equal(arg1, 'Hello'); - assert.equal(arg2, 'World'); - resolve(arg1 + arg2); - }); - }; + const functionToRepeat = (arg1, arg2) => (new Promise((resolve, reject) => { + if (toThrow) { + toThrow = false; + reject(); + } + assert.equal(arg1, 'Hello'); + assert.equal(arg2, 'World'); + resolve(arg1 + arg2); + })); const spy = sinon.spy(functionToRepeat.bind(this, 'Hello', 'World')); return catchie.retry(spy).then((result) => { assert.equal(spy.callCount, catchie.callCount); @@ -122,16 +120,15 @@ describe('Repeater module tests', () => { it('Should not loose args passed to the function during retrys [promise] [arrow function]', () => { let toThrow = true; - const functionToRepeat = (arg1, arg2) => - (new Promise((resolve, reject) => { - if (toThrow) { - toThrow = false; - reject(); - } - assert.equal(arg1, 'Hello'); - assert.equal(arg2, 'World'); - resolve(arg1 + arg2); - })); + const functionToRepeat = (arg1, arg2) => (new Promise((resolve, reject) => { + if (toThrow) { + toThrow = false; + reject(); + } + assert.equal(arg1, 'Hello'); + assert.equal(arg2, 'World'); + resolve(arg1 + arg2); + })); const spy = sinon.spy(functionToRepeat.bind(this, 'Hello', 'World')); return catchie.retry(spy).then((result) => { assert.equal(spy.callCount, catchie.callCount); @@ -140,10 +137,10 @@ describe('Repeater module tests', () => { }); it('Should propagate rejection after retries cap reached', () => { - const spy = sinon.spy(sinon.stub().returns(Promise.reject('Promise rejected'))); + const spy = sinon.spy(sinon.stub().returns(Promise.reject(new Error('Promise rejected')))); return catchie.retry(spy, 5).catch((e) => { assert(e instanceof Error); - assert.equal(e.message, 'Promise rejected'); + assert.equal(e, 'Error: Error: Promise rejected'); assert.equal(spy.callCount, catchie.callCount); }); }); @@ -240,29 +237,27 @@ describe('Repeater module tests', () => { it('should not loose context [promise] [rejected]', (done) => { const spy = sinon.spy(sinon.stub().returns(Promise.reject())); - const badFunction = () => - (new Promise((resolve) => { - setTimeout(() => resolve(spy()), 250); - })); + const badFunction = () => (new Promise((resolve) => { + setTimeout(() => resolve(spy()), 250); + })); catchie.retry(badFunction, 5) - .catch((e) => { - assert(e instanceof Error); - assert.equal(spy.callCount, catchie.callCount); - done(); - }); + .catch((e) => { + assert(e instanceof Error); + assert.equal(spy.callCount, catchie.callCount); + done(); + }); }); it('should not loose context [promise] [resolved]', (done) => { const spy = sinon.spy(sinon.stub().returns(Promise.resolve(15))); - const badFunction = () => - (new Promise((resolve) => { - setTimeout(() => resolve(spy()), 250); - })); + const badFunction = () => (new Promise((resolve) => { + setTimeout(() => resolve(spy()), 250); + })); catchie.retry(badFunction, 5) - .then((val) => { - assert.equal(val, 15); - assert.equal(spy.callCount, catchie.callCount); - done(); - }); + .then((val) => { + assert.equal(val, 15); + assert.equal(spy.callCount, catchie.callCount); + done(); + }); }); }); From 719847f3bb2c76b31aad7c545c22abdbcfb5a9e0 Mon Sep 17 00:00:00 2001 From: steven heng Date: Mon, 15 Oct 2018 13:01:19 +0800 Subject: [PATCH 12/21] Adding .nyc_output folder ignore --- .eslintignore | 3 +++ .gitignore | 4 ++-- .npmignore | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.eslintignore b/.eslintignore index b6f11ad..8a3acef 100644 --- a/.eslintignore +++ b/.eslintignore @@ -14,6 +14,9 @@ lib-cov coverage .sonar/ +# Nyc coverage directory +.nyc_output + # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt diff --git a/.gitignore b/.gitignore index 61231b3..2c92f71 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,9 @@ pids # Directory for instrumented libs generated by jscoverage/JSCover lib-cov -# Coverage directory used by tools like nyc or sonar -.sonar/ +# Coverage directory used by tools like istanbul/nyc or sonar coverage +.sonar/ .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) diff --git a/.npmignore b/.npmignore index 2fe96d7..9341f0f 100644 --- a/.npmignore +++ b/.npmignore @@ -10,8 +10,9 @@ pids # Directory for instrumented libs generated by jscoverage/JSCover lib-cov -# Coverage directory used by tools like istanbul +# Coverage directory used by tools like istanbul or nyc coverage +.nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt From 14b5ec2be4d842f7cd725dcd9096a1834f4f9446 Mon Sep 17 00:00:00 2001 From: steven heng Date: Mon, 15 Oct 2018 13:01:22 +0800 Subject: [PATCH 13/21] Delete useless break line --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 6c714e2..dc7af5b 100644 --- a/Makefile +++ b/Makefile @@ -18,12 +18,12 @@ test: sonar: sed '/sonar.projectVersion/d' ./sonar-project.properties > tmp && mv tmp sonar-project.properties echo sonar.projectVersion=`cat package.json | python -c "import json,sys;obj=json.load(sys.stdin);print obj['version'];"` >> sonar-project.properties - wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.8.zip - unzip sonar-scanner-2.8.zip + wget https://s3.eu-central-1.amazonaws.com/dialonce-cdn/utilities/sonar-scanner-cli.zip + unzip sonar-scanner-* ifdef CI_PULL_REQUEST - @sonar-scanner-2.8/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) + @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) endif ifeq ($(CIRCLE_BRANCH),develop) - @sonar-scanner-2.8/bin/sonar-scanner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) + @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) endif - rm -rf sonar-scanner-2.8 sonar-scanner-2.8.zip + rm -rf sonar-scanner From 994cc9dd19eb387241ddce9b7f8abc2c5c85c613 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Sat, 27 Oct 2018 19:07:10 +0800 Subject: [PATCH 14/21] Replace CI_PULL_REQUEST by CIRCLE_PULL_REQUEST --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dc7af5b..ab6c36b 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,8 @@ sonar: echo sonar.projectVersion=`cat package.json | python -c "import json,sys;obj=json.load(sys.stdin);print obj['version'];"` >> sonar-project.properties wget https://s3.eu-central-1.amazonaws.com/dialonce-cdn/utilities/sonar-scanner-cli.zip unzip sonar-scanner-* -ifdef CI_PULL_REQUEST - @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CI_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) +ifdef CIRCLE_PULL_REQUEST + @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=${shell basename $(CIRCLE_PULL_REQUEST)} -Dsonar.github.repository=$(REPO_SLUG) -Dsonar.github.oauth=$(GITHUB_TOKEN) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) -Dsonar.host.url=$(SONAR_HOST_URL) endif ifeq ($(CIRCLE_BRANCH),develop) @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) From f865b3a336f91efb6636e4808163ee8318121ee0 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Sat, 27 Oct 2018 19:07:14 +0800 Subject: [PATCH 15/21] Adding config file to migrate circleci v1 to v2 --- .circleci/config.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a6c56a2 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,27 @@ +version: 2 +jobs: + build: + working_directory: ~/node-catchie + docker: + - image: circleci/node:8 + - image: rabbitmq:3.7.7 + steps: + - checkout + - run: + name: install make + command: sudo apt-get update && sudo apt-get -y install gcc make + - run: + name: Install dependencies + command: make deps + - run: + name: Init project + command: make init + - run: + name: Linting + command: make lint + - run: + name: Testing + command: make cover + - run: + name: Sonar + command: sudo make sonar From 1e45d31ff5aa28d49b2f8e295072eae94bdbfd54 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Mon, 5 Nov 2018 18:16:17 +0800 Subject: [PATCH 16/21] Adding eslint-disable no-use-before-define --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 81d9553..fd44af6 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,7 @@ let defaultLogger = console; +/* eslint-disable no-use-before-define */ + /** * @class Catchie * Consume errors and retry the function execution given times @@ -73,7 +75,7 @@ class Catchie { if (!this.silent) { this.logger.info(`Retrying function due to ${e} error`); } - return repeatable(...args); // eslint-disable-line + return repeatable(...args); }; const repeatable = () => { From 3849807ccce6f99cfd9d50fbe30f583ce179cdac Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Mon, 12 Nov 2018 20:00:11 +0800 Subject: [PATCH 17/21] Updating file --- .circleci/config.yml | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6c56a2..54d1a7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,27 +1,51 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# version: 2 jobs: build: - working_directory: ~/node-catchie docker: - - image: circleci/node:8 - - image: rabbitmq:3.7.7 + # specify the version you desire here + - image: circleci/node:8.9 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/mongo:3.4.4 + + working_directory: ~/node-catchie + steps: - checkout - run: name: install make command: sudo apt-get update && sudo apt-get -y install gcc make + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} + - v1-dependencies-{{ .Branch }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies - run: name: Install dependencies command: make deps - - run: - name: Init project - command: make init + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} + - run: name: Linting command: make lint + - run: name: Testing command: make cover + - run: - name: Sonar + name: Sonar analysis command: sudo make sonar From 93854ae1e0bc535f255c04d3eddcee1572b8a18f Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Mon, 12 Nov 2018 20:00:24 +0800 Subject: [PATCH 18/21] Adding rm sonar folder after analysis --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ab6c36b..f979936 100644 --- a/Makefile +++ b/Makefile @@ -26,4 +26,4 @@ endif ifeq ($(CIRCLE_BRANCH),develop) @sonar-scanner/bin/sonar-scanner -e -Dsonar.analysis.mode=publish -Dsonar.host.url=$(SONAR_HOST_URL) -Dsonar.login=$(SONAR_LOGIN) -Dsonar.password=$(SONAR_PASS) endif - rm -rf sonar-scanner + rm -rf sonar-scanner* From 0e2af7c5cf9a93ed35942a823416f69713440256 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Sun, 18 Nov 2018 13:49:42 +0800 Subject: [PATCH 19/21] Adding workflow, second job with java image to run sonar analysis correctly --- .circleci/config.yml | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 54d1a7b..d76aac1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,46 +6,48 @@ version: 2 jobs: build: docker: - # specify the version you desire here - image: circleci/node:8.9 - # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ # - image: circleci/mongo:3.4.4 working_directory: ~/node-catchie - steps: - checkout - run: name: install make command: sudo apt-get update && sudo apt-get -y install gcc make - # Download and cache dependencies - restore_cache: keys: - v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - v1-dependencies-{{ .Branch }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies + - v1-dependencies # fallback to using the latest cache if no exact match is found - run: - name: Install dependencies + name: Installing dependencies command: make deps - - save_cache: paths: - node_modules key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - - - run: - name: Linting - command: make lint - - run: name: Testing - command: make cover + command: make test + sonarqube: + docker: + - image: circleci/openjdk:8-jdk-browsers + steps: + - checkout - run: name: Sonar analysis - command: sudo make sonar + command: make sonar +workflows: + version: 2 + build_and_test: + jobs: + - build + - sonarqube: + requires: + - build From e544363c3e64f788524fb70c4aa59b1bf19339c0 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Tue, 20 Nov 2018 15:28:14 +0800 Subject: [PATCH 20/21] Adding secondary job for sonar to run his analysis and report coverage on his dashboard --- .circleci/config.yml | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d76aac1..2ead50d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,49 +5,76 @@ version: 2 jobs: build: + working_directory: ~/node-catchie docker: - image: circleci/node:8.9 # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/mongo:3.4.4 - - working_directory: ~/node-catchie steps: - checkout - run: - name: install make + name: Install make command: sudo apt-get update && sudo apt-get -y install gcc make + # Download and cache dependencies - restore_cache: keys: - v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - v1-dependencies-{{ .Branch }} - - v1-dependencies # fallback to using the latest cache if no exact match is found + # fallback to using the latest cache if no exact match is found + - v1-dependencies - run: - name: Installing dependencies + name: Install dependencies command: make deps - save_cache: paths: - node_modules key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} + + #Initialize the project and run tests + - run: + name: Initialize + command: make init - run: - name: Testing + name: Test project command: make test + # Special step used to persist a temporary file to be used by another job in the workflow + - persist_to_workspace: + root: ~/node-catchie + paths: + - coverage + sonarqube: + working_directory: ~/node-catchie docker: + # Sonarqube need OpenJDK 8 to run his analysis correctly - image: circleci/openjdk:8-jdk-browsers steps: - checkout + # Special step used to attach the workflow’s workspace to the current container + # Retrieve coverage's folder for sonarqube + - attach_workspace: + at: ~/node-catchie + + # Sonarqube need to have node installed to run his analysis + - run: + name: Install node + command: | + sudo apt install curl + curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - + sudo apt install nodejs - run: name: Sonar analysis command: make sonar + workflows: version: 2 build_and_test: jobs: - build - sonarqube: + # sonarqube's job waiting for build's job before to run requires: - build From f320e048744c54c38d9073942fb7c64809a84357 Mon Sep 17 00:00:00 2001 From: Steven Heng Date: Tue, 20 Nov 2018 15:33:43 +0800 Subject: [PATCH 21/21] Deleting make init --- .circleci/config.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ead50d..ae3962c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,11 +31,6 @@ jobs: paths: - node_modules key: v1-dependencies-{{ .Branch }}-{{ checksum "package.json" }} - - #Initialize the project and run tests - - run: - name: Initialize - command: make init - run: name: Test project command: make test