Skip to content

Commit 505289e

Browse files
committed
update README.md
1 parent 1ff306c commit 505289e

1 file changed

Lines changed: 60 additions & 9 deletions

File tree

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,84 @@ Go library for posting Infracost cost estimate comments to pull requests. Suppor
1010
gh, err := github.New(ctx, "my-org", "my-repo", token, prNumber, github.Options{})
1111
```
1212

13-
For GitHub Enterprise, set `Options.APIURL` to your instance URL.
13+
For GitHub Enterprise, set `Options.APIURL` to your instance URL. You can also provide a custom `Options.TLSConfig` for Enterprise TLS requirements.
1414

1515
### 2. Build the comment data
1616

17-
Populate a `vcs.CommentData` struct with cost and policy data from your run. All fields use shared proto types from `github.com/infracost/proto`.
17+
Populate a `comment.Data` struct with cost and policy data from your run. Cost fields use `*rat.Rat` from `github.com/infracost/go-proto/pkg/rat`, and policy fields use proto types from `github.com/infracost/proto` and `github.com/infracost/go-proto`.
1818

1919
```go
20-
data := vcs.CommentData{
20+
data := comment.Data{
2121
Currency: "USD",
2222
TotalMonthlyCost: totalCost,
2323
PastTotalMonthlyCost: pastCost,
24-
Projects: []vcs.ProjectResult{
24+
Projects: []comment.ProjectResult{
2525
{
2626
Name: "my-project",
2727
TotalMonthlyCost: projectCost,
28-
Resources: output.GetResources(),
29-
DiffResources: diffResources,
28+
Breakdown: breakdown,
29+
Resources: resources,
3030
},
3131
},
3232
}
3333
```
3434

35+
#### `comment.Data` fields
36+
37+
| Field | Type | Description |
38+
|---|---|---|
39+
| `EnableEnvironmentalMetrics` | `bool` | Show carbon emissions in the comment. |
40+
| `NeverShowCostEstimate` | `bool` | Suppress the cost details section entirely. |
41+
| `UsedUsageFile` | `bool` | Whether an `infracost-usage.yml` was used. |
42+
| `UsageAPIEnabled` | `bool` | Whether Infracost Cloud usage API estimates are enabled. |
43+
| `OrgSlug` | `string` | Organization slug for Infracost Cloud links. |
44+
| `RepoID` | `string` | Repository ID for Infracost Cloud links. |
45+
| `BaseBranchName` | `string` | Default/base branch name (e.g. `"main"`). |
46+
| `Currency` | `string` | ISO 4217 currency code (e.g. `"USD"`). |
47+
| `TotalMonthlyCost` | `*rat.Rat` | Current total monthly cost across all projects. |
48+
| `PastTotalMonthlyCost` | `*rat.Rat` | Previous total monthly cost (from base branch). Nil if no previous run. |
49+
| `DiffTotalMonthlyCarbonGramsCo2e` | `*rat.Rat` | Change in monthly carbon emissions (grams CO2e). |
50+
| `CloudURL` | `string` | Link to the Infracost Cloud dashboard for this run. |
51+
| `RepoURL` | `string` | VCS repository URL, used for source links in governance tables. |
52+
| `CommitSHA` | `string` | Head commit SHA, used with `RepoURL` for source links. |
53+
| `Summary` | `ResourceSummary` | Aggregated resource counts across all projects. |
54+
| `Projects` | `[]ProjectResult` | Per-project cost and resource data. |
55+
| `FinOpsPolicyResults` | `[]*provider.FinopsPolicyResult` | FinOps policy results for the current run. |
56+
| `PreviousFinOpsPolicyResults` | `[]*provider.FinopsPolicyResult` | FinOps policy results from the previous run. |
57+
| `SecurityPolicyResults` | `[]*provider.FinopsPolicyResult` | Security policy results for the current run. |
58+
| `PreviousSecurityPolicyResults` | `[]*provider.FinopsPolicyResult` | Security policy results from the previous run. |
59+
| `TaggingPolicyResults` | `[]*event.TaggingPolicyResult` | Tagging policy results for the current run. |
60+
| `PreviousTaggingPolicyResults` | `[]*event.TaggingPolicyResult` | Tagging policy results from the previous run. |
61+
| `GuardrailResults` | `[]*event.GuardrailResult` | Guardrail results for the current run. |
62+
| `PreviousGuardrailResults` | `[]*event.GuardrailResult` | Guardrail results from the previous run. |
63+
64+
#### `comment.ProjectResult` fields
65+
66+
| Field | Type | Description |
67+
|---|---|---|
68+
| `Name` | `string` | Project name from configuration. |
69+
| `ModulePath` | `string` | Terraform module path, if applicable. |
70+
| `Workspace` | `string` | Terraform workspace name, if applicable. |
71+
| `TotalMonthlyCost` | `*rat.Rat` | Current total monthly cost for this project. |
72+
| `PastTotalMonthlyCost` | `*rat.Rat` | Previous total monthly cost for this project. |
73+
| `TotalMonthlyUsageCost` | `*rat.Rat` | Current usage-based monthly cost. |
74+
| `PastTotalMonthlyUsageCost` | `*rat.Rat` | Previous usage-based monthly cost. |
75+
| `Breakdown` | `*CostBreakdown` | Current resource-level cost breakdown. |
76+
| `PastBreakdown` | `*CostBreakdown` | Previous resource-level cost breakdown. |
77+
| `DiffBreakdown` | `*CostBreakdown` | Resources that changed between runs. |
78+
| `Resources` | `[]*provider.Resource` | Resources with costs; each has an `Action` (CREATE, MODIFY, DELETE, NOOP). |
79+
| `Diagnostics` | `[]*parser.Diagnostic` | Parsing errors or warnings for this project. |
80+
| `PastDiagnostics` | `[]*parser.Diagnostic` | Parsing errors or warnings before the current changes. |
81+
3582
### 3. Generate and post the comment
3683

3784
```go
3885
body, err := gh.GenerateComment(data)
3986
result, err := gh.PostComment(ctx, body, vcs.BehaviorUpdate)
4087
```
4188

89+
`PostResult.Posted` indicates whether a comment was created or updated. If it was skipped (e.g. duplicate or stale), `PostResult.SkipReason` explains why.
90+
4291
## Comment behaviors
4392

4493
`PostComment` accepts a `vcs.Behavior` that controls how comments are managed:
@@ -62,15 +111,17 @@ gh, err := github.New(ctx, owner, repo, token, pr, github.Options{
62111
})
63112
```
64113

65-
The template receives a `vcs.CommentData` struct and has access to the template functions defined in `template_funcs.go`.
114+
The template receives a `comment.Data` struct and has access to the template functions defined in `template_funcs.go`.
115+
116+
You can also set `Options.Tag` to use a custom comment identifier (defaults to `"infracost-comment"`).
66117

67118
## Interface
68119

69120
Any VCS provider implements:
70121

71122
```go
72123
type VCS interface {
73-
GenerateComment(CommentData) (string, error)
124+
GenerateComment(comment.Data) (string, error)
74125
PostComment(ctx context.Context, body string, behavior Behavior) (PostResult, error)
75126
}
76-
```
127+
```

0 commit comments

Comments
 (0)