Skip to content

Commit

Permalink
Merge pull request #1427 from DataDog/juli1/STAL-2160
Browse files Browse the repository at this point in the history
[STAL-2160] Show message when default branch not found
  • Loading branch information
juli1 authored Aug 26, 2024
2 parents 1bdf92d + 8577e4c commit d74e427
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/commands/sbom/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export const renderDuplicateUpload = (sha: string, env: string, service: string)
return fullStr
}

export const renderNoDefaultBranch = (repositoryUrl: string) => {
let fullStr = ''

fullStr += chalk.red(`Default branch not found for repository ${repositoryUrl}\n`)
fullStr += chalk.red(`Fix this issue by either:\n`)
fullStr += chalk.red(` - define a default branch in the repository settings on Datadog\n`)
fullStr += chalk.red(` - push result from your default branch first\n\n`)
fullStr += chalk.red(`Run an analysis once the issue is resolved\n`)

return fullStr
}

export const renderFailedUpload = (sbomReport: string, error: any) => {
const reportPath = `[${chalk.bold.dim(sbomReport)}]`

Expand Down
10 changes: 9 additions & 1 deletion src/commands/sbom/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Ajv from 'ajv'
import {AxiosPromise, AxiosResponse, isAxiosError} from 'axios'
import {Command, Option} from 'clipanion'

import {GIT_SHA, getSpanTags, mandatoryGitFields} from '../../helpers/tags'
import {GIT_SHA, getSpanTags, mandatoryGitFields, GIT_REPOSITORY_URL} from '../../helpers/tags'

import {getApiHelper} from './api'
import {generatePayload} from './payload'
Expand All @@ -15,6 +15,7 @@ import {
renderInvalidFile,
renderInvalidPayload,
renderMissingSpan,
renderNoDefaultBranch,
renderSuccessfulCommand,
renderUploading,
} from './renderer'
Expand Down Expand Up @@ -135,6 +136,13 @@ export class UploadSbomCommand extends Command {

return 0
}

if (error.response?.status === 412) {
const repositoryUrl = tags[GIT_REPOSITORY_URL] || 'url-not-found'
this.context.stderr.write(renderNoDefaultBranch(repositoryUrl))

return 1
}
}

this.context.stderr.write(renderFailedUpload(basePath, error))
Expand Down

0 comments on commit d74e427

Please sign in to comment.