Skip to content

Commit

Permalink
[test optimization] Configuration parameter to disable git unshallow (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariovido authored Feb 20, 2025
1 parent 4733649 commit 23abc09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const FormData = require('../../../exporters/common/form-data')
const request = require('../../../exporters/common/request')

const log = require('../../../log')
const { isFalse } = require('../../../util')
const {
getLatestCommits,
getRepositoryUrl,
Expand Down Expand Up @@ -284,7 +285,9 @@ function sendGitMetadata (url, { isEvpProxy, evpProxyPrefix }, configRepositoryU
}
// Otherwise we unshallow and get commits to upload again
log.debug('It is shallow clone, unshallowing...')
unshallowRepository()
if (!isFalse(process.env.DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED)) {
unshallowRepository()
}

// The latest commits change after unshallowing
latestCommits = getLatestCommits()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('git_metadata', () => {

after(() => {
delete process.env.DD_API_KEY
delete process.env.DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED
fs.unlinkSync(temporaryPackFile)
fs.unlinkSync(secondTemporaryPackFile)
})
Expand Down Expand Up @@ -97,6 +98,25 @@ describe('git_metadata', () => {
})
})

it('should not unshallow if the parameter to enable unshallow is false', (done) => {
process.env.DD_CIVISIBILITY_GIT_UNSHALLOW_ENABLED = false
const scope = nock('https://api.test.com')
.post('/api/v2/git/repository/search_commits')
.reply(200, JSON.stringify({ data: [] }))
.post('/api/v2/git/repository/search_commits') // calls a second time after unshallowing
.reply(200, JSON.stringify({ data: [] }))
.post('/api/v2/git/repository/packfile')
.reply(204)

isShallowRepositoryStub.returns(true)
gitMetadata.sendGitMetadata(new URL('https://api.test.com'), { isEvpProxy: false }, '', (err) => {
expect(unshallowRepositoryStub).not.to.have.been.called
expect(err).to.be.null
expect(scope.isDone()).to.be.true
done()
})
})

it('should request to /api/v2/git/repository/search_commits and /api/v2/git/repository/packfile', (done) => {
const scope = nock('https://api.test.com')
.post('/api/v2/git/repository/search_commits')
Expand Down

0 comments on commit 23abc09

Please sign in to comment.