Improve mandatory git field checks#1506
Merged
Merged
Conversation
Datadog ReportBranch report: ✅ 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
a88c096 to
0be6e76
Compare
tanishq-dubey
approved these changes
Dec 18, 2024
daniel-mohedano
approved these changes
Dec 19, 2024
Drarig29
approved these changes
Dec 19, 2024
Merged
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why?
In v2.45.0, we introduced mandatory git fields for the
sarifandsbomcommands. That implementation missed use cases where no.gitmetadata 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
.gitexists, but the user sets the following environment variables: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.shais 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