diff --git a/src/testObservability.js b/src/testObservability.js index 56ca7e2..eb04010 100644 --- a/src/testObservability.js +++ b/src/testObservability.js @@ -8,6 +8,7 @@ const {makeRequest} = require('./utils/requestHelper'); const CrashReporter = require('./utils/crashReporter'); const Logger = require('./utils/logger'); const {API_URL, TAKE_SCREENSHOT_REGEX} = require('./utils/constants'); +const OrchestrationUtils = require('./testorchestration/orchestrationUtils'); const hooksMap = {}; class TestObservability { @@ -111,7 +112,8 @@ class TestObservability { frameworkName: helper.getFrameworkName(this._testRunner), frameworkVersion: helper.getPackageVersion('nightwatch'), sdkVersion: helper.getAgentVersion() - } + }, + test_orchestration: this.getTestOrchestrationBuildStartData(this._parentSettings) }; const config = { @@ -151,6 +153,11 @@ class TestObservability { process.env.BROWSERSTACK_TEST_REPORTING = false; } } + getTestOrchestrationBuildStartData(settings) { + const orchestrationUtils = OrchestrationUtils.getInstance(settings); + + return orchestrationUtils.getBuildStartData(); + } async stopBuildUpstream () { if (!process.env.BS_TESTOPS_BUILD_COMPLETED) { diff --git a/src/testorchestration/orchestrationUtils.js b/src/testorchestration/orchestrationUtils.js index f93bd28..c9965f6 100644 --- a/src/testorchestration/orchestrationUtils.js +++ b/src/testorchestration/orchestrationUtils.js @@ -2,7 +2,6 @@ const path = require('path'); const fs = require('fs'); const {tmpdir} = require('os'); const Logger = require('../utils/logger'); -const {getHostInfo} = require('../utils/helper'); const RequestUtils = require('./requestUtils'); const helper = require('../utils/helper'); // Constants @@ -307,12 +306,16 @@ class OrchestrationUtils { const getFeatureBranch = (name, repoInfo) => { // 1. Check in environment variable map - if (featureBranchEnvMap[name]) { - return featureBranchEnvMap[name]; + if (featureBranchEnvMap && featureBranchEnvMap[name]) { + const val = featureBranchEnvMap[name]; + + return typeof val === 'string' ? val.trim() : val; } // 2. Check in repo_info - if (repoInfo.featureBranch) { - return repoInfo.featureBranch; + if (repoInfo && repoInfo.featureBranch) { + const val = repoInfo.featureBranch; + + return typeof val === 'string' ? val.trim() : val; } return null; @@ -327,7 +330,7 @@ class OrchestrationUtils { continue; } - if (!repoInfo.url) { + if (!repoInfo.url || String(repoInfo.url).trim() === '') { this.logger.warn(`Repository URL is missing for source '${name}': ${JSON.stringify(repoInfo)}`); continue; } @@ -348,7 +351,7 @@ class OrchestrationUtils { repoInfoCopy.name = name; repoInfoCopy.featureBranch = getFeatureBranch(name, repoInfo); - if (!repoInfoCopy.featureBranch) { + if (!repoInfoCopy.featureBranch || repoInfoCopy.featureBranch === '') { this.logger.warn(`Feature branch not specified for source '${name}': ${JSON.stringify(repoInfo)}`); continue; } @@ -414,7 +417,7 @@ class OrchestrationUtils { /** * Get build start data */ - getBuildStartData(config) { + getBuildStartData() { const testOrchestrationData = {}; testOrchestrationData['run_smart_selection'] = { @@ -442,7 +445,7 @@ class OrchestrationUtils { buildRunIdentifier: this.getBuildIdentifier(), nodeIndex: parseInt(process.env.BROWSERSTACK_NODE_INDEX || '0', 10), totalNodes: parseInt(process.env.BROWSERSTACK_TOTAL_NODE_COUNT || '1', 10), - hostInfo: getHostInfo() + hostInfo: helper.getHostInfo() }; this.logger.debug(`[collectBuildData] Sending build data payload: ${JSON.stringify(payload)}`); diff --git a/src/utils/helper.js b/src/utils/helper.js index 4202d44..1054240 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -1057,7 +1057,7 @@ function getBaseBranch() { try { const originHeadOutput = execSync('git symbolic-ref refs/remotes/origin/HEAD').toString().trim(); if (originHeadOutput.startsWith('refs/remotes/origin/')) { - return originHeadOutput.replace('refs/remotes/origin/', ''); + return originHeadOutput.replace('refs/remotes/', ''); } } catch (e) { // Symbolic ref might not exist