MYNEWT-623; allow user to override "github.com" as repo location.
Override is done using repository variable "server".


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/4789254d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/4789254d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/4789254d

Branch: refs/heads/develop
Commit: 4789254d78dd88fcb2b23b084a26e6a383cf7406
Parents: d3d719c
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Sat Feb 11 12:39:36 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Sat Feb 11 12:39:36 2017 -0800

----------------------------------------------------------------------
 newt/downloader/downloader.go | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/4789254d/newt/downloader/downloader.go
----------------------------------------------------------------------
diff --git a/newt/downloader/downloader.go b/newt/downloader/downloader.go
index bd763f5..06557dd 100644
--- a/newt/downloader/downloader.go
+++ b/newt/downloader/downloader.go
@@ -47,8 +47,9 @@ type GenericDownloader struct {
 
 type GithubDownloader struct {
        GenericDownloader
-       User string
-       Repo string
+       Server string
+       User   string
+       Repo   string
 
        // Github access token for private repositories.
        Token string
@@ -117,8 +118,12 @@ func (gd *GenericDownloader) TempDir() (string, error) {
 }
 
 func (gd *GithubDownloader) FetchFile(name string, dest string) error {
-       url := 
fmt.Sprintf("https://api.github.com/repos/%s/%s/contents/%s?ref=%s";,
-               gd.User, gd.Repo, name, gd.Branch())
+       server := "github.com"
+       if gd.Server != "" {
+               server = gd.Server
+       }
+       url := fmt.Sprintf("https://api.%s/repos/%s/%s/contents/%s?ref=%s";,
+               server, gd.User, gd.Repo, name, gd.Branch())
 
        req, err := http.NewRequest("GET", url, nil)
        req.Header.Add("Accept", "application/vnd.github.v3.raw")
@@ -174,8 +179,12 @@ func (gd *GithubDownloader) DownloadRepo(commit string) 
(string, error) {
 
        // Currently only the master branch is supported.
        branch := "master"
+       server := "github.com"
 
-       url := fmt.Sprintf("https://github.com/%s/%s.git";, gd.User, gd.Repo)
+       if gd.Server != "" {
+               server = gd.Server
+       }
+       url := fmt.Sprintf("https://%s/%s/%s.git";, server, gd.User, gd.Repo)
        util.StatusMessage(util.VERBOSITY_VERBOSE, "Downloading "+
                "repository %s (branch: %s; commit: %s) at %s\n", gd.Repo, 
branch,
                commit, url)
@@ -265,6 +274,7 @@ func LoadDownloader(repoName string, repoVars 
map[string]string) (
        case "github":
                gd := NewGithubDownloader()
 
+               gd.Server = repoVars["server"]
                gd.User = repoVars["user"]
                gd.Repo = repoVars["repo"]
 

Reply via email to