Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add vcsBaseCommitSha to estimate metadata #3059

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ linters:
disable-all: true
enable:
- bodyclose
- deadcode
- errcheck
- gocritic
- gofmt
Expand All @@ -13,10 +12,8 @@ linters:
- misspell
- revive
- staticcheck
- structcheck
- typecheck
- unused
- varcheck

linters-settings:
gocritic:
Expand Down
20 changes: 20 additions & 0 deletions cmd/infracost/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ func TestDiffWithCompareToFormatJSON(t *testing.T) {
)
}

func TestDiffWithCompareToNoMetadataFormatJSON(t *testing.T) {
dir := path.Join("./testdata", testutil.CalcGoldenFileTestdataDirName())
GoldenFileCommandTest(
t,
testutil.CalcGoldenFileTestdataDirName(),
[]string{
"diff",
"--path",
dir,
"--compare-to",
path.Join(dir, "prior.json"),
"--format",
"json",
}, &GoldenFileOptions{
RunTerraformCLI: true,
IsJSON: true,
},
)
}

func TestDiffWithCompareToPreserveSummary(t *testing.T) {
dir := path.Join("./testdata", testutil.CalcGoldenFileTestdataDirName())
GoldenFileCommandTest(
Expand Down
6 changes: 6 additions & 0 deletions cmd/infracost/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func TestOutputFormatJSON(t *testing.T) {
GoldenFileCommandTest(t, testutil.CalcGoldenFileTestdataDirName(), []string{"output", "--format", "json", "--path", "./testdata/example_out.json", "--path", "./testdata/azure_firewall_out.json"}, opts)
}

func TestOutputDiffFormatJSON(t *testing.T) {
opts := DefaultOptions()
opts.IsJSON = true
GoldenFileCommandTest(t, testutil.CalcGoldenFileTestdataDirName(), []string{"output", "--format", "json", "--path", "./testdata/example_diff_out.json"}, opts)
}

func TestOutputFormatBitbucketCommentWithProjectNames(t *testing.T) {
testName := testutil.CalcGoldenFileTestdataDirName()
GoldenFileCommandTest(t, testName,
Expand Down
8 changes: 8 additions & 0 deletions cmd/infracost/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func runMain(cmd *cobra.Command, runCtx *config.RunContext) error {
logging.Logger.Debug().Err(err).Msgf("failed to fetch vcs metadata for path %s", wd)
}
runCtx.VCSMetadata = metadata
runCtx.VCSMetadata.BaseCommit = vcs.Commit{}

pr, err := newParallelRunner(cmd, runCtx)
if err != nil {
Expand Down Expand Up @@ -126,6 +127,13 @@ func runMain(cmd *cobra.Command, runCtx *config.RunContext) error {
if err != nil {
return err
}
runCtx.VCSMetadata.BaseCommit = vcs.Commit{
SHA: pr.prior.Metadata.CommitSHA,
AuthorName: pr.prior.Metadata.CommitAuthorName,
AuthorEmail: pr.prior.Metadata.CommitAuthorEmail,
Time: pr.prior.Metadata.CommitTimestamp,
Message: pr.prior.Metadata.CommitMessage,
}
}

r.IsCIRun = runCtx.IsCIRun()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"metadata": {
"infracostCommand": "diff",
"vcsBranch": "stub-branch",
"vcsBaseCommitSha": "71785af96bce822bd54f359d0883cfa4ca805432",
"vcsCommitSha": "stub-sha",
"vcsCommitAuthorName": "stub-author",
"vcsCommitAuthorEmail": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"metadata": {
"infracostCommand": "diff",
"vcsBranch": "stub-branch",
"vcsBaseCommitSha": "71785af96bce822bd54f359d0883cfa4ca805432",
"vcsCommitSha": "stub-sha",
"vcsCommitAuthorName": "stub-author",
"vcsCommitAuthorEmail": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"metadata": {
"infracostCommand": "diff",
"vcsBranch": "stub-branch",
"vcsBaseCommitSha": "71785af96bce822bd54f359d0883cfa4ca805432",
"vcsCommitSha": "stub-sha",
"vcsCommitAuthorName": "stub-author",
"vcsCommitAuthorEmail": "[email protected]",
Expand Down
10 changes: 10 additions & 0 deletions cmd/infracost/testdata/diff_with_compare_to_format_json/prior.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"version": "0.2",
"metadata": {
"infracostCommand": "breakdown",
"vcsBranch": "master",
"vcsCommitSha": "71785af96bce822bd54f359d0883cfa4ca805432",
"vcsCommitAuthorName": "Hugo",
"vcsCommitAuthorEmail": "",
"vcsCommitTimestamp": "2024-02-23T11:04:26Z",
"vcsCommitMessage": "wip",
"vcsRepositoryUrl": "https://github.com/infracost/infracost.git"
},
"currency": "USD",
"projects": [
{
Expand Down