Skip to content

Commit 62593f2

Browse files
authored
[test-optimization] [SDTEST-2034] Send tag when there is no branch (#5770)
1 parent 3ed46b7 commit 62593f2

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

packages/datadog-plugin-cypress/src/cypress-plugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const {
6767
GIT_BRANCH,
6868
CI_PROVIDER_NAME,
6969
CI_WORKSPACE_PATH,
70-
GIT_COMMIT_MESSAGE
70+
GIT_COMMIT_MESSAGE,
71+
GIT_TAG
7172
} = require('../../dd-trace/src/plugins/util/tags')
7273
const {
7374
OS_VERSION,
@@ -206,7 +207,8 @@ class CypressPlugin {
206207
[GIT_BRANCH]: branch,
207208
[CI_PROVIDER_NAME]: ciProviderName,
208209
[CI_WORKSPACE_PATH]: repositoryRoot,
209-
[GIT_COMMIT_MESSAGE]: commitMessage
210+
[GIT_COMMIT_MESSAGE]: commitMessage,
211+
[GIT_TAG]: tag
210212
} = this.testEnvironmentMetadata
211213

212214
this.repositoryRoot = repositoryRoot
@@ -223,7 +225,8 @@ class CypressPlugin {
223225
runtimeVersion,
224226
branch,
225227
testLevel: 'test',
226-
commitMessage
228+
commitMessage,
229+
tag
227230
}
228231
this.finishedTestsByFile = {}
229232
this.testStatuses = {}

packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function getLibraryConfiguration ({
2828
runtimeVersion,
2929
branch,
3030
testLevel = 'suite',
31-
custom
31+
custom,
32+
tag
3233
}, done) {
3334
const options = {
3435
path: '/api/v2/libraries/tests/services/setting',
@@ -69,7 +70,7 @@ function getLibraryConfiguration ({
6970
env,
7071
repository_url: repositoryUrl,
7172
sha,
72-
branch
73+
branch: branch || tag
7374
}
7475
}
7576
})

packages/dd-trace/src/plugins/ci_plugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const {
4545
GIT_COMMIT_SHA,
4646
GIT_BRANCH,
4747
CI_WORKSPACE_PATH,
48-
GIT_COMMIT_MESSAGE
48+
GIT_COMMIT_MESSAGE,
49+
GIT_TAG
4950
} = require('./util/tags')
5051
const { OS_VERSION, OS_PLATFORM, OS_ARCHITECTURE, RUNTIME_NAME, RUNTIME_VERSION } = require('./util/env')
5152
const getDiClient = require('../ci-visibility/dynamic-instrumentation')
@@ -253,7 +254,8 @@ module.exports = class CiPlugin extends Plugin {
253254
[GIT_BRANCH]: branch,
254255
[CI_PROVIDER_NAME]: ciProviderName,
255256
[CI_WORKSPACE_PATH]: repositoryRoot,
256-
[GIT_COMMIT_MESSAGE]: commitMessage
257+
[GIT_COMMIT_MESSAGE]: commitMessage,
258+
[GIT_TAG]: tag
257259
} = this.testEnvironmentMetadata
258260

259261
this.repositoryRoot = repositoryRoot || process.cwd()
@@ -272,7 +274,8 @@ module.exports = class CiPlugin extends Plugin {
272274
runtimeVersion,
273275
branch,
274276
testLevel: 'suite',
275-
commitMessage
277+
commitMessage,
278+
tag
276279
}
277280
}
278281

packages/dd-trace/test/ci-visibility/exporters/ci-visibility-exporter.spec.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,44 @@ describe('CI Visibility Exporter', () => {
151151
})
152152
ciVisibilityExporter._resolveCanUseCiVisProtocol(true)
153153
})
154-
154+
it('should handle git metadata with tag but no branch', (done) => {
155+
let requestBody
156+
const scope = nock(`http://localhost:${port}`)
157+
.post('/api/v2/libraries/tests/services/setting', function (body) {
158+
requestBody = body
159+
return true
160+
})
161+
.reply(200, JSON.stringify({
162+
data: {
163+
attributes: {
164+
itr_enabled: true,
165+
require_git: false,
166+
code_coverage: true,
167+
tests_skipping: true
168+
}
169+
}
170+
}))
171+
const ciVisibilityExporter = new CiVisibilityExporter({
172+
port,
173+
isIntelligentTestRunnerEnabled: true
174+
})
175+
const testConfiguration = {
176+
tag: 'v1.0.0'
177+
}
178+
ciVisibilityExporter.getLibraryConfiguration(testConfiguration, (err, libraryConfig) => {
179+
expect(err).to.be.null
180+
expect(libraryConfig).to.contain({
181+
requireGit: false,
182+
isCodeCoverageEnabled: true,
183+
isItrEnabled: true,
184+
isSuitesSkippingEnabled: true
185+
})
186+
expect(scope.isDone()).to.be.true
187+
expect(requestBody.data.attributes.branch).to.equal('v1.0.0')
188+
done()
189+
})
190+
ciVisibilityExporter._resolveCanUseCiVisProtocol(true)
191+
})
155192
it('should request the API after EVP proxy is resolved', (done) => {
156193
const scope = nock(`http://localhost:${port}`)
157194
.post('/api/v2/libraries/tests/services/setting')

0 commit comments

Comments
 (0)