You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/03/06 21:44:07 UTC

[07/41] incubator-mynewt-newt git commit: MYNEWT-623; allow user to override "github.com" as repo location. Override is done using repository variable "server".

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/3e4102b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/3e4102b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/3e4102b1

Branch: refs/heads/mynewt_1_0_0
Commit: 3e4102b1c51ae5591c80153e6fd45fa550040918
Parents: df3061f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Sat Feb 11 12:39:36 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 13:30:52 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/3e4102b1/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"]