added a private mode flag for github enterprise, defaulted to true

This commit is contained in:
Brad Rydzewski 2014-09-07 11:26:16 -07:00
parent b9c103cef8
commit 31b1ed1f48
4 changed files with 26 additions and 16 deletions

View file

@ -45,6 +45,7 @@ client=""
secret=""
api=""
url=""
private_mode=false
[bitbucket]
client=""
@ -64,6 +65,10 @@ pass=""
Or you can use environment variables
```sh
# enable users to self-register
export DRONE_REGISTRATION_OPEN=false
# github configuration
export DRONE_GITHUB_CLIENT=""
export DRONE_GITHUB_SECRET=""
@ -73,6 +78,7 @@ export DRONE_GITHUB_ENTERPRISE_CLIENT=""
export DRONE_GITHUB_ENTERPRISE_SECRET=""
export DRONE_GITHUB_ENTERPRISE_API=""
export DRONE_GITHUB_ENTERPRISE_URL=""
export DRONE_GITHUB_ENTERPRISE_PRIVATE_MODE=false
# bitbucket configuration
export DRONE_BITBUCKET_CLIENT=""

View file

@ -25,6 +25,7 @@
#DRONE_GITHUB_ENTERPRISE_SECRET=
#DRONE_GITHUB_ENTERPRISE_URL=
#DRONE_GITHUB_ENTERPRISE_API=
#DRONE_GITHUB_ENTERPRISE_PRIVATE_MODE=false
# GitLab configuration
#DRONE_GITLAB_URL=

View file

@ -21,18 +21,20 @@ const (
)
type GitHub struct {
URL string
API string
Client string
Secret string
URL string
API string
Client string
Secret string
Private bool
}
func New(url, api, client, secret string) *GitHub {
func New(url, api, client, secret string, private bool) *GitHub {
var github = GitHub{
URL: url,
API: api,
Client: client,
Secret: secret,
URL: url,
API: api,
Client: client,
Secret: secret,
Private: private,
}
// the API must have a trailing slash
if !strings.HasSuffix(github.API, "/") {
@ -46,7 +48,7 @@ func New(url, api, client, secret string) *GitHub {
}
func NewDefault(client, secret string) *GitHub {
return New(DefaultURL, DefaultAPI, client, secret)
return New(DefaultURL, DefaultAPI, client, secret, false)
}
// Authorize handles GitHub API Authorization.
@ -134,7 +136,6 @@ func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) {
var remote = r.GetKind()
var hostname = r.GetHost()
var enterprise = r.IsEnterprise()
for _, item := range list {
var repo = model.Repo{
@ -151,7 +152,7 @@ func (r *GitHub) GetRepos(user *model.User) ([]*model.Repo, error) {
Role: &model.Perm{},
}
if enterprise || repo.Private {
if r.Private || repo.Private {
repo.CloneURL = *item.SSHURL
}

View file

@ -11,10 +11,11 @@ var (
githubSecret = config.String("github-secret", "")
// GitHub Enterprise configuration details
githubEnterpriseURL = config.String("github-enterprise-url", "")
githubEnterpriseAPI = config.String("github-enterprise-api", "")
githubEnterpriseClient = config.String("github-enterprise-client", "")
githubEnterpriseSecret = config.String("github-enterprise-secret", "")
githubEnterpriseURL = config.String("github-enterprise-url", "")
githubEnterpriseAPI = config.String("github-enterprise-api", "")
githubEnterpriseClient = config.String("github-enterprise-client", "")
githubEnterpriseSecret = config.String("github-enterprise-secret", "")
githubEnterprisePrivate = config.Bool("github-enterprise-private-mode", true)
)
// Registers the GitHub plugins using the default
@ -49,6 +50,7 @@ func registerGitHubEnterprise() {
*githubEnterpriseAPI,
*githubEnterpriseClient,
*githubEnterpriseSecret,
*githubEnterprisePrivate,
),
)
}