From 67a4e302c7d47e59d6039ebce3b6cb9d535b94b7 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 28 Apr 2015 14:39:48 -0700 Subject: [PATCH] ability to get netrc from remote --- Makefile | 7 +++++-- remote/github/github.go | 15 +++++++++++++++ remote/remote.go | 4 ++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 073067ced..2c1383794 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,11 @@ concat: server/static/scripts/controllers/*.js \ server/static/scripts/term.js > server/static/scripts/drone.min.js +bindata_deps: + go get github.com/jteeuwen/go-bindata/... + bindata_debug: - go-bindata --debug server/static/... + $$GOPATH/bin/go-bindata --debug server/static/... bindata: - go-bindata server/static/... \ No newline at end of file + $$GOPATH/bin/go-bindata server/static/... diff --git a/remote/github/github.go b/remote/github/github.go index d881aa3bb..439ca0d63 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" "strings" "github.com/drone/drone/common" @@ -149,6 +150,20 @@ func (g *GitHub) Script(u *common.User, r *common.Repo, b *common.Build) ([]byte return GetFile(client, r.Owner, r.Name, ".drone.yml", sha) } +// Netrc returns a .netrc file that can be used to clone +// private repositories from a remote system. +func (g *GitHub) Netrc(u *common.User, r *common.Repo) (*common.Netrc, error) { + url_, err := url.Parse(g.URL) + if err != nil { + return nil, err + } + netrc := &common.Netrc{} + netrc.Login = u.Token + netrc.Password = "x-oauth-basic" + netrc.Machine = url_.Host + return netrc, nil +} + // Activate activates a repository by creating the post-commit hook and // adding the SSH deploy key, if applicable. func (g *GitHub) Activate(u *common.User, r *common.Repo, k *common.Keypair, link string) error { diff --git a/remote/remote.go b/remote/remote.go index 4f110e677..b1cb210be 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -29,6 +29,10 @@ type Remote interface { // An example would be the GitHub pull request status. Status(u *common.User, r *common.Repo, b *common.Build, link string) error + // Netrc returns a .netrc file that can be used to clone + // private repositories from a remote system. + Netrc(u *common.User, r *common.Repo) (*common.Netrc, error) + // Activate activates a repository by creating the post-commit hook and // adding the SSH deploy key, if applicable. Activate(u *common.User, r *common.Repo, k *common.Keypair, link string) error