implements Stringer for store and remotes

This commit is contained in:
Brad Rydzewski 2015-10-27 16:48:05 -07:00
parent fc02d38b4a
commit 4a0deff5a5
7 changed files with 35 additions and 15 deletions

View file

@ -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 {

View file

@ -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"

View file

@ -417,3 +417,7 @@ func (g *Gitlab) GetOpen() bool {
func (g *Gitlab) Scope() string {
return DefaultScope
}
func (g *Gitlab) String() string {
return "gitlab"
}

View file

@ -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"
}

View file

@ -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()
}

View file

@ -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},
)
}

View file

@ -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,