From 7f6165d9e584e22feff4fdae5640eb35d9e0af6e Mon Sep 17 00:00:00 2001 From: Anudeep Date: Wed, 25 Dec 2024 12:55:53 +0530 Subject: [PATCH 1/2] chore: refactor ci info --- package-lock.json | 4 +- package.json | 2 +- src/helpers/ci/azure-devops.js | 54 ++++++------- src/helpers/ci/base.ci.js | 134 +++++++++++++++++++++++++++++++++ src/helpers/ci/circle-ci.js | 47 ++++++------ src/helpers/ci/github.js | 54 +++++++------ src/helpers/ci/gitlab.js | 55 +++++++------- src/helpers/ci/index.js | 53 +++++-------- src/helpers/ci/jenkins.js | 54 +++++++------ src/helpers/ci/system.js | 30 -------- 10 files changed, 286 insertions(+), 201 deletions(-) create mode 100644 src/helpers/ci/base.ci.js delete mode 100644 src/helpers/ci/system.js diff --git a/package-lock.json b/package-lock.json index 8aae27b..495a5bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "testbeats", - "version": "2.1.7", + "version": "2.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "testbeats", - "version": "2.1.7", + "version": "2.2.0", "license": "ISC", "dependencies": { "async-retry": "^1.3.3", diff --git a/package.json b/package.json index 56b77df..479c00e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "testbeats", - "version": "2.1.7", + "version": "2.2.0", "description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB", "main": "src/index.js", "types": "./src/index.d.ts", diff --git a/src/helpers/ci/azure-devops.js b/src/helpers/ci/azure-devops.js index 80dced1..646e326 100644 --- a/src/helpers/ci/azure-devops.js +++ b/src/helpers/ci/azure-devops.js @@ -1,37 +1,37 @@ +const { BaseCI } = require('./base.ci'); + const ENV = process.env; -/** - * @returns {import('../../extensions/extensions').ICIInfo} - */ -function info() { - const azure_devops = { - ci: 'AZURE_DEVOPS_PIPELINES', - git: 'AZURE_DEVOPS_REPOS', - repository_url: ENV.BUILD_REPOSITORY_URI, - repository_name: ENV.BUILD_REPOSITORY_NAME, - repository_ref: ENV.BUILD_SOURCEBRANCH, - repository_commit_sha: ENV.BUILD_SOURCEVERSION, - branch_url: '', - branch_name: '', - pull_request_url:'', - pull_request_name: '', - build_url: ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID, - build_number: ENV.BUILD_BUILDNUMBER, - build_name: ENV.BUILD_DEFINITIONNAME, - build_reason: ENV.BUILD_REASON, - user: ENV.BUILD_REQUESTEDFOR +class AzureDevOpsCI extends BaseCI { + constructor() { + super(); + this.init(); } - azure_devops.branch_url = azure_devops.repository_url + azure_devops.repository_ref.replace('refs/heads/', '/tree/'); - azure_devops.branch_name = azure_devops.repository_ref.replace('refs/heads/', ''); + init() { + this.setInfo(this.targets.ci, 'AZURE_DEVOPS_PIPELINES'); + this.setInfo(this.targets.git, 'AZURE_DEVOPS_REPOS'); + this.setInfo(this.targets.repository_url, ENV.BUILD_REPOSITORY_URI); + this.setInfo(this.targets.repository_name, ENV.BUILD_REPOSITORY_NAME); + this.setInfo(this.targets.repository_ref, ENV.BUILD_SOURCEBRANCH); + this.setInfo(this.targets.repository_commit_sha, ENV.BUILD_SOURCEVERSION); + this.setInfo(this.targets.build_url, ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + ENV.SYSTEM_TEAMPROJECT + '/_build/results?buildId=' + ENV.BUILD_BUILDID); + this.setInfo(this.targets.build_number, ENV.BUILD_BUILDNUMBER); + this.setInfo(this.targets.build_name, ENV.BUILD_DEFINITIONNAME); + this.setInfo(this.targets.build_reason, ENV.BUILD_REASON); + + this.setInfo(this.targets.branch_url, this.repository_url + this.repository_ref.replace('refs/heads/', '/tree/')); + this.setInfo(this.targets.branch_name, this.repository_ref.replace('refs/heads/', '')); + + if (this.repository_ref.includes('refs/pull')) { + this.setInfo(this.targets.pull_request_url, this.repository_url + this.repository_ref.replace('refs/pull/', '/pull/')); + this.setInfo(this.targets.pull_request_name, this.repository_ref.replace('refs/pull/', '').replace('/merge', '')); + } - if (azure_devops.repository_ref.includes('refs/pull')) { - azure_devops.pull_request_url = azure_devops.repository_url + azure_devops.repository_ref.replace('refs/pull/', '/pull/'); - azure_devops.pull_request_name = azure_devops.repository_ref.replace('refs/pull/', '').replace('/merge', ''); + this.setInfo(this.targets.user, ENV.BUILD_REQUESTEDFOR, true); } - return azure_devops; } module.exports = { - info + AzureDevOpsCI } diff --git a/src/helpers/ci/base.ci.js b/src/helpers/ci/base.ci.js new file mode 100644 index 0000000..b019c6d --- /dev/null +++ b/src/helpers/ci/base.ci.js @@ -0,0 +1,134 @@ +const os = require('os'); +const pkg = require('../../../package.json'); + +const ENV = process.env; + +class BaseCI { + ci = ''; + git = ''; + repository_url = ''; + repository_name = ''; + repository_ref = ''; + repository_commit_sha = ''; + branch_url = ''; + branch_name = ''; + pull_request_url = ''; + pull_request_name = ''; + build_url = ''; + build_number = ''; + build_name = ''; + build_reason = ''; + user = ''; + runtime = ''; + runtime_version = ''; + os = ''; + os_version = ''; + testbeats_version = ''; + + targets = { + ci: 'ci', + git: 'git', + repository_url: 'repository_url', + repository_name: 'repository_name', + repository_ref: 'repository_ref', + repository_commit_sha: 'repository_commit_sha', + branch_url: 'branch_url', + branch_name: 'branch_name', + pull_request_url: 'pull_request_url', + pull_request_name: 'pull_request_name', + build_url: 'build_url', + build_number: 'build_number', + build_name: 'build_name', + build_reason: 'build_reason', + user: 'user', + runtime: 'runtime', + runtime_version: 'runtime_version', + os: 'os', + os_version: 'os_version', + testbeats_version: 'testbeats_version' + } + + constructor() { + this.setDefaultInformation(); + } + + setDefaultInformation() { + this.ci = ENV.TEST_BEATS_CI_NAME; + this.git = ENV.TEST_BEATS_CI_GIT; + this.repository_url = ENV.TEST_BEATS_CI_REPOSITORY_URL; + this.repository_name = ENV.TEST_BEATS_CI_REPOSITORY_NAME; + this.repository_ref = ENV.TEST_BEATS_CI_REPOSITORY_REF; + this.repository_commit_sha = ENV.TEST_BEATS_CI_REPOSITORY_COMMIT_SHA; + this.branch_url = ENV.TEST_BEATS_BRANCH_URL; + this.branch_name = ENV.TEST_BEATS_BRANCH_NAME; + this.pull_request_url = ENV.TEST_BEATS_PULL_REQUEST_URL; + this.pull_request_name = ENV.TEST_BEATS_PULL_REQUEST_NAME; + this.build_url = ENV.TEST_BEATS_CI_BUILD_URL; + this.build_number = ENV.TEST_BEATS_CI_BUILD_NUMBER; + this.build_name = ENV.TEST_BEATS_CI_BUILD_NAME; + this.build_reason = ENV.TEST_BEATS_CI_BUILD_REASON; + this.user = ENV.TEST_BEATS_CI_USER || os.userInfo().username; + + const runtime = this.#getRuntimeInfo(); + this.runtime = runtime.name; + this.runtime_version = runtime.version; + this.os = os.platform(); + this.os_version = os.release(); + this.testbeats_version = pkg.version; + + } + + #getRuntimeInfo() { + if (typeof process !== 'undefined' && process.versions && process.versions.node) { + return { name: 'node', version: process.versions.node }; + } else if (typeof Deno !== 'undefined') { + return { name: 'deno', version: Deno.version.deno }; + } else if (typeof Bun !== 'undefined') { + return { name: 'bun', version: Bun.version }; + } else { + return { name: 'unknown', version: 'unknown' }; + } + } + + setInfo(target, value, force = false) { + if (force && value) { + this[target] = value; + return; + } + if (!this[target]) { + this[target] = value; + } + } + + /** + * + * @returns {import('../../extensions/extensions').ICIInfo} + */ + info() { + return { + ci: this.ci, + git: this.git, + repository_url: this.repository_url, + repository_name: this.repository_name, + repository_ref: this.repository_ref, + repository_commit_sha: this.repository_commit_sha, + branch_url: this.branch_url, + branch_name: this.branch_name, + pull_request_url: this.pull_request_url, + pull_request_name: this.pull_request_name, + build_url: this.build_url, + build_number: this.build_number, + build_name: this.build_name, + build_reason: this.build_reason, + user: this.user, + runtime: this.runtime, + runtime_version: this.runtime_version, + os: this.os, + os_version: this.os_version, + testbeats_version: this.testbeats_version + } + } + +} + +module.exports = { BaseCI }; \ No newline at end of file diff --git a/src/helpers/ci/circle-ci.js b/src/helpers/ci/circle-ci.js index 0df224f..652786c 100644 --- a/src/helpers/ci/circle-ci.js +++ b/src/helpers/ci/circle-ci.js @@ -1,29 +1,32 @@ +const { BaseCI } = require('./base.ci'); + const ENV = process.env; -/** - * @returns {import('../../extensions/extensions').ICIInfo} - */ -function info() { - const circle = { - ci: 'CIRCLE_CI', - git: '', - repository_url: ENV.CIRCLE_REPOSITORY_URL, - repository_name: ENV.CIRCLE_PROJECT_REPONAME, // Need to find a better match - repository_ref: ENV.CIRCLE_BRANCH, - repository_commit_sha: ENV.CIRCLE_SHA1, - branch_url: '', - branch_name: ENV.CIRCLE_BRANCH, - pull_request_url:'', - pull_request_name: '', - build_url: ENV.CIRCLE_BUILD_URL, - build_number: ENV.CIRCLE_BUILD_NUM, - build_name: ENV.CIRCLE_JOB, - build_reason: 'Push', - user: ENV.CIRCLE_USERNAME, +class CircleCI extends BaseCI { + constructor() { + super(); + this.init(); + } + + init() { + this.setInfo(this.targets.ci, 'CIRCLE_CI'); + this.setInfo(this.targets.git, ''); + this.setInfo(this.targets.repository_url, ENV.CIRCLE_REPOSITORY_URL); + this.setInfo(this.targets.repository_name, ENV.CIRCLE_PROJECT_REPONAME); + this.setInfo(this.targets.repository_ref, ENV.CIRCLE_BRANCH); + this.setInfo(this.targets.repository_commit_sha, ENV.CIRCLE_SHA1); + this.setInfo(this.targets.branch_url, ''); + this.setInfo(this.targets.branch_name, ENV.CIRCLE_BRANCH); + this.setInfo(this.targets.pull_request_url,''); + this.setInfo(this.targets.pull_request_name, ''); + this.setInfo(this.targets.build_url, ENV.CIRCLE_BUILD_URL); + this.setInfo(this.targets.build_number, ENV.CIRCLE_BUILD_NUM); + this.setInfo(this.targets.build_name, ENV.CIRCLE_JOB); + this.setInfo(this.targets.build_reason, 'Push'); + this.setInfo(this.targets.user, ENV.CIRCLE_USERNAME, true); } - return circle } module.exports = { - info + CircleCI } diff --git a/src/helpers/ci/github.js b/src/helpers/ci/github.js index 373661b..24ca4ce 100644 --- a/src/helpers/ci/github.js +++ b/src/helpers/ci/github.js @@ -1,38 +1,36 @@ +const { BaseCI } = require('./base.ci'); + const ENV = process.env; -/** - * @returns {import('../../extensions/extensions').ICIInfo} - */ -function info() { - const github = { - ci: 'GITHUB_ACTIONS', - git: 'GITHUB', - repository_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY, - repository_name: ENV.GITHUB_REPOSITORY, - repository_ref: ENV.GITHUB_REF, - repository_commit_sha: ENV.GITHUB_SHA, - branch_url: '', - branch_name: '', - pull_request_url:'', - pull_request_name: '', - build_url: ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID, - build_number: ENV.GITHUB_RUN_NUMBER, - build_name: ENV.GITHUB_WORKFLOW, - build_reason: ENV.GITHUB_EVENT_NAME, - user: ENV.GITHUB_ACTOR, +class GitHubCI extends BaseCI { + constructor() { + super(); + this.init(); } - github.branch_url = github.repository_url + github.repository_ref.replace('refs/heads/', '/tree/'); - github.branch_name = github.repository_ref.replace('refs/heads/', ''); + init() { + this.setInfo(this.targets.ci, 'GITHUB_ACTIONS'); + this.setInfo(this.targets.git, 'GITHUB'); + this.setInfo(this.targets.repository_url, ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY); + this.setInfo(this.targets.repository_name, ENV.GITHUB_REPOSITORY); + this.setInfo(this.targets.repository_ref, ENV.GITHUB_REF); + this.setInfo(this.targets.repository_commit_sha, ENV.GITHUB_SHA); + this.setInfo(this.targets.build_url, ENV.GITHUB_SERVER_URL + '/' + ENV.GITHUB_REPOSITORY + '/actions/runs/' + ENV.GITHUB_RUN_ID); + this.setInfo(this.targets.build_number, ENV.GITHUB_RUN_NUMBER); + this.setInfo(this.targets.build_name, ENV.GITHUB_WORKFLOW); + this.setInfo(this.targets.build_reason, ENV.GITHUB_EVENT_NAME); + this.setInfo(this.targets.user, ENV.GITHUB_ACTOR, true); - if (github.repository_ref.includes('refs/pull')) { - github.pull_request_url = github.repository_url + github.repository_ref.replace('refs/pull/', '/pull/'); - github.pull_request_name = github.repository_ref.replace('refs/pull/', '').replace('/merge', ''); - } + this.setInfo(this.targets.branch_url, this.repository_url + this.repository_ref.replace('refs/heads/', '/tree/')); + this.setInfo(this.targets.branch_name, this.repository_ref.replace('refs/heads/', '')); - return github + if (this.repository_ref.includes('refs/pull')) { + this.setInfo(this.targets.pull_request_url, this.repository_url + this.repository_ref.replace('refs/pull/', '/pull/')); + this.setInfo(this.targets.pull_request_name, this.repository_ref.replace('refs/pull/', '').replace('/merge', '')); + } + } } module.exports = { - info + GitHubCI } \ No newline at end of file diff --git a/src/helpers/ci/gitlab.js b/src/helpers/ci/gitlab.js index e4a4b18..036ccdc 100644 --- a/src/helpers/ci/gitlab.js +++ b/src/helpers/ci/gitlab.js @@ -1,36 +1,37 @@ +const { BaseCI } = require('./base.ci'); + const ENV = process.env; -/** - * @returns {import('../../extensions/extensions').ICIInfo} - */ -function info() { - const gitlab = { - ci: 'GITLAB', - git: 'GITLAB', - repository_url: ENV.CI_PROJECT_URL, - repository_name: ENV.CI_PROJECT_NAME, - repository_ref: '/-/tree/' + (ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME), - repository_commit_sha: ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA, - branch_url: ENV.CI_PROJECT_URL + '/-/tree/' + (ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH), - branch_name: ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH, - pull_request_url:'', - pull_request_name: '', - build_url: ENV.CI_JOB_URL, - build_number: ENV.CI_JOB_ID, - build_name: ENV.CI_JOB_NAME, - build_reason: ENV.CI_PIPELINE_SOURCE, - user: ENV.GITLAB_USER_LOGIN || ENV.CI_COMMIT_AUTHOR +class GitLabCI extends BaseCI { + constructor() { + super(); + this.init(); } - if (ENV.CI_OPEN_MERGE_REQUESTS) { - const pr_number = ENV.CI_OPEN_MERGE_REQUESTS.split("!")[1]; - gitlab.pull_request_name = "#" + pr_number; - gitlab.pull_request_url = ENV.CI_PROJECT_URL + "/-/merge_requests/" + pr_number; - } + init() { + this.setInfo(this.targets.ci, 'GITLAB'); + this.setInfo(this.targets.git, 'GITLAB'); + this.setInfo(this.targets.repository_url, ENV.CI_PROJECT_URL); + this.setInfo(this.targets.repository_name, ENV.CI_PROJECT_NAME); + this.setInfo(this.targets.repository_ref, '/-/tree/' + (ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME || ENV.CI_COMMIT_REF_NAME)); + this.setInfo(this.targets.repository_commit_sha, ENV.CI_MERGE_REQUEST_SOURCE_BRANCH_SHA || ENV.CI_COMMIT_SHA); + this.setInfo(this.targets.branch_url, ENV.CI_PROJECT_URL + '/-/tree/' + (ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH)); + this.setInfo(this.targets.branch_name, ENV.CI_COMMIT_REF_NAME || ENV.CI_COMMIT_BRANCH); + this.setInfo(this.targets.pull_request_url,''); + this.setInfo(this.targets.pull_request_name, ''); + this.setInfo(this.targets.build_url, ENV.CI_JOB_URL); + this.setInfo(this.targets.build_number, ENV.CI_JOB_ID); + this.setInfo(this.targets.build_name, ENV.CI_JOB_NAME); + this.setInfo(this.targets.build_reason, ENV.CI_PIPELINE_SOURCE); - return gitlab + if (ENV.CI_OPEN_MERGE_REQUESTS) { + const pr_number = ENV.CI_OPEN_MERGE_REQUESTS.split("!")[1]; + this.setInfo(this.targets.pull_request_name, "#" + pr_number); + this.setInfo(this.targets.pull_request_url, ENV.CI_PROJECT_URL + "/-/merge_requests/" + pr_number); + } + } } module.exports = { - info + GitLabCI } diff --git a/src/helpers/ci/index.js b/src/helpers/ci/index.js index 62a8397..65cdff9 100644 --- a/src/helpers/ci/index.js +++ b/src/helpers/ci/index.js @@ -1,10 +1,9 @@ -const os = require('os'); const github = require('./github'); const gitlab = require('./gitlab'); const jenkins = require('./jenkins'); const azure_devops = require('./azure-devops'); const circle_ci = require('./circle-ci'); -const system = require('./system'); +const { BaseCI } = require('./base.ci'); const ENV = process.env; @@ -12,51 +11,33 @@ const ENV = process.env; * @returns {import('../../extensions/extensions').ICIInfo} */ function getCIInformation() { - const ci_info = getBaseCIInfo(); - const system_info = system.info(); - return { - ...ci_info, - ...system_info - } -} - -function getBaseCIInfo() { if (ENV.GITHUB_ACTIONS) { - return github.info(); + const ci = new github.GitHubCI(); + return ci.info(); } + if (ENV.GITLAB_CI) { - return gitlab.info(); + const ci = new gitlab.GitLabCI(); + return ci.info(); } + if (ENV.JENKINS_URL) { - return jenkins.info(); + const ci = new jenkins.JenkinsCI(); + return ci.info(); } + if (ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI) { - return azure_devops.info(); + const ci = new azure_devops.AzureDevOpsCI(); + return ci.info(); } + if (ENV.CIRCLECI) { - return circle_ci.info(); + const ci = new circle_ci.CircleCI(); + return ci.info(); } - return getDefaultInformation(); -} -function getDefaultInformation() { - return { - ci: ENV.TEST_BEATS_CI_NAME, - git: ENV.TEST_BEATS_CI_GIT, - repository_url: ENV.TEST_BEATS_CI_REPOSITORY_URL, - repository_name: ENV.TEST_BEATS_CI_REPOSITORY_NAME, - repository_ref: ENV.TEST_BEATS_CI_REPOSITORY_REF, - repository_commit_sha: ENV.TEST_BEATS_CI_REPOSITORY_COMMIT_SHA, - branch_url: ENV.TEST_BEATS_BRANCH_URL, - branch_name: ENV.TEST_BEATS_BRANCH_NAME, - pull_request_url: ENV.TEST_BEATS_PULL_REQUEST_URL, - pull_request_name: ENV.TEST_BEATS_PULL_REQUEST_NAME, - build_url: ENV.TEST_BEATS_CI_BUILD_URL, - build_number: ENV.TEST_BEATS_CI_BUILD_NUMBER, - build_name: ENV.TEST_BEATS_CI_BUILD_NAME, - build_reason: ENV.TEST_BEATS_CI_BUILD_REASON, - user: ENV.TEST_BEATS_CI_USER || os.userInfo().username - } + const ci = new BaseCI(); + return ci.info(); } module.exports = { diff --git a/src/helpers/ci/jenkins.js b/src/helpers/ci/jenkins.js index aaf5a9c..df8e23d 100644 --- a/src/helpers/ci/jenkins.js +++ b/src/helpers/ci/jenkins.js @@ -1,38 +1,36 @@ +const { BaseCI } = require('./base.ci'); + const ENV = process.env; -/** - * @returns {import('../../extensions/extensions').ICIInfo} - */ -function info() { - const jenkins = { - ci: 'JENKINS', - git: '', - repository_url: ENV.GIT_URL || ENV.GITHUB_URL || ENV.BITBUCKET_URL, - repository_name: ENV.JOB_NAME, - repository_ref: ENV.BRANCH || ENV.BRANCH_NAME, - repository_commit_sha: ENV.GIT_COMMIT || ENV.GIT_COMMIT_SHA || ENV.GITHUB_SHA || ENV.BITBUCKET_COMMIT, - branch_url: '', - branch_name: '', - pull_request_url:'', - pull_request_name: '', - build_url: ENV.BUILD_URL, - build_number: ENV.BUILD_NUMBER, - build_name: ENV.JOB_NAME, - build_reason: ENV.BUILD_CAUSE, - user: ENV.USER || ENV.USERNAME +class JenkinsCI extends BaseCI { + constructor() { + super(); + this.init(); } - jenkins.branch_url = jenkins.repository_url + jenkins.repository_ref.replace('refs/heads/', '/tree/'); - jenkins.branch_name = jenkins.repository_ref.replace('refs/heads/', ''); + init() { + this.setInfo(this.targets.ci, 'JENKINS'); + this.setInfo(this.targets.git, ''); + this.setInfo(this.targets.repository_url, ENV.GIT_URL || ENV.GITHUB_URL || ENV.BITBUCKET_URL); + this.setInfo(this.targets.repository_name, ENV.JOB_NAME); + this.setInfo(this.targets.repository_ref, ENV.BRANCH || ENV.BRANCH_NAME); + this.setInfo(this.targets.repository_commit_sha, ENV.GIT_COMMIT || ENV.GIT_COMMIT_SHA || ENV.GITHUB_SHA || ENV.BITBUCKET_COMMIT); + this.setInfo(this.targets.branch_url, this.repository_url + this.repository_ref.replace('refs/heads/', '/tree/')); + this.setInfo(this.targets.branch_name, this.repository_ref.replace('refs/heads/', '')); - if (jenkins.repository_ref.includes('refs/pull')) { - jenkins.pull_request_url = jenkins.repository_url + jenkins.repository_ref.replace('refs/pull/', '/pull/'); - jenkins.pull_request_name = jenkins.repository_ref.replace('refs/pull/', '').replace('/merge', ''); - } + if (this.repository_ref.includes('refs/pull')) { + this.setInfo(this.targets.pull_request_url, this.repository_url + this.repository_ref.replace('refs/pull/', '/pull/')); + this.setInfo(this.targets.pull_request_name, this.repository_ref.replace('refs/pull/', '').replace('/merge', '')); + } - return jenkins_info; + this.setInfo(this.targets.build_url, ENV.BUILD_URL); + this.setInfo(this.targets.build_number, ENV.BUILD_NUMBER); + this.setInfo(this.targets.build_name, ENV.JOB_NAME); + this.setInfo(this.targets.build_reason, ENV.BUILD_CAUSE); + this.setInfo(this.targets.user, ENV.USER || ENV.USERNAME, true); + } } module.exports = { - info + JenkinsCI } diff --git a/src/helpers/ci/system.js b/src/helpers/ci/system.js deleted file mode 100644 index c5ed804..0000000 --- a/src/helpers/ci/system.js +++ /dev/null @@ -1,30 +0,0 @@ -const os = require('os'); -const pkg = require('../../../package.json'); - -function info() { - function getRuntimeInfo() { - if (typeof process !== 'undefined' && process.versions && process.versions.node) { - return { name: 'node', version: process.versions.node }; - } else if (typeof Deno !== 'undefined') { - return { name: 'deno', version: Deno.version.deno }; - } else if (typeof Bun !== 'undefined') { - return { name: 'bun', version: Bun.version }; - } else { - return { name: 'unknown', version: 'unknown' }; - } - } - - const runtime = getRuntimeInfo(); - - return { - runtime: runtime.name, - runtime_version: runtime.version, - os: os.platform(), - os_version: os.release(), - testbeats_version: pkg.version - } -} - -module.exports = { - info -} \ No newline at end of file From f2d977c9541974b1b612cdaba67c24b31b3f280b Mon Sep 17 00:00:00 2001 From: Anudeep Date: Wed, 25 Dec 2024 12:59:57 +0530 Subject: [PATCH 2/2] chore: update imports --- src/helpers/ci/index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/helpers/ci/index.js b/src/helpers/ci/index.js index 65cdff9..61c7ed9 100644 --- a/src/helpers/ci/index.js +++ b/src/helpers/ci/index.js @@ -1,8 +1,8 @@ -const github = require('./github'); -const gitlab = require('./gitlab'); -const jenkins = require('./jenkins'); -const azure_devops = require('./azure-devops'); -const circle_ci = require('./circle-ci'); +const { GitHubCI } = require('./github'); +const { GitLabCI } = require('./gitlab'); +const { JenkinsCI } = require('./jenkins'); +const { AzureDevOpsCI } = require('./azure-devops'); +const { CircleCI } = require('./circle-ci'); const { BaseCI } = require('./base.ci'); const ENV = process.env; @@ -12,27 +12,27 @@ const ENV = process.env; */ function getCIInformation() { if (ENV.GITHUB_ACTIONS) { - const ci = new github.GitHubCI(); + const ci = new GitHubCI(); return ci.info(); } if (ENV.GITLAB_CI) { - const ci = new gitlab.GitLabCI(); + const ci = new GitLabCI(); return ci.info(); } if (ENV.JENKINS_URL) { - const ci = new jenkins.JenkinsCI(); + const ci = new JenkinsCI(); return ci.info(); } if (ENV.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI) { - const ci = new azure_devops.AzureDevOpsCI(); + const ci = new AzureDevOpsCI(); return ci.info(); } if (ENV.CIRCLECI) { - const ci = new circle_ci.CircleCI(); + const ci = new CircleCI(); return ci.info(); }