Skip to content

Improve mandatory git field checks#1506

Merged
dastrong merged 1 commit into
masterfrom
dastrong/improve-mandatory-git-checks
Dec 19, 2024
Merged

Improve mandatory git field checks#1506
dastrong merged 1 commit into
masterfrom
dastrong/improve-mandatory-git-checks

Conversation

@dastrong

Copy link
Copy Markdown
Contributor

What and why?

In v2.45.0, we introduced mandatory git fields for the sarif and sbom commands. That implementation missed use cases where no .git metadata is available as the returned tags object is empty (code link). Our issue arises because we're looping over this tags object where we're not guaranteed to have all the fields set by default.

No .git exists, but the user sets the following environment variables:

export DD_GIT_REPOSITORY_URL = 'github.com/foo/bar'
export DD_GIT_BRANCH = 'main'
export DD_GIT_COMMIT_AUTHOR_EMAIL = 'test@test.com'
export DD_GIT_COMMIT_AUTHOR_NAME = 'tester'
export DD_GIT_COMMIT_COMMITTER_EMAIL = 'test@test.com'
export DD_GIT_COMMIT_COMMITTER_NAME = 'tester'

This would create this tags object:

{
  "git.repository_url": "github.com/foo/bar",
  "git.branch": "main",
  "git.commit.author.email": "test@test.com",
  "git.commit.author.name": "tester",
  "git.commit.committer.email": "test@test.com",
  "git.commit.committer.name": "tester"
}

When we iterate over this object we missed checking whether git.commit.sha is there and valid.

How?

Iterate over each required git field and check whether they exists in the final tags object to ensure we're checking all requirements each time.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)

@dastrong dastrong added the static-analysis Related to [sarif, sbom] label Dec 18, 2024
@dastrong dastrong requested review from a team as code owners December 18, 2024 16:15
@dastrong dastrong requested review from daniel-mohedano, juli1 and tanishq-dubey and removed request for juli1 December 18, 2024 16:16
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Dec 18, 2024

Copy link
Copy Markdown

Datadog Report

Branch report: dastrong/improve-mandatory-git-checks
Commit report: 0be6e76
Test service: datadog-ci-tests

✅ 0 Failed, 6332 Passed, 0 Skipped, 3m 13.65s Total duration (36.33s time saved)

Remove unused import

Handle CI env vars in tests

Change to github_sha
@dastrong dastrong force-pushed the dastrong/improve-mandatory-git-checks branch from a88c096 to 0be6e76 Compare December 18, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

static-analysis Related to [sarif, sbom]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants