Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Support GitHub enterprise #133

Merged
merged 5 commits into from
Sep 30, 2021
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
1 change: 1 addition & 0 deletions cmd/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/how-it-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
7 changes: 7 additions & 0 deletions docs/references/GITPLOY_GITHUB_BASE_URL.md
Original file line number Diff line number Diff line change
@@ -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/
```
7 changes: 7 additions & 0 deletions docs/references/GITPLOY_GITHUB_SCOPES.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions docs/references/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 27 additions & 5 deletions internal/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,47 @@ 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 {
tc := oauth2.NewClient(c, oauth2.StaticTokenSource(
&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 {
tc := oauth2.NewClient(c, oauth2.StaticTokenSource(
&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
}
19 changes: 19 additions & 0 deletions internal/pkg/github/github_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}