diff --git a/cmd/server/config.go b/cmd/server/config.go index eb434147..f2645dc8 100644 --- a/cmd/server/config.go +++ b/cmd/server/config.go @@ -43,6 +43,7 @@ type ( GithubClientID string `split_words:"true"` GithubClientSecret string `split_words:"true"` GithubScopes []string `split_words:"true" default:"repo,read:user,read:org"` + GithubBaseURL string `split_words:"true"` } Slack struct { diff --git a/cmd/server/main.go b/cmd/server/main.go index b6296bb4..879bcc5f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -166,7 +166,9 @@ func newSCM(c *Config) interactor.SCM { var scm interactor.SCM if c.isGithubEnabled() { - scm = github.NewGithub() + scm = github.NewGithub(&github.GithubConfig{ + BaseURL: c.GithubBaseURL, + }) } return scm diff --git a/docs/concepts/how-it-work.md b/docs/concepts/how-it-work.md index 090814cc..8de70ae1 100644 --- a/docs/concepts/how-it-work.md +++ b/docs/concepts/how-it-work.md @@ -39,6 +39,6 @@ Below is a simple diagram for how these interactions would work: | | | | ``` -Gitploy lets you create a deployment in advanced ways, such as promotion or rollback, and beef up steps to create a new deployment. +Gitploy lets you can build the advanced deployment system so your team and organization enable to deploy the application with lower risk and faster. *Keep in mind that Gitploy is never actually accessing your servers. It's up to your tools to interact with deployment events.* diff --git a/docs/references/GITPLOY_GITHUB_BASE_URL.md b/docs/references/GITPLOY_GITHUB_BASE_URL.md new file mode 100644 index 00000000..047bb819 --- /dev/null +++ b/docs/references/GITPLOY_GITHUB_BASE_URL.md @@ -0,0 +1,7 @@ +# GITPLOY_GITHUB_BASE_URL + +Optional string value configures the base URL for the GitHub enterprise. + +``` +GITPLOY_GITHUB_BASE_URL=https://github.gitploy.io/ +``` diff --git a/docs/references/GITPLOY_GITHUB_SCOPES.md b/docs/references/GITPLOY_GITHUB_SCOPES.md new file mode 100644 index 00000000..1d8f9739 --- /dev/null +++ b/docs/references/GITPLOY_GITHUB_SCOPES.md @@ -0,0 +1,7 @@ +# GITPLOY_GITHUB_SCOPES + +Optional String value provides a comma-separated scopes of GitHub OAuth. The default values should not be modified. + +``` +GITPLOY_GITHUB_SCOPES=repo,read:user,read:org +``` diff --git a/docs/references/configurations.md b/docs/references/configurations.md index e8f55517..3f27b9ea 100644 --- a/docs/references/configurations.md +++ b/docs/references/configurations.md @@ -12,6 +12,8 @@ Index of server configuration settings: * [GITPLOY_ADMIN_USERS](./GITPLOY_ADMIN_USERS.md) * [GITPLOY_GITHUB_CLIENT_ID](./GITPLOY_GITHUB_CLIENT_ID.md) * [GITPLOY_GITHUB_CLIENT_SECRET](./GITPLOY_GITHUB_CLIENT_SECRET.md) +* [GITPLOY_GITHUB_BASE_URL](./GITPLOY_GITHUB_BASE_URL.md) +* [GITPLOY_GITHUB_SCOPES](./GITPLOY_GITHUB_SCOPES.md) * [GITPLOY_SLACK_CLIENT_ID](./GITPLOY_SLACK_CLIENT_ID.md) * [GITPLOY_SLACK_CLIENT_SECRET](./GITPLOY_SLACK_CLIENT_SECRET.md) * [GITPLOY_SLACK_SIGNING_SECRET](./GITPLOY_SLACK_SIGNING_SECRET.md) diff --git a/internal/pkg/github/github.go b/internal/pkg/github/github.go index 9ea71c2f..266ea027 100644 --- a/internal/pkg/github/github.go +++ b/internal/pkg/github/github.go @@ -9,11 +9,19 @@ import ( ) type ( - Github struct{} + Github struct { + baseURL string + } + + GithubConfig struct { + BaseURL string + } ) -func NewGithub() *Github { - return &Github{} +func NewGithub(c *GithubConfig) *Github { + return &Github{ + baseURL: c.BaseURL, + } } func (g *Github) Client(c context.Context, token string) *github.Client { @@ -21,7 +29,14 @@ func (g *Github) Client(c context.Context, token string) *github.Client { &oauth2.Token{AccessToken: token}, )) - return github.NewClient(tc) + var client *github.Client + if g.baseURL != "" { + client, _ = github.NewEnterpriseClient(g.baseURL, g.baseURL, tc) + } else { + client = github.NewClient(tc) + } + + return client } func (g *Github) GraphQLClient(c context.Context, token string) *graphql.Client { @@ -29,5 +44,12 @@ func (g *Github) GraphQLClient(c context.Context, token string) *graphql.Client &oauth2.Token{AccessToken: token}, )) - return graphql.NewClient(tc) + var client *graphql.Client + if g.baseURL != "" { + client = graphql.NewEnterpriseClient(g.baseURL, tc) + } else { + client = graphql.NewClient(tc) + } + + return client } diff --git a/internal/pkg/github/github_test.go b/internal/pkg/github/github_test.go new file mode 100644 index 00000000..329a1b0e --- /dev/null +++ b/internal/pkg/github/github_test.go @@ -0,0 +1,19 @@ +package github + +import ( + "testing" +) + +func Test_NewGithub(t *testing.T) { + t.Run("Create a new Github with the base URL.", func(t *testing.T) { + url := "https://github.gitploy.io/" + + g := NewGithub(&GithubConfig{ + BaseURL: url, + }) + + if g.baseURL != url { + t.Fatalf("NewGithub.baseURL = %v, wanted %v", g.baseURL, url) + } + }) +}