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

Commit 8a9bc50

Browse files
author
Noah Hanjun Lee
authored
Support GitHub enterprise (#133)
* Add the baseURL field for GitHub enterprise * Add documentation.
1 parent 9ccbf16 commit 8a9bc50

File tree

8 files changed

+67
-7
lines changed

8 files changed

+67
-7
lines changed

cmd/server/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type (
4343
GithubClientID string `split_words:"true"`
4444
GithubClientSecret string `split_words:"true"`
4545
GithubScopes []string `split_words:"true" default:"repo,read:user,read:org"`
46+
GithubBaseURL string `split_words:"true"`
4647
}
4748

4849
Slack struct {

cmd/server/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ func newSCM(c *Config) interactor.SCM {
166166
var scm interactor.SCM
167167

168168
if c.isGithubEnabled() {
169-
scm = github.NewGithub()
169+
scm = github.NewGithub(&github.GithubConfig{
170+
BaseURL: c.GithubBaseURL,
171+
})
170172
}
171173

172174
return scm

docs/concepts/how-it-work.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ Below is a simple diagram for how these interactions would work:
3939
| | | |
4040
```
4141

42-
Gitploy lets you create a deployment in advanced ways, such as promotion or rollback, and beef up steps to create a new deployment.
42+
Gitploy lets you can build the advanced deployment system so your team and organization enable to deploy the application with lower risk and faster.
4343

4444
*Keep in mind that Gitploy is never actually accessing your servers. It's up to your tools to interact with deployment events.*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# GITPLOY_GITHUB_BASE_URL
2+
3+
Optional string value configures the base URL for the GitHub enterprise.
4+
5+
```
6+
GITPLOY_GITHUB_BASE_URL=https://github.gitploy.io/
7+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# GITPLOY_GITHUB_SCOPES
2+
3+
Optional String value provides a comma-separated scopes of GitHub OAuth. The default values should not be modified.
4+
5+
```
6+
GITPLOY_GITHUB_SCOPES=repo,read:user,read:org
7+
```

docs/references/configurations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Index of server configuration settings:
1212
* [GITPLOY_ADMIN_USERS](./GITPLOY_ADMIN_USERS.md)
1313
* [GITPLOY_GITHUB_CLIENT_ID](./GITPLOY_GITHUB_CLIENT_ID.md)
1414
* [GITPLOY_GITHUB_CLIENT_SECRET](./GITPLOY_GITHUB_CLIENT_SECRET.md)
15+
* [GITPLOY_GITHUB_BASE_URL](./GITPLOY_GITHUB_BASE_URL.md)
16+
* [GITPLOY_GITHUB_SCOPES](./GITPLOY_GITHUB_SCOPES.md)
1517
* [GITPLOY_SLACK_CLIENT_ID](./GITPLOY_SLACK_CLIENT_ID.md)
1618
* [GITPLOY_SLACK_CLIENT_SECRET](./GITPLOY_SLACK_CLIENT_SECRET.md)
1719
* [GITPLOY_SLACK_SIGNING_SECRET](./GITPLOY_SLACK_SIGNING_SECRET.md)

internal/pkg/github/github.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,47 @@ import (
99
)
1010

1111
type (
12-
Github struct{}
12+
Github struct {
13+
baseURL string
14+
}
15+
16+
GithubConfig struct {
17+
BaseURL string
18+
}
1319
)
1420

15-
func NewGithub() *Github {
16-
return &Github{}
21+
func NewGithub(c *GithubConfig) *Github {
22+
return &Github{
23+
baseURL: c.BaseURL,
24+
}
1725
}
1826

1927
func (g *Github) Client(c context.Context, token string) *github.Client {
2028
tc := oauth2.NewClient(c, oauth2.StaticTokenSource(
2129
&oauth2.Token{AccessToken: token},
2230
))
2331

24-
return github.NewClient(tc)
32+
var client *github.Client
33+
if g.baseURL != "" {
34+
client, _ = github.NewEnterpriseClient(g.baseURL, g.baseURL, tc)
35+
} else {
36+
client = github.NewClient(tc)
37+
}
38+
39+
return client
2540
}
2641

2742
func (g *Github) GraphQLClient(c context.Context, token string) *graphql.Client {
2843
tc := oauth2.NewClient(c, oauth2.StaticTokenSource(
2944
&oauth2.Token{AccessToken: token},
3045
))
3146

32-
return graphql.NewClient(tc)
47+
var client *graphql.Client
48+
if g.baseURL != "" {
49+
client = graphql.NewEnterpriseClient(g.baseURL, tc)
50+
} else {
51+
client = graphql.NewClient(tc)
52+
}
53+
54+
return client
3355
}

internal/pkg/github/github_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package github
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_NewGithub(t *testing.T) {
8+
t.Run("Create a new Github with the base URL.", func(t *testing.T) {
9+
url := "https://github.gitploy.io/"
10+
11+
g := NewGithub(&GithubConfig{
12+
BaseURL: url,
13+
})
14+
15+
if g.baseURL != url {
16+
t.Fatalf("NewGithub.baseURL = %v, wanted %v", g.baseURL, url)
17+
}
18+
})
19+
}

0 commit comments

Comments
 (0)