Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ builds:
flags:
- -trimpath
ldflags:
- "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}"
- "-s -w -X main.version={{.Version}}"
goos:
- freebsd
- windows
Expand All @@ -41,7 +41,8 @@ builds:
binary: "{{ .ProjectName }}_v{{ .Version }}"

archives:
- format: zip
- formats:
- zip
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

checksum:
Expand Down
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ internal/
- `POST /v1/seats/unassign` - Unassign seat from user

API docs: https://api.coderabbit.ai/v1/docs/

## Documentation

When modifying usage or behavior, always update `README.md` to reflect the changes.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ provider "coderabbit" {

# Optional: Custom API endpoint (default: https://api.coderabbit.ai)
# base_url = "https://api.coderabbit.ai"

# Optional: GitHub token for API authentication (higher rate limits)
# Can also be set via GITHUB_TOKEN environment variable
# github_token = "ghp_xxxxxxxxxxxx"
}
```

Expand All @@ -52,6 +56,7 @@ provider "coderabbit" {
|----------|-------------|
| `CODERABBITAI_API_KEY` | CodeRabbit API authentication key |
| `CODERABBIT_BASE_URL` | API base URL (optional) |
| `GITHUB_TOKEN` | GitHub personal access token for higher rate limits (optional) |

### Assigning Seats

Expand Down
11 changes: 8 additions & 3 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ func DefaultRetryConfig() RetryConfig {
type Client struct {
APIKey string
BaseURL string
GitHubToken string
HTTPClient *http.Client
RetryConfig RetryConfig
}

// NewClient creates a new CodeRabbit API client
func NewClient(apiKey, baseURL string) *Client {
func NewClient(apiKey, baseURL, githubToken string) *Client {
return &Client{
APIKey: apiKey,
BaseURL: baseURL,
APIKey: apiKey,
BaseURL: baseURL,
GitHubToken: githubToken,
HTTPClient: &http.Client{
Timeout: 30 * time.Second,
},
Expand Down Expand Up @@ -191,6 +193,9 @@ func (c *Client) GetGitUserID(githubID string) (string, error) {
}

req.Header.Set("Accept", "application/vnd.github+json")
if c.GitHubToken != "" {
req.Header.Set("Authorization", "Bearer "+c.GitHubToken)
}

resp, err := c.HTTPClient.Do(req)
if err != nil {
Expand Down
18 changes: 15 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ type CodeRabbitProvider struct {
}

type CodeRabbitProviderModel struct {
APIKey types.String `tfsdk:"api_key"`
BaseURL types.String `tfsdk:"base_url"`
APIKey types.String `tfsdk:"api_key"`
BaseURL types.String `tfsdk:"base_url"`
GitHubToken types.String `tfsdk:"github_token"`
}

func New(version string) func() provider.Provider {
Expand Down Expand Up @@ -51,6 +52,11 @@ func (p *CodeRabbitProvider) Schema(ctx context.Context, req provider.SchemaRequ
Description: "Base URL for CodeRabbit API. Defaults to https://api.coderabbit.ai. Can also be set via CODERABBIT_BASE_URL environment variable.",
Optional: true,
},
"github_token": schema.StringAttribute{
Description: "GitHub personal access token for GitHub API authentication. Can also be set via GITHUB_TOKEN environment variable. If not set, GitHub API requests will be unauthenticated (lower rate limits).",
Optional: true,
Sensitive: true,
},
},
}
}
Expand Down Expand Up @@ -88,8 +94,14 @@ func (p *CodeRabbitProvider) Configure(ctx context.Context, req provider.Configu
baseURL = "https://api.coderabbit.ai"
}

// Get GitHub token from config or environment variable
githubToken := os.Getenv("GITHUB_TOKEN")
if !config.GitHubToken.IsNull() {
githubToken = config.GitHubToken.ValueString()
}

// Create API client
c := client.NewClient(apiKey, baseURL)
c := client.NewClient(apiKey, baseURL, githubToken)

// Make the client available to resources and data sources
resp.DataSourceData = c
Expand Down
5 changes: 1 addition & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/providerserver"
)

var (
version string = "dev"
commit string = "none"
)
var version string = "dev"

func main() {
var debug bool
Expand Down
Loading