Skip to content

Commit

Permalink
feat: support GitHub Enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed May 25, 2022
1 parent d46e007 commit dd70ce3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
21 changes: 11 additions & 10 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (

// Config is for tfcmt config structure
type Config struct {
CI CI `yaml:"-"`
Terraform Terraform
Vars map[string]string `yaml:"-"`
EmbeddedVarNames []string `yaml:"embedded_var_names"`
Templates map[string]string
Log Log
GHEBaseURL string `yaml:"ghe_base_url"`
GitHubToken string `yaml:"-"`
Complement Complement `yaml:"ci"`
PlanPatch bool `yaml:"plan_patch"`
CI CI `yaml:"-"`
Terraform Terraform
Vars map[string]string `yaml:"-"`
EmbeddedVarNames []string `yaml:"embedded_var_names"`
Templates map[string]string
Log Log
GHEBaseURL string `yaml:"ghe_base_url"`
GHEGraphQLEndpoint string `yaml:"ghe_graphql_endpoint"`
GitHubToken string `yaml:"-"`
Complement Complement `yaml:"ci"`
PlanPatch bool `yaml:"plan_patch"`
}

type CI struct {
Expand Down
9 changes: 5 additions & 4 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ func (ctrl *Controller) getNotifier(ctx context.Context) (notifier.Notifier, err
labels = a
}
client, err := github.NewClient(ctx, github.Config{
Token: ctrl.Config.GitHubToken,
BaseURL: ctrl.Config.GHEBaseURL,
Owner: ctrl.Config.CI.Owner,
Repo: ctrl.Config.CI.Repo,
Token: ctrl.Config.GitHubToken,
BaseURL: ctrl.Config.GHEBaseURL,
GraphQLEndpoint: ctrl.Config.GHEGraphQLEndpoint,
Owner: ctrl.Config.CI.Owner,
Repo: ctrl.Config.CI.Repo,
PR: github.PullRequest{
Revision: ctrl.Config.CI.SHA,
Number: ctrl.Config.CI.PRNumber,
Expand Down
26 changes: 16 additions & 10 deletions pkg/notifier/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ type Client struct {

// Config is a configuration for GitHub client
type Config struct {
Token string
BaseURL string
Owner string
Repo string
PR PullRequest
CI string
Parser terraform.Parser
Token string
BaseURL string
GraphQLEndpoint string
Owner string
Repo string
PR PullRequest
CI string
Parser terraform.Parser
// Template is used for all Terraform command output
Template *terraform.Template
ParseErrorTemplate *terraform.Template
Expand Down Expand Up @@ -100,10 +101,15 @@ func NewClient(ctx context.Context, cfg Config) (*Client, error) {
}

c := &Client{
Config: cfg,
Client: client,
v4Client: githubv4.NewClient(tc),
Config: cfg,
Client: client,
}
if cfg.GraphQLEndpoint == "" {
c.v4Client = githubv4.NewClient(tc)
} else {
c.v4Client = githubv4.NewEnterpriseClient(cfg.GraphQLEndpoint, tc)
}

c.common.client = c
c.Comment = (*CommentService)(&c.common)
c.Commits = (*CommitsService)(&c.common)
Expand Down

0 comments on commit dd70ce3

Please sign in to comment.