Skip to content

feat: add GitHub Billing plugin#80

Open
LZG3530606141 wants to merge 1 commit into
opencost:mainfrom
LZG3530606141:feat/github-billing-plugin
Open

feat: add GitHub Billing plugin#80
LZG3530606141 wants to merge 1 commit into
opencost:mainfrom
LZG3530606141:feat/github-billing-plugin

Conversation

@LZG3530606141
Copy link
Copy Markdown

Summary

Implements GitHub Billing plugin for OpenCost Plugins, as requested in #42.

What

  • New GitHubBillingCostSource plugin that ingests GitHub billing data into OpenCost
  • Follows the OpenCost plugin architecture (hashicorp go-plugin + gRPC)

Features

  • Usage billing: Fetches standard usage via /organizations/{org}/settings/billing/usage
  • Premium request usage: Fetches Copilot and premium API usage via /organizations/{org}/settings/billing/premium_request/usage
  • Bearer token authentication: Uses GitHub personal access token
  • Rich cost mapping: Maps GitHub billing fields to FOCUS spec including:
    • Product (Actions, Packages, Copilot, etc.)
    • SKU, Repository Name, Organization
    • Unit Type, Price Per Unit
    • Gross Amount, Net Amount, Discount Amount
    • Model (for premium/Copilot usage)
  • Rate limiting: Respects GitHub API rate limits (5000 req/hr)
  • Year/month filtering: Queries billing data by time window

Implementation Details

  • Plugin directory structure follows OpenCost conventions:
    • cmd/main/main.go - Main plugin implementation
    • cmd/main/main_test.go - Unit tests
    • cmd/validator/main/main.go - Config validator
    • config/githubbillingconfig.go - Configuration struct
    • githubbillingplugin/githubbilling.go - API response types
  • Config: github_api_token (required), github_organization (required), github_billing_plugin_log_level (optional)
  • CostSource: "dev_tools", Domain: "github"

Testing

Unit tests cover:

  • Standard usage item JSON unmarshalling
  • Premium usage item JSON unmarshalling
  • Usage response with multiple items (Actions, Packages)

References

Closes #42

Signed-off-by: LZG3530606141 3530606141@qq.com

- Implement GitHubBillingCostSource for ingesting GitHub billing data
- Fetch usage billing via GitHub Billing REST API
- Fetch premium request usage (Copilot) via Premium Request API
- Support Bearer token authentication with GitHub API
- Map GitHub billing fields to FOCUS spec including product, SKU,
  repository name, organization, unit type, price per unit
- Include both gross and net amounts with discount tracking
- Add rate limiting for GitHub API (5000 req/hr)
- Add unit tests for JSON unmarshalling
- Add config validator
- Follow OpenCost plugin architecture (hashicorp go-plugin)

References:
- GitHub Billing API: https://docs.github.com/en/rest/billing/usage
- Issue: opencost#42

Signed-off-by: LZG3530606141 <3530606141@qq.com>
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.

Github Billing and Usage

1 participant