diff --git a/CHANGELOG.md b/CHANGELOG.md index 46ed1b0..0949f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) ### Added - GHORG_DRY_RUN to do dry runs on clones - output for long running repo fetches +- support for cloning github enterprise repos ### Changed - go-github versions v32 -> v41 ### Deprecated diff --git a/README.md b/README.md index 1c700bc..ba4d988 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ $ ghorg ls someorg ### github setup 1. Create [Personal Access Token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) with all `repo` scopes. Update `GHORG_GITHUB_TOKEN` in your `ghorg/conf.yaml`, as a cli flag, or add to your [osx keychain](https://help.github.com/en/github/using-git/caching-your-github-password-in-git). If your org has Saml SSO in front you will need to give your token those permissions as well, see [this doc](https://docs.github.com/en/github/authenticating-to-github/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on). +1. For cloning GitHub Enterprise repos you must set `--base-url` e.g. `ghorg clone --base-url=https://internal.github.com` ### gitlab setup diff --git a/examples/github.md b/examples/github.md index 4456485..d8342fb 100644 --- a/examples/github.md +++ b/examples/github.md @@ -1,3 +1,5 @@ +# GitHub Cloud + clone a **users** repos ``` @@ -15,3 +17,23 @@ clone all repos from a **github org** that are **prefixed** with "frontend" **in ``` $ ghorg clone --match-regex=^frontend --output-dir=design_only ``` + +# GitHub Enterprise + +clone a **users** repos + +``` +$ ghorg clone --clone-type=user --base-url=https://internal.github.com +``` + +clone an **org** + +``` +$ ghorg clone --base-url=https://internal.github.com +``` + +clone all repos from a **github org** that are **prefixed** with "frontend" **into a folder** called "design_only" + +``` +$ ghorg clone --match-regex=^frontend --output-dir=design_only --base-url=https://internal.github.com +``` diff --git a/scm/github.go b/scm/github.go index 6513a4d..d2a88a2 100644 --- a/scm/github.go +++ b/scm/github.go @@ -32,9 +32,6 @@ func (_ Github) GetType() string { // GetOrgRepos gets org repos func (c Github) GetOrgRepos(targetOrg string) ([]Repo, error) { - if os.Getenv("GHORG_SCM_BASE_URL") != "" { - c.BaseURL, _ = url.Parse(os.Getenv("GHORG_SCM_BASE_URL")) - } opt := &github.RepositoryListByOrgOptions{ Type: "all", @@ -120,7 +117,15 @@ func (_ Github) NewClient() (Client, error) { &oauth2.Token{AccessToken: os.Getenv("GHORG_GITHUB_TOKEN")}, ) tc := oauth2.NewClient(ctx, ts) - c := github.NewClient(tc) + + baseURL := os.Getenv("GHORG_SCM_BASE_URL") + var c *github.Client + + if baseURL != "" { + c, _ = github.NewEnterpriseClient(baseURL, baseURL, tc) + } else { + c = github.NewClient(tc) + } client := Github{Client: c, perPage: 100}