From 77beaf0ff379f4c954f11b0b134c83d8f6a2eae7 Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 30 Sep 2021 21:42:15 +0900 Subject: [PATCH 1/5] Add the baseURL field for github enterprise --- cmd/server/config.go | 1 + cmd/server/main.go | 4 +++- internal/pkg/github/github.go | 32 +++++++++++++++++++++++++----- internal/pkg/github/github_test.go | 19 ++++++++++++++++++ 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 internal/pkg/github/github_test.go diff --git a/cmd/server/config.go b/cmd/server/config.go index eb434147..e7bd0f92 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"` + GithubServer string `split_words:"true"` } Slack struct { diff --git a/cmd/server/main.go b/cmd/server/main.go index b6296bb4..4b240c64 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.GithubServer, + }) } return scm 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) + } + }) +} From 79c75b300afdb1e6b11332e96f686282f85b18a2 Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 30 Sep 2021 21:51:45 +0900 Subject: [PATCH 2/5] Fix the name of environment --- cmd/server/config.go | 2 +- cmd/server/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/server/config.go b/cmd/server/config.go index e7bd0f92..f2645dc8 100644 --- a/cmd/server/config.go +++ b/cmd/server/config.go @@ -43,7 +43,7 @@ type ( GithubClientID string `split_words:"true"` GithubClientSecret string `split_words:"true"` GithubScopes []string `split_words:"true" default:"repo,read:user,read:org"` - GithubServer string `split_words:"true"` + GithubBaseURL string `split_words:"true"` } Slack struct { diff --git a/cmd/server/main.go b/cmd/server/main.go index 4b240c64..879bcc5f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -167,7 +167,7 @@ func newSCM(c *Config) interactor.SCM { if c.isGithubEnabled() { scm = github.NewGithub(&github.GithubConfig{ - BaseURL: c.GithubServer, + BaseURL: c.GithubBaseURL, }) } From 14c4891046a47b9a1f20e6c0a242318be0a25587 Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 30 Sep 2021 22:00:45 +0900 Subject: [PATCH 3/5] Add documentation. --- docs/references/GITPLOY_GITHUB_BASE_URL.md | 7 +++++++ docs/references/GITPLOY_GITHUB_SCOPES.md | 7 +++++++ docs/references/configurations.md | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 docs/references/GITPLOY_GITHUB_BASE_URL.md create mode 100644 docs/references/GITPLOY_GITHUB_SCOPES.md diff --git a/docs/references/GITPLOY_GITHUB_BASE_URL.md b/docs/references/GITPLOY_GITHUB_BASE_URL.md new file mode 100644 index 00000000..4a1805c5 --- /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 of 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) From a2c8c55e01292e5158fadf16c52a78d9c8981a7c Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 30 Sep 2021 22:07:28 +0900 Subject: [PATCH 4/5] Fix some docs --- docs/concepts/how-it-work.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.* From 6c72b22add5c26c4b18e1d24885ee63a8e5958ac Mon Sep 17 00:00:00 2001 From: noah Date: Thu, 30 Sep 2021 22:08:14 +0900 Subject: [PATCH 5/5] Fix typo --- docs/references/GITPLOY_GITHUB_BASE_URL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/references/GITPLOY_GITHUB_BASE_URL.md b/docs/references/GITPLOY_GITHUB_BASE_URL.md index 4a1805c5..047bb819 100644 --- a/docs/references/GITPLOY_GITHUB_BASE_URL.md +++ b/docs/references/GITPLOY_GITHUB_BASE_URL.md @@ -1,6 +1,6 @@ # GITPLOY_GITHUB_BASE_URL -Optional string value configures the base URL of GitHub enterprise. +Optional string value configures the base URL for the GitHub enterprise. ``` GITPLOY_GITHUB_BASE_URL=https://github.gitploy.io/