diff --git a/.github/workflows/CI-pipeline.yml b/.github/workflows/CI-pipeline.yml index 5a99adc..22cfa0c 100644 --- a/.github/workflows/CI-pipeline.yml +++ b/.github/workflows/CI-pipeline.yml @@ -1,3 +1,16 @@ +# Copyright 2020 EPAM Systems +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: CI-pipeline on: @@ -16,7 +29,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x - name: Clean install of node dependencies run: npm ci - name: Run lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 09b1022..f3aea0d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,3 +1,16 @@ +# Copyright 2020 EPAM Systems +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: publish on: @@ -14,7 +27,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x - name: Clean install of node dependencies run: npm ci - name: Run lint @@ -24,7 +37,7 @@ jobs: - name: Check coverage run: npm run test:coverage - publish-to-npm: + publish-to-npm-and-gpr: needs: build runs-on: ubuntu-latest steps: @@ -33,30 +46,28 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x registry-url: 'https://registry.npmjs.org' - name: Clean install of node dependencies run: npm ci - - name: Publish package to npm - run: npm publish + - name: Publish to NPM + run: | + npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN + npm config list + npm publish --access public env: NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} - - publish-to-gpr: - needs: build - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - name: Set up Node.js uses: actions/setup-node@v1 with: - node-version: 10.x + node-version: 12.x registry-url: 'https://npm.pkg.github.com' scope: '@reportportal' - - name: Clean install of node dependencies - run: npm ci - - name: Publish package to github packages - run: npm publish + - name: Publish to GPR + run: | + npm config set //npm.pkg.github.com/:_authToken=$NODE_AUTH_TOKEN + npm config set scope '@reportportal' + npm config list + npm publish env: NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9391ea1..83119c7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,16 @@ +# Copyright 2020 EPAM Systems +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + name: release on: diff --git a/.gitignore b/.gitignore index c602ed7..180db87 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ coverage.lcov .nyc_output coverage/ +.npmrc diff --git a/.npmignore b/.npmignore index 895b3e3..f62b286 100644 --- a/.npmignore +++ b/.npmignore @@ -2,3 +2,4 @@ coverage .nyc_output .gitignore .editorconfig +.github/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a4cb39..bc6daee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Changed +- Packages publishing workflow improved +### Added +- The ability to disable google analytics ## [5.0.0] - 2020-06-09 ### Added diff --git a/README.md b/README.md index bd7b622..123b664 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ As system attributes, this method sends the following data (these data are not f * nodeJS version; We use Google Analytics for sending anonymous usage information as library's name/version and the agent's name/version when the launchStart is called. This information might help us to improve reportportal-client. Used by the ReportPortal team only and not for sharing with 3rd parties. +You can disable Google Analytics by specify the following parameter **disableGA** with the value **true**. ### finishLaunch finishLaunch - finish of the launch. After calling this method, you can not add items to the launch. diff --git a/VERSION b/VERSION index 0062ac9..4f76215 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.0.0 +5.0.1-SNAPSHOT diff --git a/analytics/constants.js b/analytics/constants.js index fdcc715..353d4f6 100644 --- a/analytics/constants.js +++ b/analytics/constants.js @@ -2,6 +2,6 @@ const pjson = require('./../package.json'); const PJSON_VERSION = pjson.version; const PJSON_NAME = pjson.name; -const GOOGLE_ANALYTICS_INSTANCE = 'UA-96321031-1'; +const GOOGLE_ANALYTICS_INSTANCE = 'UA-173456809-1'; module.exports = { PJSON_VERSION, PJSON_NAME, GOOGLE_ANALYTICS_INSTANCE }; diff --git a/lib/report-portal-client.js b/lib/report-portal-client.js index 7f88fed..5862e63 100644 --- a/lib/report-portal-client.js +++ b/lib/report-portal-client.js @@ -32,11 +32,10 @@ class RPClient { this.isLaunchMergeRequired = params.isLaunchMergeRequired === undefined ? false : params.isLaunchMergeRequired; this.map = {}; this.baseURL = [params.endpoint, params.project].join('/'); - const headers = { + const headers = Object.assign({ 'User-Agent': 'NodeJS', Authorization: `bearer ${params.token}`, - ...(params.headers || {}), - }; + }, params.headers || {}); this.headers = headers; this.options = { headers, @@ -113,6 +112,19 @@ class RPClient { return RestClient.request('GET', url, {}, { headers: this.headers }); } + triggerAnalyticsEvent() { + if (this.config.disableGA) { + return; + } + + if (this.analytics.agentParams) { + const label = getAgentEventLabel(this.analytics.agentParams); + this.analytics.trackEvent(Object.assign(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label })); + } else { + this.analytics.trackEvent(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH); + } + } + /** * Start launch and report it. * @param {Object} launchDataRQ - request object. @@ -189,12 +201,7 @@ class RPClient { }); }); } - if (this.analytics.agentParams) { - const label = getAgentEventLabel(this.analytics.agentParams); - this.analytics.trackEvent(Object.assign(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label })); - } else { - this.analytics.trackEvent(CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH); - } + this.triggerAnalyticsEvent(); return { tempId, promise: this.map[tempId].promiseStart, @@ -639,10 +646,9 @@ class RPClient { url, this.buildMultiPartStream([saveLogRQ], fileObj, MULTIPART_BOUNDARY), { - headers: { - ...this.headers, + headers: Object.assign(this.headers, { 'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}`, - }, + }), }, ) .then(response => response) diff --git a/package-lock.json b/package-lock.json index aed0774..bca7ab2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -123,15 +123,15 @@ } }, "@tootallnate/once": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.0.0.tgz", - "integrity": "sha512-KYyTT/T6ALPkIRd2Ge080X/BsXvy9O0hcWTtMWkPvwAwF99+vn6Dv4GzrFT/Nn1LePr+FFDbRXXlqmsy9lw2zA==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", + "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", "dev": true }, "acorn": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", - "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz", + "integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA==", "dev": true }, "acorn-jsx": { @@ -141,9 +141,9 @@ "dev": true }, "agent-base": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.0.tgz", - "integrity": "sha512-j1Q7cSCqN+AwrmDd+pzgqc0/NpC655x2bUf5ZjRIO77DcNBFmh+OgRNzF6OKdCC9RSCb19fGd99+bhXFdkRNqw==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.1.tgz", + "integrity": "sha512-01q25QQDwLSsyfhrKbn8yuur+JNw0H+0Y4JiGIKd3z9aYk/w/2kxD/Upc+t2ZBBSUNff50VjPsSW2YxM8QYKVg==", "dev": true, "requires": { "debug": "4" @@ -432,9 +432,9 @@ } }, "codecov": { - "version": "3.6.5", - "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.6.5.tgz", - "integrity": "sha512-v48WuDMUug6JXwmmfsMzhCHRnhUf8O3duqXvltaYJKrO1OekZWpB/eH6iIoaxMl8Qli0+u3OxptdsBOYiD7VAQ==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.7.1.tgz", + "integrity": "sha512-JHWxyPTkMLLJn9SmKJnwAnvY09kg2Os2+Ux+GG7LwZ9g8gzDDISpIN5wAsH1UBaafA/yGcd3KofMaorE8qd6Lw==", "dev": true, "requires": { "argv": "0.0.2", @@ -1788,9 +1788,9 @@ } }, "lodash": { - "version": "4.17.13", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.13.tgz", - "integrity": "sha512-vm3/XWXfWtRua0FkUyEHBZy8kCPjErNBT9fJx8Zvs+U6zjqPbTUOpkaoum3O5uiA8sm+yNMHXfYkTUHFoMxFNA==", + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", + "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", "dev": true }, "lodash.flattendeep": { diff --git a/package.json b/package.json index 5e2f84c..d50197e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test:coverage": "nyc report --reporter=lcov --reporter=text-summary" }, "devDependencies": { - "codecov": "3.6.5", + "codecov": "3.7.1", "eslint": "5.16.0", "eslint-config-airbnb-base": "^13.1.0", "eslint-plugin-import": "^2.17.0", diff --git a/spec/report-portal-client.spec.js b/spec/report-portal-client.spec.js index 79e784d..6e111d0 100644 --- a/spec/report-portal-client.spec.js +++ b/spec/report-portal-client.spec.js @@ -88,6 +88,53 @@ describe('ReportPortal javascript client', () => { }); }); + describe('triggerAnalyticsEvent', () => { + it('should not call analytics.trackEvent if disableGA is true', () => { + const client = new RPClient({ + token: 'startLaunchTest', + endpoint: 'https://rp.us/api/v1', + project: 'tst', + disableGA: true, + }); + spyOn(events, 'getAgentEventLabel').and.returnValue('name|version'); + spyOn(client.analytics, 'trackEvent'); + + client.triggerAnalyticsEvent(); + + expect(client.analytics.trackEvent).not.toHaveBeenCalled(); + }); + + it('should call analytics.trackEvent with label if agentParams is not empty', () => { + const client = new RPClient({ + token: 'startLaunchTest', + endpoint: 'https://rp.us/api/v1', + project: 'tst', + }); + client.analytics.agentParams = { name: 'name', version: 'version' }; + spyOn(events, 'getAgentEventLabel').and.returnValue('name|version'); + spyOn(client.analytics, 'trackEvent'); + + client.triggerAnalyticsEvent(); + + expect(client.analytics.trackEvent).toHaveBeenCalledWith( + Object.assign(events.CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label: 'name|version' }), + ); + }); + + it('should call analytics.trackEvent without label if agentParams is empty', () => { + const client = new RPClient({ + token: 'startLaunchTest', + endpoint: 'https://rp.us/api/v1', + project: 'tst', + }); + spyOn(client.analytics, 'trackEvent'); + + client.triggerAnalyticsEvent(); + + expect(client.analytics.trackEvent).toHaveBeenCalledWith(events.CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH); + }); + }); + describe('startLaunch', () => { it('should call restClient with suitable parameters', () => { const fakeSystemAttr = [{ @@ -152,42 +199,6 @@ describe('ReportPortal javascript client', () => { }, { headers: client.headers }); }); - it('should call analytics.trackEvent with label if agentParams is not empty', () => { - const client = new RPClient({ - token: 'startLaunchTest', - endpoint: 'https://rp.us/api/v1', - project: 'tst', - }); - const time = 12345734; - client.analytics.agentParams = { name: 'name', version: 'version' }; - spyOn(events, 'getAgentEventLabel').and.returnValue('name|version'); - spyOn(client.analytics, 'trackEvent'); - - client.startLaunch({ - startTime: time, - }); - - expect(client.analytics.trackEvent).toHaveBeenCalledWith( - Object.assign(events.CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH, { label: 'name|version' }), - ); - }); - - it('should call analytics.trackEvent without label if agentParams is empty', () => { - const client = new RPClient({ - token: 'startLaunchTest', - endpoint: 'https://rp.us/api/v1', - project: 'tst', - }); - const time = 12345734; - spyOn(client.analytics, 'trackEvent'); - - client.startLaunch({ - startTime: time, - }); - - expect(client.analytics.trackEvent).toHaveBeenCalledWith(events.CLIENT_JAVASCRIPT_EVENTS.START_LAUNCH); - }); - it('dont start new launch if launchDataRQ.id is not empty', () => { const client = new RPClient({ token: 'startLaunchTest', endpoint: 'https://rp.us/api/v1', project: 'tst' }); const myPromise = Promise.resolve({ id: 'testidlaunch' });