From 1ef6dc0bc6f935aa417889a2a7121dec838e5e82 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 12 May 2015 23:58:30 -0700 Subject: [PATCH] persist self url in repo field --- common/repo.go | 1 + datastore/builtin/migrate/migrate.go | 1 + remote/github/github.go | 4 ++-- remote/remote.go | 2 +- runner/builtin/updater.go | 5 ++++- server/hooks.go | 10 +--------- server/repos.go | 5 +++++ 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/common/repo.go b/common/repo.go index 9ad843f7..040070c9 100644 --- a/common/repo.go +++ b/common/repo.go @@ -9,6 +9,7 @@ type Repo struct { Token string `meddler:"repo_token" json:"-"` Language string `meddler:"repo_lang" json:"language"` Private bool `meddler:"repo_private" json:"private"` + Self string `meddler:"repo_self" json:"self_url"` Link string `meddler:"repo_link" json:"link_url"` Clone string `meddler:"repo_clone" json:"clone_url"` Branch string `meddler:"repo_branch" json:"default_branch"` diff --git a/datastore/builtin/migrate/migrate.go b/datastore/builtin/migrate/migrate.go index 971b3d3a..04be1433 100644 --- a/datastore/builtin/migrate/migrate.go +++ b/datastore/builtin/migrate/migrate.go @@ -64,6 +64,7 @@ CREATE TABLE IF NOT EXISTS repos ( ,repo_branch VARCHAR(255) ,repo_private BOOLEAN ,repo_trusted BOOLEAN + ,repo_self VARCHAR(1024) ,repo_link VARCHAR(1024) ,repo_clone VARCHAR(1024) ,repo_push BOOLEAN diff --git a/remote/github/github.go b/remote/github/github.go index d9d34dff..7c886dd6 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -212,12 +212,12 @@ func (g *GitHub) Deactivate(u *common.User, r *common.Repo, link string) error { return DeleteHook(client, r.Owner, r.Name, link) } -func (g *GitHub) Status(u *common.User, r *common.Repo, c *common.Commit, link string) error { +func (g *GitHub) Status(u *common.User, r *common.Repo, c *common.Commit) error { client := NewClient(g.API, u.Token, g.SkipVerify) if len(c.PullRequest) == 0 { return nil } - + link := fmt.Sprintf("%s/%v", r.Self, c.Sequence) status := getStatus(c.State) desc := getDesc(c.State) data := github.RepoStatus{ diff --git a/remote/remote.go b/remote/remote.go index e855f1d0..da2bb27b 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -27,7 +27,7 @@ type Remote interface { // Status sends the commit status to the remote system. // An example would be the GitHub pull request status. - Status(u *common.User, r *common.Repo, c *common.Commit, link string) error + Status(u *common.User, r *common.Repo, c *common.Commit) error // Netrc returns a .netrc file that can be used to clone // private repositories from a remote system. diff --git a/runner/builtin/updater.go b/runner/builtin/updater.go index c635d12f..eda8d578 100644 --- a/runner/builtin/updater.go +++ b/runner/builtin/updater.go @@ -35,7 +35,10 @@ func (u *updater) SetCommit(user *common.User, r *common.Repo, c *common.Commit) return err } - // TODO invoke remote.Status to set the build status + err = u.remote.Status(user, r, c) + if err != nil { + // log err + } msg, err := json.Marshal(c) if err != nil { diff --git a/server/hooks.go b/server/hooks.go index 347cfe99..ac011335 100644 --- a/server/hooks.go +++ b/server/hooks.go @@ -1,12 +1,10 @@ package server import ( - "fmt" "strings" log "github.com/Sirupsen/logrus" "github.com/drone/drone/common" - "github.com/drone/drone/common/httputil" "github.com/drone/drone/parser" "github.com/drone/drone/parser/inject" "github.com/drone/drone/parser/matrix" @@ -147,13 +145,7 @@ func PostHook(c *gin.Context) { c.JSON(200, commit) - link := fmt.Sprintf( - "%s/%s/%d", - httputil.GetURL(c.Request), - repo.FullName, - commit.Sequence, - ) - err = remote.Status(user, repo, commit, link) + err = remote.Status(user, repo, commit) if err != nil { log.Errorf("error setting commit status for %s/%d", repo.FullName, commit.Sequence) } diff --git a/server/repos.go b/server/repos.go index 2589caa0..c175176b 100644 --- a/server/repos.go +++ b/server/repos.go @@ -210,6 +210,11 @@ func PostRepo(c *gin.Context) { r.UserID = user.ID r.PostCommit = true r.PullRequest = true + r.Self = fmt.Sprintf( + "%s/%s", + httputil.GetURL(c.Request), + r.FullName, + ) // generate an RSA key and add to the repo key, err := sshutil.GeneratePrivateKey()