Skip to content

Commit

Permalink
Merge pull request #90 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.0.1
  • Loading branch information
AmsterGet authored Aug 14, 2020
2 parents 68b9b62 + c109e65 commit 182fd90
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 84 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/CI-pipeline.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
45 changes: 28 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 }}
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
coverage.lcov
.nyc_output
coverage/
.npmrc
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage
.nyc_output
.gitignore
.editorconfig
.github/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Changed
- Packages publishing workflow improved
### Added
- The ability to disable google analytics

## [5.0.0] - 2020-06-09
### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5.0.1-SNAPSHOT
2 changes: 1 addition & 1 deletion analytics/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
30 changes: 18 additions & 12 deletions lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
83 changes: 47 additions & 36 deletions spec/report-portal-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [{
Expand Down Expand Up @@ -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' });
Expand Down

0 comments on commit 182fd90

Please sign in to comment.