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

View file

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

View file

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

View file

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