diff --git a/remote/bitbucket/bitbucket.go b/remote/bitbucket/bitbucket.go index 51502883f..98d43df63 100644 --- a/remote/bitbucket/bitbucket.go +++ b/remote/bitbucket/bitbucket.go @@ -370,6 +370,10 @@ func (bb *Bitbucket) Hook(r *http.Request) (*model.Repo, *model.Build, error) { return nil, nil, nil } +func (bb *Bitbucket) String() string { + return "bitbucket" +} + func (bb *Bitbucket) pushHook(r *http.Request) (*model.Repo, *model.Build, error) { payload := []byte(r.FormValue("payload")) if len(payload) == 0 { diff --git a/remote/github/github.go b/remote/github/github.go index d1e23fe5b..aa2f4e5d1 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -470,6 +470,10 @@ func (g *Github) deployment(r *http.Request) (*model.Repo, *model.Build, error) return repo, build, nil } +func (g *Github) String() string { + return "github" +} + const ( StatusPending = "pending" StatusSuccess = "success" diff --git a/remote/gitlab/gitlab.go b/remote/gitlab/gitlab.go index d6846020f..4c0616bbf 100644 --- a/remote/gitlab/gitlab.go +++ b/remote/gitlab/gitlab.go @@ -417,3 +417,7 @@ func (g *Gitlab) GetOpen() bool { func (g *Gitlab) Scope() string { return DefaultScope } + +func (g *Gitlab) String() string { + return "gitlab" +} diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go index ee396b016..16755a081 100644 --- a/remote/gogs/gogs.go +++ b/remote/gogs/gogs.go @@ -231,3 +231,7 @@ func (g *Gogs) Hook(r *http.Request) (*model.Repo, *model.Build, error) { } return repo, build, err } + +func (g *Gogs) String() string { + return "gogs" +} diff --git a/router/middleware/header/header.go b/router/middleware/header/header.go index b57b07c49..0e0eaee7b 100644 --- a/router/middleware/header/header.go +++ b/router/middleware/header/header.go @@ -53,6 +53,7 @@ func Secure(c *gin.Context) { // for debugging and troubleshooting. func Version(version string) gin.HandlerFunc { return func(c *gin.Context) { + c.Set("version", "0.4.0-beta+"+version) c.Header("X-DRONE-VERSION", "0.4.0-beta+"+version) c.Next() } diff --git a/store/datastore/store.go b/store/datastore/store.go index 08c0e4d10..4ff85e0a1 100644 --- a/store/datastore/store.go +++ b/store/datastore/store.go @@ -16,19 +16,6 @@ import ( log "github.com/Sirupsen/logrus" ) -// From creates a datastore from an existing database connection. -func From(db *sql.DB) store.Store { - return store.New( - &nodestore{db}, - &userstore{db}, - &repostore{db}, - &keystore{db}, - &buildstore{db}, - &jobstore{db}, - &logstore{db}, - ) -} - // Load opens a new database connection with the specified driver // and connection string specified in the environment variables. func Load(env envconfig.Env) store.Store { @@ -40,8 +27,20 @@ func Load(env envconfig.Env) store.Store { log.Infof("using database driver %s", driver) log.Infof("using database config %s", config) - return From( - Open(driver, config), + return New(driver, config) +} + +func New(driver, config string) store.Store { + conn := Open(driver, config) + return store.New( + driver, + &nodestore{conn}, + &userstore{conn}, + &repostore{conn}, + &keystore{conn}, + &buildstore{conn}, + &jobstore{conn}, + &logstore{conn}, ) } diff --git a/store/store.go b/store/store.go index 8ef0ac9e5..9372b7a2e 100644 --- a/store/store.go +++ b/store/store.go @@ -11,6 +11,7 @@ type Store interface { } type store struct { + name string nodes NodeStore users UserStore repos RepoStore @@ -27,8 +28,10 @@ func (s *store) Keys() KeyStore { return s.keys } func (s *store) Builds() BuildStore { return s.builds } func (s *store) Jobs() JobStore { return s.jobs } func (s *store) Logs() LogStore { return s.logs } +func (s *store) String() string { return s.name } func New( + name string, nodes NodeStore, users UserStore, repos RepoStore, @@ -38,6 +41,7 @@ func New( logs LogStore, ) Store { return &store{ + name, nodes, users, repos,