Skip to content

Commit

Permalink
feat: Add vcsBaseCommitSha to estimate metadata
Browse files Browse the repository at this point in the history
It's empty on breakdown, and base branch's HEAD SHA on diff/output.
NB: When combining several JSONs in output command latest item's
metadata will be used in the output.
  • Loading branch information
vdmgolub committed May 2, 2024
1 parent 60befff commit 47fcd03
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/infracost/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func runMain(cmd *cobra.Command, runCtx *config.RunContext) error {
logging.Logger.Debug().Err(err).Msgf("failed to fetch vcs metadata for path %s", repoPath)
}
runCtx.VCSMetadata = metadata
runCtx.VCSMetadata.BaseCommit = vcs.Commit{}

pr, err := newParallelRunner(cmd, runCtx)
if err != nil {
Expand Down Expand Up @@ -123,6 +124,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
2 changes: 2 additions & 0 deletions internal/output/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Metadata struct {
InfracostCommand string `json:"infracostCommand"`

Branch string `json:"vcsBranch"`
BaseCommitSHA string `json:"vcsBaseCommitSha,omitempty"`
CommitSHA string `json:"vcsCommitSha"`
CommitAuthorName string `json:"vcsCommitAuthorName"`
CommitAuthorEmail string `json:"vcsCommitAuthorEmail"`
Expand Down Expand Up @@ -38,6 +39,7 @@ func NewMetadata(ctx *config.RunContext) Metadata {
m := Metadata{
InfracostCommand: ctx.CMD,
Branch: ctx.VCSMetadata.Branch.Name,
BaseCommitSHA: ctx.VCSMetadata.BaseCommit.SHA,
CommitSHA: ctx.VCSMetadata.Commit.SHA,
CommitAuthorEmail: ctx.VCSMetadata.Commit.AuthorEmail,
CommitAuthorName: ctx.VCSMetadata.Commit.AuthorName,
Expand Down
1 change: 1 addition & 0 deletions internal/vcs/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ type Metadata struct {
Remote Remote
Branch Branch
Commit Commit
BaseCommit Commit
PullRequest *PullRequest
Pipeline *Pipeline
}
Expand Down
3 changes: 3 additions & 0 deletions schema/infracost.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
"vcsBranch": {
"type": "string"
},
"vcsBaseCommitSha": {
"type": "string"
},
"vcsCommitSha": {
"type": "string"
},
Expand Down

0 comments on commit 47fcd03

Please sign in to comment.