Skip to content

Commit

Permalink
[ci-visibility] More verbose logging for git upload (#3251)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez authored and tlhunter committed Jun 29, 2023
1 parent 7b729a1 commit c0b2da9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 12 additions & 0 deletions packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function getCommonRequestOptions (url) {
*/
function getCommitsToExclude ({ url, isEvpProxy, repositoryUrl }, callback) {
const latestCommits = getLatestCommits()

log.debug(`There were ${latestCommits.length} commits since last month.`)

const [headCommit] = latestCommits

const commonOptions = getCommonRequestOptions(url)
Expand Down Expand Up @@ -158,26 +161,35 @@ function sendGitMetadata (url, isEvpProxy, configRepositoryUrl, callback) {
repositoryUrl = getRepositoryUrl()
}

log.debug(`Uploading git history for repository ${repositoryUrl}`)

if (!repositoryUrl) {
return callback(new Error('Repository URL is empty'))
}

if (isShallowRepository()) {
log.debug('It is shallow clone, unshallowing...')
unshallowRepository()
}

getCommitsToExclude({ url, repositoryUrl, isEvpProxy }, (err, commitsToExclude, headCommit) => {
if (err) {
return callback(err)
}
log.debug(`There are ${commitsToExclude.length} commits to exclude.`)

const commitsToUpload = getCommitsToUpload(commitsToExclude)

if (!commitsToUpload.length) {
log.debug('No commits to upload')
return callback(null)
}
log.debug(`There are ${commitsToUpload.length} commits to upload`)

const packFilesToUpload = generatePackFilesForCommits(commitsToUpload)

log.debug(`Uploading ${packFilesToUpload.length} packfiles.`)

if (!packFilesToUpload.length) {
return callback(new Error('Failed to generate packfiles'))
}
Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/src/plugins/util/exec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const cp = require('child_process')
const log = require('../../log')

const sanitizedExec = (cmd, flags, options = { stdio: 'pipe' }) => {
try {
return cp.execFileSync(cmd, flags, options).toString().replace(/(\r\n|\n|\r)/gm, '')
} catch (e) {
log.error(e)
return ''
}
}
Expand Down
12 changes: 4 additions & 8 deletions packages/dd-trace/src/plugins/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ function isShallowRepository () {
}

function unshallowRepository () {
try {
sanitizedExec('git', ['config', 'remote.origin.partialclonefilter', '"blob:none"'])
sanitizedExec('git', ['fetch', '--shallow-since="1 month ago"', '--update-shallow', '--refetch'])
} catch (err) {
log.error(err)
}
sanitizedExec('git', ['config', 'remote.origin.partialclonefilter', '"blob:none"'])
sanitizedExec('git', ['fetch', '--shallow-since="1 month ago"', '--update-shallow', '--refetch'])
}

function getRepositoryUrl () {
Expand All @@ -55,7 +51,7 @@ function getLatestCommits () {
.split('\n')
.filter(commit => commit)
} catch (err) {
log.error(err)
log.error(`Get latest commits failed: ${err.message}`)
return []
}
}
Expand All @@ -80,7 +76,7 @@ function getCommitsToUpload (commitsToExclude) {
.split('\n')
.filter(commit => commit)
} catch (err) {
log.error(err)
log.error(`Get commits to upload failed: ${err.message}`)
return []
}
}
Expand Down

0 comments on commit c0b2da9

Please sign in to comment.