Skip to content

[FEAT] Add enterprise billing usage data sources#3293

Open
vmvarela wants to merge 7 commits intointegrations:mainfrom
vmvarela:billing-usage
Open

[FEAT] Add enterprise billing usage data sources#3293
vmvarela wants to merge 7 commits intointegrations:mainfrom
vmvarela:billing-usage

Conversation

@vmvarela
Copy link

Summary

This PR adds three new data sources for querying GitHub Enterprise billing
usage via the enhanced billing platform API:

  • github_enterprise_billing_usage — itemized usage report
    (GET /enterprises/{enterprise}/settings/billing/usage)
  • github_enterprise_billing_usage_summary — aggregated summary report
    (GET /enterprises/{enterprise}/settings/billing/usage/summary)
  • github_enterprise_billing_premium_request_usage — premium request (e.g.
    Copilot) usage report
    (GET /enterprises/{enterprise}/settings/billing/premium_request/usage)

All three are read-only data sources. No resources are added.

Relates to #2739

Context

The enhanced billing platform endpoints for enterprises are not yet wrapped
by the go-github client library. This PR implements manual HTTP requests
using client.NewRequest / client.Do, following the same pattern used
elsewhere in the provider for endpoints not yet covered by the SDK.

Data Sources

github_enterprise_billing_usage

Returns itemized billing line items for an enterprise. Optional filters:
year, month, day, cost_center_id.

data "github_enterprise_billing_usage" "example" {
  enterprise_slug = "my-enterprise"
  year            = 2025
  month           = 6
}

github_enterprise_billing_usage_summary

Returns an aggregated summary of billing usage. Optional filters: year,
month, day, organization, repository, product, sku,
cost_center_id.

Note: This endpoint is in public preview and subject to change.

data "github_enterprise_billing_usage_summary" "example" {
  enterprise_slug = "my-enterprise"
  product         = "Actions"
}

github_enterprise_billing_premium_request_usage

Returns premium request usage (AI models, Copilot, etc.). Optional filters:
year, month, day, organization, user, model, product,
cost_center_id.

data "github_enterprise_billing_premium_request_usage" "example" {
  enterprise_slug = "my-enterprise"
  year            = 2025
  month           = 1
}

Testing

Acceptance tests are gated on skipUnlessMode(t, enterprise) and require
a GitHub Enterprise token (GITHUB_ENTERPRISE_SLUG, GITHUB_TOKEN).

Unit tests for all helper functions are in util_enterprise_billing_test.go
and run without any credentials.

Checklist

  • Data source schema follows provider conventions
  • ValidateDiagFunc used (not deprecated ValidateFunc)
  • d.Set() errors checked and returned
  • diag.Errorf used instead of diag.FromErr(fmt.Errorf(...))
  • Data source IDs are stable (buildTwoPartID)
  • Registered in provider.go and website/github.erb
  • Documentation in website/docs/d/
  • Unit tests pass (go test ./github/ -run TestFlatten...)

@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@vmvarela
Copy link
Author

Updated acceptance tests (commit 9ebb722) to go beyond the trivial slug check:

  • ID format assertion: StringRegexp verifies the ID is set with the correct slug:billing-usage / slug:billing-usage-summary / slug:billing-premium-request-usage format produced by buildTwoPartID
  • usage_items is NotNull: verifies the list attribute is always populated (not nil/empty) after a successful read
  • time_period is NotNull (summary + premium request data sources): verifies the block is returned by the API and set in state
  • Additional filter sub-test for billing-usage (year+month combination)

All unit tests still pass (TestFlattenUsageItems, TestFlattenPremiumRequestUsageItems, TestFlattenUsageSummaryItems, TestFlattenTimePeriod).

Add three new data sources for GitHub enterprise billing:
- github_enterprise_billing_usage
- github_enterprise_billing_premium_request_usage
- github_enterprise_billing_usage_summary
Register data sources in provider.go and add sidebar entries in github.erb.
- Dereference *string pointer fields (organization_name, repository_name)
  in flattenUsageItems to avoid storing pointers in TypeString schema fields
- Replace deprecated ValidateFunc with ValidateDiagFunc for year/month/day
  integer validators across all three enterprise billing data sources
- Replace fork-local buildID() with upstream-compatible buildTwoPartID()
  in all three data source Read functions
- Update unit test assertions to match dereferenced string values
…ctural checks

Add assertions for:
- ID format using StringRegexp (e.g. 'slug:billing-usage')
- usage_items and time_period are NotNull
- Additional filter variants (year+month) for billing usage data source
The modernize/newexpr rule incorrectly suggests replacing github.Ptr(x)
with new(x), but new() takes a type not an expression — the auto-fix
generates invalid Go code. Exclude this specific rule pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant