diff --git a/drone.go b/drone.go index dbab94d2..4d0fe989 100644 --- a/drone.go +++ b/drone.go @@ -13,8 +13,8 @@ import ( "github.com/drone/drone/settings" "github.com/elazarl/go-bindata-assetfs" - store "github.com/drone/drone/datastore/builtin" - eventbus "github.com/drone/drone/eventbus/builtin" + eventbus "github.com/drone/drone/pkg/bus/builtin" + store "github.com/drone/drone/pkg/store/builtin" queue "github.com/drone/drone/queue/builtin" runner "github.com/drone/drone/runner/builtin" diff --git a/eventbus/builtin/bus.go b/pkg/bus/builtin/bus.go similarity index 55% rename from eventbus/builtin/bus.go rename to pkg/bus/builtin/bus.go index f7081305..c5e91d48 100644 --- a/eventbus/builtin/bus.go +++ b/pkg/bus/builtin/bus.go @@ -3,26 +3,26 @@ package builtin import ( "sync" - "github.com/drone/drone/eventbus" + "github.com/drone/drone/pkg/bus" ) -type EventBus struct { +type Bus struct { sync.Mutex - subs map[chan *eventbus.Event]bool + subs map[chan *bus.Event]bool } -// New creates a new EventBus that manages a list of +// New creates a new Bus that manages a list of // subscribers to which events are published. -func New() *EventBus { - return &EventBus{ - subs: make(map[chan *eventbus.Event]bool), +func New() *Bus { + return &Bus{ + subs: make(map[chan *bus.Event]bool), } } // Subscribe adds the channel to the list of // subscribers. Each subscriber in the list will // receive broadcast events. -func (b *EventBus) Subscribe(c chan *eventbus.Event) { +func (b *Bus) Subscribe(c chan *bus.Event) { b.Lock() b.subs[c] = true b.Unlock() @@ -30,19 +30,19 @@ func (b *EventBus) Subscribe(c chan *eventbus.Event) { // Unsubscribe removes the channel from the // list of subscribers. -func (b *EventBus) Unsubscribe(c chan *eventbus.Event) { +func (b *Bus) Unsubscribe(c chan *bus.Event) { b.Lock() delete(b.subs, c) b.Unlock() } // Send dispatches a message to all subscribers. -func (b *EventBus) Send(event *eventbus.Event) { +func (b *Bus) Send(event *bus.Event) { b.Lock() defer b.Unlock() for s := range b.subs { - go func(c chan *eventbus.Event) { + go func(c chan *bus.Event) { defer recover() c <- event }(s) diff --git a/eventbus/builtin/bus_test.go b/pkg/bus/builtin/bus_test.go similarity index 69% rename from eventbus/builtin/bus_test.go rename to pkg/bus/builtin/bus_test.go index 7e67b664..c00bbc29 100644 --- a/eventbus/builtin/bus_test.go +++ b/pkg/bus/builtin/bus_test.go @@ -3,7 +3,7 @@ package builtin import ( "testing" - "github.com/drone/drone/eventbus" + "github.com/drone/drone/pkg/bus" . "github.com/franela/goblin" ) @@ -12,8 +12,8 @@ func TestBuild(t *testing.T) { g.Describe("Bus", func() { g.It("Should unsubscribe", func() { - c1 := make(chan *eventbus.Event) - c2 := make(chan *eventbus.Event) + c1 := make(chan *bus.Event) + c2 := make(chan *bus.Event) b := New() b.Subscribe(c1) b.Subscribe(c2) @@ -21,8 +21,8 @@ func TestBuild(t *testing.T) { }) g.It("Should subscribe", func() { - c1 := make(chan *eventbus.Event) - c2 := make(chan *eventbus.Event) + c1 := make(chan *bus.Event) + c2 := make(chan *bus.Event) b := New() b.Subscribe(c1) b.Subscribe(c2) @@ -33,9 +33,9 @@ func TestBuild(t *testing.T) { }) g.It("Should send", func() { - e1 := &eventbus.Event{Name: "foo"} - e2 := &eventbus.Event{Name: "bar"} - c := make(chan *eventbus.Event) + e1 := &bus.Event{Name: "foo"} + e2 := &bus.Event{Name: "bar"} + c := make(chan *bus.Event) b := New() b.Subscribe(c) b.Send(e1) diff --git a/eventbus/bus.go b/pkg/bus/bus.go similarity index 92% rename from eventbus/bus.go rename to pkg/bus/bus.go index 7e61ddf5..bed61b6f 100644 --- a/eventbus/bus.go +++ b/pkg/bus/bus.go @@ -1,4 +1,4 @@ -package eventbus +package bus const ( EventRepo = "repo" diff --git a/datastore/builtin/agent.go b/pkg/store/builtin/agent.go similarity index 100% rename from datastore/builtin/agent.go rename to pkg/store/builtin/agent.go diff --git a/datastore/builtin/blob.go b/pkg/store/builtin/blob.go similarity index 100% rename from datastore/builtin/blob.go rename to pkg/store/builtin/blob.go diff --git a/datastore/builtin/blob_test.go b/pkg/store/builtin/blob_test.go similarity index 100% rename from datastore/builtin/blob_test.go rename to pkg/store/builtin/blob_test.go diff --git a/datastore/builtin/build.go b/pkg/store/builtin/build.go similarity index 100% rename from datastore/builtin/build.go rename to pkg/store/builtin/build.go diff --git a/datastore/builtin/build_test.go b/pkg/store/builtin/build_test.go similarity index 100% rename from datastore/builtin/build_test.go rename to pkg/store/builtin/build_test.go diff --git a/datastore/builtin/commit.go b/pkg/store/builtin/commit.go similarity index 100% rename from datastore/builtin/commit.go rename to pkg/store/builtin/commit.go diff --git a/datastore/builtin/commit_test.go b/pkg/store/builtin/commit_test.go similarity index 100% rename from datastore/builtin/commit_test.go rename to pkg/store/builtin/commit_test.go diff --git a/datastore/builtin/migrate/helper.go b/pkg/store/builtin/migrate/helper.go similarity index 100% rename from datastore/builtin/migrate/helper.go rename to pkg/store/builtin/migrate/helper.go diff --git a/datastore/builtin/migrate/migrate.go b/pkg/store/builtin/migrate/migrate.go similarity index 100% rename from datastore/builtin/migrate/migrate.go rename to pkg/store/builtin/migrate/migrate.go diff --git a/datastore/builtin/migrate/version.go b/pkg/store/builtin/migrate/version.go similarity index 100% rename from datastore/builtin/migrate/version.go rename to pkg/store/builtin/migrate/version.go diff --git a/datastore/builtin/repo.go b/pkg/store/builtin/repo.go similarity index 100% rename from datastore/builtin/repo.go rename to pkg/store/builtin/repo.go diff --git a/datastore/builtin/repo_test.go b/pkg/store/builtin/repo_test.go similarity index 100% rename from datastore/builtin/repo_test.go rename to pkg/store/builtin/repo_test.go diff --git a/datastore/builtin/star.go b/pkg/store/builtin/star.go similarity index 100% rename from datastore/builtin/star.go rename to pkg/store/builtin/star.go diff --git a/datastore/builtin/star_test.go b/pkg/store/builtin/star_test.go similarity index 100% rename from datastore/builtin/star_test.go rename to pkg/store/builtin/star_test.go diff --git a/datastore/builtin/datastore.go b/pkg/store/builtin/store.go similarity index 93% rename from datastore/builtin/datastore.go rename to pkg/store/builtin/store.go index fec2f01f..8ff575f6 100644 --- a/datastore/builtin/datastore.go +++ b/pkg/store/builtin/store.go @@ -4,8 +4,8 @@ import ( "database/sql" "os" - "github.com/drone/drone/datastore" - "github.com/drone/drone/datastore/builtin/migrate" + "github.com/drone/drone/pkg/store" + "github.com/drone/drone/pkg/store/builtin/migrate" "github.com/BurntSushi/migration" _ "github.com/lib/pq" @@ -71,7 +71,7 @@ func mustConnectTest() *sql.DB { } // New returns a new Datastore -func New(db *sql.DB) datastore.Datastore { +func New(db *sql.DB) store.Store { return struct { *Userstore *Repostore diff --git a/datastore/builtin/token.go b/pkg/store/builtin/token.go similarity index 100% rename from datastore/builtin/token.go rename to pkg/store/builtin/token.go diff --git a/datastore/builtin/token_test.go b/pkg/store/builtin/token_test.go similarity index 100% rename from datastore/builtin/token_test.go rename to pkg/store/builtin/token_test.go diff --git a/datastore/builtin/user.go b/pkg/store/builtin/user.go similarity index 100% rename from datastore/builtin/user.go rename to pkg/store/builtin/user.go diff --git a/datastore/builtin/users_test.go b/pkg/store/builtin/users_test.go similarity index 100% rename from datastore/builtin/users_test.go rename to pkg/store/builtin/users_test.go diff --git a/datastore/builtin/util.go b/pkg/store/builtin/util.go similarity index 100% rename from datastore/builtin/util.go rename to pkg/store/builtin/util.go diff --git a/datastore/mock/mock.go b/pkg/store/mock/mock.go similarity index 61% rename from datastore/mock/mock.go rename to pkg/store/mock/mock.go index 1f4e578f..6338bb91 100644 --- a/datastore/mock/mock.go +++ b/pkg/store/mock/mock.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/mock" ) -type Datastore struct { +type Store struct { mock.Mock } -func (m *Datastore) User(id int64) (*common.User, error) { +func (m *Store) User(id int64) (*common.User, error) { ret := m.Called(id) var r0 *common.User @@ -22,7 +22,7 @@ func (m *Datastore) User(id int64) (*common.User, error) { return r0, r1 } -func (m *Datastore) UserLogin(_a0 string) (*common.User, error) { +func (m *Store) UserLogin(_a0 string) (*common.User, error) { ret := m.Called(_a0) var r0 *common.User @@ -33,7 +33,7 @@ func (m *Datastore) UserLogin(_a0 string) (*common.User, error) { return r0, r1 } -func (m *Datastore) UserList() ([]*common.User, error) { +func (m *Store) UserList() ([]*common.User, error) { ret := m.Called() var r0 []*common.User @@ -44,7 +44,7 @@ func (m *Datastore) UserList() ([]*common.User, error) { return r0, r1 } -func (m *Datastore) UserFeed(_a0 *common.User, _a1 int, _a2 int) ([]*common.RepoCommit, error) { +func (m *Store) UserFeed(_a0 *common.User, _a1 int, _a2 int) ([]*common.RepoCommit, error) { ret := m.Called(_a0, _a1, _a2) var r0 []*common.RepoCommit @@ -55,7 +55,7 @@ func (m *Datastore) UserFeed(_a0 *common.User, _a1 int, _a2 int) ([]*common.Repo return r0, r1 } -func (m *Datastore) UserCount() (int, error) { +func (m *Store) UserCount() (int, error) { ret := m.Called() r0 := ret.Get(0).(int) @@ -63,28 +63,28 @@ func (m *Datastore) UserCount() (int, error) { return r0, r1 } -func (m *Datastore) AddUser(_a0 *common.User) error { +func (m *Store) AddUser(_a0 *common.User) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) SetUser(_a0 *common.User) error { +func (m *Store) SetUser(_a0 *common.User) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) DelUser(_a0 *common.User) error { +func (m *Store) DelUser(_a0 *common.User) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) Token(_a0 int64) (*common.Token, error) { +func (m *Store) Token(_a0 int64) (*common.Token, error) { ret := m.Called(_a0) var r0 *common.Token @@ -95,7 +95,7 @@ func (m *Datastore) Token(_a0 int64) (*common.Token, error) { return r0, r1 } -func (m *Datastore) TokenLabel(_a0 *common.User, _a1 string) (*common.Token, error) { +func (m *Store) TokenLabel(_a0 *common.User, _a1 string) (*common.Token, error) { ret := m.Called(_a0, _a1) var r0 *common.Token @@ -106,7 +106,7 @@ func (m *Datastore) TokenLabel(_a0 *common.User, _a1 string) (*common.Token, err return r0, r1 } -func (m *Datastore) TokenList(_a0 *common.User) ([]*common.Token, error) { +func (m *Store) TokenList(_a0 *common.User) ([]*common.Token, error) { ret := m.Called(_a0) var r0 []*common.Token @@ -117,21 +117,21 @@ func (m *Datastore) TokenList(_a0 *common.User) ([]*common.Token, error) { return r0, r1 } -func (m *Datastore) AddToken(_a0 *common.Token) error { +func (m *Store) AddToken(_a0 *common.Token) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) DelToken(_a0 *common.Token) error { +func (m *Store) DelToken(_a0 *common.Token) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) Starred(_a0 *common.User, _a1 *common.Repo) (bool, error) { +func (m *Store) Starred(_a0 *common.User, _a1 *common.Repo) (bool, error) { ret := m.Called(_a0, _a1) r0 := ret.Get(0).(bool) @@ -139,21 +139,21 @@ func (m *Datastore) Starred(_a0 *common.User, _a1 *common.Repo) (bool, error) { return r0, r1 } -func (m *Datastore) AddStar(_a0 *common.User, _a1 *common.Repo) error { +func (m *Store) AddStar(_a0 *common.User, _a1 *common.Repo) error { ret := m.Called(_a0, _a1) r0 := ret.Error(0) return r0 } -func (m *Datastore) DelStar(_a0 *common.User, _a1 *common.Repo) error { +func (m *Store) DelStar(_a0 *common.User, _a1 *common.Repo) error { ret := m.Called(_a0, _a1) r0 := ret.Error(0) return r0 } -func (m *Datastore) Repo(id int64) (*common.Repo, error) { +func (m *Store) Repo(id int64) (*common.Repo, error) { ret := m.Called(id) var r0 *common.Repo @@ -164,7 +164,7 @@ func (m *Datastore) Repo(id int64) (*common.Repo, error) { return r0, r1 } -func (m *Datastore) RepoName(owner string, name string) (*common.Repo, error) { +func (m *Store) RepoName(owner string, name string) (*common.Repo, error) { ret := m.Called(owner, name) var r0 *common.Repo @@ -175,7 +175,7 @@ func (m *Datastore) RepoName(owner string, name string) (*common.Repo, error) { return r0, r1 } -func (m *Datastore) RepoList(_a0 *common.User) ([]*common.Repo, error) { +func (m *Store) RepoList(_a0 *common.User) ([]*common.Repo, error) { ret := m.Called(_a0) var r0 []*common.Repo @@ -186,28 +186,28 @@ func (m *Datastore) RepoList(_a0 *common.User) ([]*common.Repo, error) { return r0, r1 } -func (m *Datastore) AddRepo(_a0 *common.Repo) error { +func (m *Store) AddRepo(_a0 *common.Repo) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) SetRepo(_a0 *common.Repo) error { +func (m *Store) SetRepo(_a0 *common.Repo) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) DelRepo(_a0 *common.Repo) error { +func (m *Store) DelRepo(_a0 *common.Repo) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) Commit(_a0 int64) (*common.Commit, error) { +func (m *Store) Commit(_a0 int64) (*common.Commit, error) { ret := m.Called(_a0) var r0 *common.Commit @@ -218,7 +218,7 @@ func (m *Datastore) Commit(_a0 int64) (*common.Commit, error) { return r0, r1 } -func (m *Datastore) CommitSeq(_a0 *common.Repo, _a1 int) (*common.Commit, error) { +func (m *Store) CommitSeq(_a0 *common.Repo, _a1 int) (*common.Commit, error) { ret := m.Called(_a0, _a1) var r0 *common.Commit @@ -229,7 +229,7 @@ func (m *Datastore) CommitSeq(_a0 *common.Repo, _a1 int) (*common.Commit, error) return r0, r1 } -func (m *Datastore) CommitLast(_a0 *common.Repo, _a1 string) (*common.Commit, error) { +func (m *Store) CommitLast(_a0 *common.Repo, _a1 string) (*common.Commit, error) { ret := m.Called(_a0, _a1) var r0 *common.Commit @@ -240,7 +240,7 @@ func (m *Datastore) CommitLast(_a0 *common.Repo, _a1 string) (*common.Commit, er return r0, r1 } -func (m *Datastore) CommitList(_a0 *common.Repo, _a1 int, _a2 int) ([]*common.Commit, error) { +func (m *Store) CommitList(_a0 *common.Repo, _a1 int, _a2 int) ([]*common.Commit, error) { ret := m.Called(_a0, _a1, _a2) var r0 []*common.Commit @@ -251,28 +251,28 @@ func (m *Datastore) CommitList(_a0 *common.Repo, _a1 int, _a2 int) ([]*common.Co return r0, r1 } -func (m *Datastore) AddCommit(_a0 *common.Commit) error { +func (m *Store) AddCommit(_a0 *common.Commit) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) SetCommit(_a0 *common.Commit) error { +func (m *Store) SetCommit(_a0 *common.Commit) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) KillCommits() error { +func (m *Store) KillCommits() error { ret := m.Called() r0 := ret.Error(0) return r0 } -func (m *Datastore) Build(_a0 int64) (*common.Build, error) { +func (m *Store) Build(_a0 int64) (*common.Build, error) { ret := m.Called(_a0) var r0 *common.Build @@ -283,7 +283,7 @@ func (m *Datastore) Build(_a0 int64) (*common.Build, error) { return r0, r1 } -func (m *Datastore) BuildSeq(_a0 *common.Commit, _a1 int) (*common.Build, error) { +func (m *Store) BuildSeq(_a0 *common.Commit, _a1 int) (*common.Build, error) { ret := m.Called(_a0, _a1) var r0 *common.Build @@ -294,7 +294,7 @@ func (m *Datastore) BuildSeq(_a0 *common.Commit, _a1 int) (*common.Build, error) return r0, r1 } -func (m *Datastore) BuildList(_a0 *common.Commit) ([]*common.Build, error) { +func (m *Store) BuildList(_a0 *common.Commit) ([]*common.Build, error) { ret := m.Called(_a0) var r0 []*common.Build @@ -305,14 +305,14 @@ func (m *Datastore) BuildList(_a0 *common.Commit) ([]*common.Build, error) { return r0, r1 } -func (m *Datastore) SetBuild(_a0 *common.Build) error { +func (m *Store) SetBuild(_a0 *common.Build) error { ret := m.Called(_a0) r0 := ret.Error(0) return r0 } -func (m *Datastore) GetBlob(path string) ([]byte, error) { +func (m *Store) GetBlob(path string) ([]byte, error) { ret := m.Called(path) var r0 []byte @@ -323,7 +323,7 @@ func (m *Datastore) GetBlob(path string) ([]byte, error) { return r0, r1 } -func (m *Datastore) GetBlobReader(path string) (io.ReadCloser, error) { +func (m *Store) GetBlobReader(path string) (io.ReadCloser, error) { ret := m.Called(path) r0 := ret.Get(0).(io.ReadCloser) @@ -331,21 +331,21 @@ func (m *Datastore) GetBlobReader(path string) (io.ReadCloser, error) { return r0, r1 } -func (m *Datastore) SetBlob(path string, data []byte) error { +func (m *Store) SetBlob(path string, data []byte) error { ret := m.Called(path, data) r0 := ret.Error(0) return r0 } -func (m *Datastore) SetBlobReader(path string, r io.Reader) error { +func (m *Store) SetBlobReader(path string, r io.Reader) error { ret := m.Called(path, r) r0 := ret.Error(0) return r0 } -func (m *Datastore) DelBlob(path string) error { +func (m *Store) DelBlob(path string) error { ret := m.Called(path) r0 := ret.Error(0) diff --git a/datastore/plugin/build.go b/pkg/store/plugin/build.go similarity index 100% rename from datastore/plugin/build.go rename to pkg/store/plugin/build.go diff --git a/datastore/plugin/client.go b/pkg/store/plugin/client.go similarity index 100% rename from datastore/plugin/client.go rename to pkg/store/plugin/client.go diff --git a/datastore/plugin/repo.go b/pkg/store/plugin/repo.go similarity index 100% rename from datastore/plugin/repo.go rename to pkg/store/plugin/repo.go diff --git a/datastore/plugin/task.go b/pkg/store/plugin/task.go similarity index 100% rename from datastore/plugin/task.go rename to pkg/store/plugin/task.go diff --git a/datastore/plugin/token.go b/pkg/store/plugin/token.go similarity index 100% rename from datastore/plugin/token.go rename to pkg/store/plugin/token.go diff --git a/datastore/plugin/user.go b/pkg/store/plugin/user.go similarity index 100% rename from datastore/plugin/user.go rename to pkg/store/plugin/user.go diff --git a/datastore/datastore.go b/pkg/store/store.go similarity index 98% rename from datastore/datastore.go rename to pkg/store/store.go index a811234f..7d645fde 100644 --- a/datastore/datastore.go +++ b/pkg/store/store.go @@ -1,4 +1,4 @@ -package datastore +package store import ( "io" @@ -6,7 +6,7 @@ import ( "github.com/drone/drone/common" ) -type Datastore interface { +type Store interface { // User returns a user by user ID. User(id int64) (*common.User, error) diff --git a/runner/builtin/updater.go b/runner/builtin/updater.go index eda8d578..45c05687 100644 --- a/runner/builtin/updater.go +++ b/runner/builtin/updater.go @@ -6,8 +6,8 @@ import ( "io" "github.com/drone/drone/common" - "github.com/drone/drone/datastore" - "github.com/drone/drone/eventbus" + "github.com/drone/drone/pkg/bus" + "github.com/drone/drone/pkg/store" "github.com/drone/drone/remote" ) @@ -19,13 +19,13 @@ type Updater interface { // NewUpdater returns an implementation of the Updater interface // that directly modifies the database and sends messages to the bus. -func NewUpdater(bus eventbus.Bus, store datastore.Datastore, rem remote.Remote) Updater { +func NewUpdater(bus bus.Bus, store store.Store, rem remote.Remote) Updater { return &updater{bus, store, rem} } type updater struct { - bus eventbus.Bus - store datastore.Datastore + bus bus.Bus + store store.Store remote remote.Remote } @@ -45,9 +45,9 @@ func (u *updater) SetCommit(user *common.User, r *common.Repo, c *common.Commit) return err } - u.bus.Send(&eventbus.Event{ + u.bus.Send(&bus.Event{ Name: r.FullName, - Kind: eventbus.EventRepo, + Kind: bus.EventRepo, Msg: msg, }) return nil @@ -64,9 +64,9 @@ func (u *updater) SetBuild(r *common.Repo, c *common.Commit, b *common.Build) er return err } - u.bus.Send(&eventbus.Event{ + u.bus.Send(&bus.Event{ Name: r.FullName, - Kind: eventbus.EventRepo, + Kind: bus.EventRepo, Msg: msg, }) return nil diff --git a/server/server.go b/server/server.go index 31f83d17..b021d200 100644 --- a/server/server.go +++ b/server/server.go @@ -7,8 +7,8 @@ import ( "github.com/gin-gonic/gin" "github.com/drone/drone/common" - "github.com/drone/drone/datastore" - "github.com/drone/drone/eventbus" + "github.com/drone/drone/pkg/bus" + "github.com/drone/drone/pkg/store" "github.com/drone/drone/queue" "github.com/drone/drone/remote" "github.com/drone/drone/runner" @@ -31,19 +31,19 @@ func ToQueue(c *gin.Context) queue.Queue { return v.(queue.Queue) } -func SetBus(r eventbus.Bus) gin.HandlerFunc { +func SetBus(r bus.Bus) gin.HandlerFunc { return func(c *gin.Context) { - c.Set("eventbus", r) + c.Set("bus", r) c.Next() } } -func ToBus(c *gin.Context) eventbus.Bus { - v, ok := c.Get("eventbus") +func ToBus(c *gin.Context) bus.Bus { + v, ok := c.Get("bus") if !ok { return nil } - return v.(eventbus.Bus) + return v.(bus.Bus) } func ToRemote(c *gin.Context) remote.Remote { @@ -115,15 +115,15 @@ func ToRepo(c *gin.Context) *common.Repo { return v.(*common.Repo) } -func ToDatastore(c *gin.Context) datastore.Datastore { - return c.MustGet("datastore").(datastore.Datastore) +func ToDatastore(c *gin.Context) store.Store { + return c.MustGet("datastore").(store.Store) } func ToSession(c *gin.Context) session.Session { return c.MustGet("session").(session.Session) } -func SetDatastore(ds datastore.Datastore) gin.HandlerFunc { +func SetDatastore(ds store.Store) gin.HandlerFunc { return func(c *gin.Context) { c.Set("datastore", ds) c.Next() diff --git a/server/ws.go b/server/ws.go index 7a670642..40ca7696 100644 --- a/server/ws.go +++ b/server/ws.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "github.com/drone/drone/eventbus" + "github.com/drone/drone/pkg/bus" log "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" @@ -37,14 +37,14 @@ var upgrader = websocket.Upgrader{ // GetRepoEvents will upgrade the connection to a Websocket and will stream // event updates to the browser. func GetRepoEvents(c *gin.Context) { - bus := ToBus(c) + bus_ := ToBus(c) repo := ToRepo(c) c.Writer.Header().Set("Content-Type", "text/event-stream") - eventc := make(chan *eventbus.Event, 1) - bus.Subscribe(eventc) + eventc := make(chan *bus.Event, 1) + bus_.Subscribe(eventc) defer func() { - bus.Unsubscribe(eventc) + bus_.Unsubscribe(eventc) log.Infof("closed event stream") }() @@ -55,7 +55,7 @@ func GetRepoEvents(c *gin.Context) { log.Infof("nil event received") return false } - if event.Kind == eventbus.EventRepo && + if event.Kind == bus.EventRepo && event.Name == repo.FullName { d := map[string]interface{}{} json.Unmarshal(event.Msg, &d)