Skip to content

Commit

Permalink
Merge pull request #2 from agoda-com/feature/make-generic
Browse files Browse the repository at this point in the history
to be more generic
  • Loading branch information
vpiyachinda committed Feb 7, 2024
2 parents e8aa98c + 25457cb commit aba2d05
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/common/getMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,26 @@ function getMetadata(runner: string): IMetadata {
if (repoName?.endsWith('.git')) {
repoName = repoName?.substring(0, repoName?.lastIndexOf('.'));
}
const ci_unique_run_id = process.env.GITHUB_RUN_ID?.concat('_').concat(process.env.GITHUB_RUN_NUMBER || '1');
// to support both gitlab and github
const ciJobId = process.env.CI_JOB_ID || process.env.GITHUB_RUN_ID?.concat('_').concat(process.env.GITHUB_RUN_NUMBER || '1');
const branch = process.env.CI_COMMIT_REF_NAME || process.env.GITHUB_REF_NAME;
const username = process.env.GITLAB_USER_LOGIN || process.env.GITHUB_TRIGGERING_ACTOR;

return {
branch: process.env.GITHUB_REF_NAME || gitBranch,
branch: branch || gitBranch,
projectName: repoName,
repository: gitProjectUrl,
repositoryName: repoName,
hostname: os.hostname(),
username: process.env.GITHUB_TRIGGERING_ACTOR || (userInfo ? userInfo.username : null),
username: username || (userInfo ? userInfo.username : null),
os: os.type(),
osVersion: os.release(),
gitCommitDate: gitCommitDate ? gitCommitDate.toISO() : null,
gitHeadCommit: gitHeadCommit,
testRunner: runner,
testRunnerVersion: testRunnerVersion,
cpuCount: os.cpus().length,
id: ci_unique_run_id || uuid4()
id: ciJobId || uuid4()
};
}

Expand Down
4 changes: 1 addition & 3 deletions src/jest/publishJestMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import getMetadata from '../common/getMetadata';
import { IMetadata, IJestTestResults } from '../common/types';

function publishJestMetrics(result: any) {
const JEST_TESTDATA_API_URL: string = process.env.JEST_TESTDATA_API_URL
? process.env.JEST_TESTDATA_API_URL
: 'http://your_domain/your_jest_api'; // TODO change to your api endpoint
const JEST_TESTDATA_API_URL: string = process.env.JEST_TESTDATA_API_URL ?? '<unknown>'; // your api endpoint eg. 'http://your_domain/jest'

const metadata: IMetadata = getMetadata('jest');
const payload: IJestTestResults = {
Expand Down
4 changes: 1 addition & 3 deletions src/playwright/publishPlaywrightMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class PublishLocalPlaywrightMetrics implements Reporter {
if (!this.junitOutputFile) {
return;
}
const PLAYWRIGHT_TESTDATA_API_URL: string = process.env.PLAYWRIGHT_TESTDATA_API_URL
? process.env.PLAYWRIGHT_TESTDATA_API_URL
: 'http://your_domain/testdata/junit'; // TODO change to your api endpoint
const PLAYWRIGHT_TESTDATA_API_URL: string = process.env.PLAYWRIGHT_TESTDATA_API_URL ?? '<unknown>'; // your api endpoint eg. 'http://your_domain/testdata/junit'
const formdata = new FormData();
Object.entries(getMetadata("playwright")).forEach(([key, value]) => {
if (value !== null && value !== undefined) {
Expand Down

0 comments on commit aba2d05

Please sign in to comment.