diff --git a/pkg/config/config.go b/pkg/config/config.go index e7b3043c..598ae8b0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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 { diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index c9e79cba..3331518a 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -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, diff --git a/pkg/notifier/github/client.go b/pkg/notifier/github/client.go index 8a72599e..e8d3fa10 100644 --- a/pkg/notifier/github/client.go +++ b/pkg/notifier/github/client.go @@ -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 @@ -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)