refactoring toward multi-binary project layout

This commit is contained in:
Brad Rydzewski 2015-05-17 11:10:43 -07:00
parent 2e9786c68e
commit 4c847296d4
35 changed files with 91 additions and 91 deletions

View file

@ -13,8 +13,8 @@ import (
"github.com/drone/drone/settings" "github.com/drone/drone/settings"
"github.com/elazarl/go-bindata-assetfs" "github.com/elazarl/go-bindata-assetfs"
store "github.com/drone/drone/datastore/builtin" eventbus "github.com/drone/drone/pkg/bus/builtin"
eventbus "github.com/drone/drone/eventbus/builtin" store "github.com/drone/drone/pkg/store/builtin"
queue "github.com/drone/drone/queue/builtin" queue "github.com/drone/drone/queue/builtin"
runner "github.com/drone/drone/runner/builtin" runner "github.com/drone/drone/runner/builtin"

View file

@ -3,26 +3,26 @@ package builtin
import ( import (
"sync" "sync"
"github.com/drone/drone/eventbus" "github.com/drone/drone/pkg/bus"
) )
type EventBus struct { type Bus struct {
sync.Mutex 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. // subscribers to which events are published.
func New() *EventBus { func New() *Bus {
return &EventBus{ return &Bus{
subs: make(map[chan *eventbus.Event]bool), subs: make(map[chan *bus.Event]bool),
} }
} }
// Subscribe adds the channel to the list of // Subscribe adds the channel to the list of
// subscribers. Each subscriber in the list will // subscribers. Each subscriber in the list will
// receive broadcast events. // receive broadcast events.
func (b *EventBus) Subscribe(c chan *eventbus.Event) { func (b *Bus) Subscribe(c chan *bus.Event) {
b.Lock() b.Lock()
b.subs[c] = true b.subs[c] = true
b.Unlock() b.Unlock()
@ -30,19 +30,19 @@ func (b *EventBus) Subscribe(c chan *eventbus.Event) {
// Unsubscribe removes the channel from the // Unsubscribe removes the channel from the
// list of subscribers. // list of subscribers.
func (b *EventBus) Unsubscribe(c chan *eventbus.Event) { func (b *Bus) Unsubscribe(c chan *bus.Event) {
b.Lock() b.Lock()
delete(b.subs, c) delete(b.subs, c)
b.Unlock() b.Unlock()
} }
// Send dispatches a message to all subscribers. // Send dispatches a message to all subscribers.
func (b *EventBus) Send(event *eventbus.Event) { func (b *Bus) Send(event *bus.Event) {
b.Lock() b.Lock()
defer b.Unlock() defer b.Unlock()
for s := range b.subs { for s := range b.subs {
go func(c chan *eventbus.Event) { go func(c chan *bus.Event) {
defer recover() defer recover()
c <- event c <- event
}(s) }(s)

View file

@ -3,7 +3,7 @@ package builtin
import ( import (
"testing" "testing"
"github.com/drone/drone/eventbus" "github.com/drone/drone/pkg/bus"
. "github.com/franela/goblin" . "github.com/franela/goblin"
) )
@ -12,8 +12,8 @@ func TestBuild(t *testing.T) {
g.Describe("Bus", func() { g.Describe("Bus", func() {
g.It("Should unsubscribe", func() { g.It("Should unsubscribe", func() {
c1 := make(chan *eventbus.Event) c1 := make(chan *bus.Event)
c2 := make(chan *eventbus.Event) c2 := make(chan *bus.Event)
b := New() b := New()
b.Subscribe(c1) b.Subscribe(c1)
b.Subscribe(c2) b.Subscribe(c2)
@ -21,8 +21,8 @@ func TestBuild(t *testing.T) {
}) })
g.It("Should subscribe", func() { g.It("Should subscribe", func() {
c1 := make(chan *eventbus.Event) c1 := make(chan *bus.Event)
c2 := make(chan *eventbus.Event) c2 := make(chan *bus.Event)
b := New() b := New()
b.Subscribe(c1) b.Subscribe(c1)
b.Subscribe(c2) b.Subscribe(c2)
@ -33,9 +33,9 @@ func TestBuild(t *testing.T) {
}) })
g.It("Should send", func() { g.It("Should send", func() {
e1 := &eventbus.Event{Name: "foo"} e1 := &bus.Event{Name: "foo"}
e2 := &eventbus.Event{Name: "bar"} e2 := &bus.Event{Name: "bar"}
c := make(chan *eventbus.Event) c := make(chan *bus.Event)
b := New() b := New()
b.Subscribe(c) b.Subscribe(c)
b.Send(e1) b.Send(e1)

View file

@ -1,4 +1,4 @@
package eventbus package bus
const ( const (
EventRepo = "repo" EventRepo = "repo"

View file

@ -4,8 +4,8 @@ import (
"database/sql" "database/sql"
"os" "os"
"github.com/drone/drone/datastore" "github.com/drone/drone/pkg/store"
"github.com/drone/drone/datastore/builtin/migrate" "github.com/drone/drone/pkg/store/builtin/migrate"
"github.com/BurntSushi/migration" "github.com/BurntSushi/migration"
_ "github.com/lib/pq" _ "github.com/lib/pq"
@ -71,7 +71,7 @@ func mustConnectTest() *sql.DB {
} }
// New returns a new Datastore // New returns a new Datastore
func New(db *sql.DB) datastore.Datastore { func New(db *sql.DB) store.Store {
return struct { return struct {
*Userstore *Userstore
*Repostore *Repostore

View file

@ -7,11 +7,11 @@ import (
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
type Datastore struct { type Store struct {
mock.Mock mock.Mock
} }
func (m *Datastore) User(id int64) (*common.User, error) { func (m *Store) User(id int64) (*common.User, error) {
ret := m.Called(id) ret := m.Called(id)
var r0 *common.User var r0 *common.User
@ -22,7 +22,7 @@ func (m *Datastore) User(id int64) (*common.User, error) {
return r0, r1 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) ret := m.Called(_a0)
var r0 *common.User var r0 *common.User
@ -33,7 +33,7 @@ func (m *Datastore) UserLogin(_a0 string) (*common.User, error) {
return r0, r1 return r0, r1
} }
func (m *Datastore) UserList() ([]*common.User, error) { func (m *Store) UserList() ([]*common.User, error) {
ret := m.Called() ret := m.Called()
var r0 []*common.User var r0 []*common.User
@ -44,7 +44,7 @@ func (m *Datastore) UserList() ([]*common.User, error) {
return r0, r1 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) ret := m.Called(_a0, _a1, _a2)
var r0 []*common.RepoCommit var r0 []*common.RepoCommit
@ -55,7 +55,7 @@ func (m *Datastore) UserFeed(_a0 *common.User, _a1 int, _a2 int) ([]*common.Repo
return r0, r1 return r0, r1
} }
func (m *Datastore) UserCount() (int, error) { func (m *Store) UserCount() (int, error) {
ret := m.Called() ret := m.Called()
r0 := ret.Get(0).(int) r0 := ret.Get(0).(int)
@ -63,28 +63,28 @@ func (m *Datastore) UserCount() (int, error) {
return r0, r1 return r0, r1
} }
func (m *Datastore) AddUser(_a0 *common.User) error { func (m *Store) AddUser(_a0 *common.User) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) SetUser(_a0 *common.User) error { func (m *Store) SetUser(_a0 *common.User) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) DelUser(_a0 *common.User) error { func (m *Store) DelUser(_a0 *common.User) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) Token(_a0 int64) (*common.Token, error) { func (m *Store) Token(_a0 int64) (*common.Token, error) {
ret := m.Called(_a0) ret := m.Called(_a0)
var r0 *common.Token var r0 *common.Token
@ -95,7 +95,7 @@ func (m *Datastore) Token(_a0 int64) (*common.Token, error) {
return r0, r1 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) ret := m.Called(_a0, _a1)
var r0 *common.Token var r0 *common.Token
@ -106,7 +106,7 @@ func (m *Datastore) TokenLabel(_a0 *common.User, _a1 string) (*common.Token, err
return r0, r1 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) ret := m.Called(_a0)
var r0 []*common.Token var r0 []*common.Token
@ -117,21 +117,21 @@ func (m *Datastore) TokenList(_a0 *common.User) ([]*common.Token, error) {
return r0, r1 return r0, r1
} }
func (m *Datastore) AddToken(_a0 *common.Token) error { func (m *Store) AddToken(_a0 *common.Token) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) DelToken(_a0 *common.Token) error { func (m *Store) DelToken(_a0 *common.Token) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 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) ret := m.Called(_a0, _a1)
r0 := ret.Get(0).(bool) r0 := ret.Get(0).(bool)
@ -139,21 +139,21 @@ func (m *Datastore) Starred(_a0 *common.User, _a1 *common.Repo) (bool, error) {
return r0, r1 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) ret := m.Called(_a0, _a1)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 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) ret := m.Called(_a0, _a1)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) Repo(id int64) (*common.Repo, error) { func (m *Store) Repo(id int64) (*common.Repo, error) {
ret := m.Called(id) ret := m.Called(id)
var r0 *common.Repo var r0 *common.Repo
@ -164,7 +164,7 @@ func (m *Datastore) Repo(id int64) (*common.Repo, error) {
return r0, r1 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) ret := m.Called(owner, name)
var r0 *common.Repo var r0 *common.Repo
@ -175,7 +175,7 @@ func (m *Datastore) RepoName(owner string, name string) (*common.Repo, error) {
return r0, r1 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) ret := m.Called(_a0)
var r0 []*common.Repo var r0 []*common.Repo
@ -186,28 +186,28 @@ func (m *Datastore) RepoList(_a0 *common.User) ([]*common.Repo, error) {
return r0, r1 return r0, r1
} }
func (m *Datastore) AddRepo(_a0 *common.Repo) error { func (m *Store) AddRepo(_a0 *common.Repo) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) SetRepo(_a0 *common.Repo) error { func (m *Store) SetRepo(_a0 *common.Repo) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) DelRepo(_a0 *common.Repo) error { func (m *Store) DelRepo(_a0 *common.Repo) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) Commit(_a0 int64) (*common.Commit, error) { func (m *Store) Commit(_a0 int64) (*common.Commit, error) {
ret := m.Called(_a0) ret := m.Called(_a0)
var r0 *common.Commit var r0 *common.Commit
@ -218,7 +218,7 @@ func (m *Datastore) Commit(_a0 int64) (*common.Commit, error) {
return r0, r1 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) ret := m.Called(_a0, _a1)
var r0 *common.Commit var r0 *common.Commit
@ -229,7 +229,7 @@ func (m *Datastore) CommitSeq(_a0 *common.Repo, _a1 int) (*common.Commit, error)
return r0, r1 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) ret := m.Called(_a0, _a1)
var r0 *common.Commit var r0 *common.Commit
@ -240,7 +240,7 @@ func (m *Datastore) CommitLast(_a0 *common.Repo, _a1 string) (*common.Commit, er
return r0, r1 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) ret := m.Called(_a0, _a1, _a2)
var r0 []*common.Commit var r0 []*common.Commit
@ -251,28 +251,28 @@ func (m *Datastore) CommitList(_a0 *common.Repo, _a1 int, _a2 int) ([]*common.Co
return r0, r1 return r0, r1
} }
func (m *Datastore) AddCommit(_a0 *common.Commit) error { func (m *Store) AddCommit(_a0 *common.Commit) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) SetCommit(_a0 *common.Commit) error { func (m *Store) SetCommit(_a0 *common.Commit) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) KillCommits() error { func (m *Store) KillCommits() error {
ret := m.Called() ret := m.Called()
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) Build(_a0 int64) (*common.Build, error) { func (m *Store) Build(_a0 int64) (*common.Build, error) {
ret := m.Called(_a0) ret := m.Called(_a0)
var r0 *common.Build var r0 *common.Build
@ -283,7 +283,7 @@ func (m *Datastore) Build(_a0 int64) (*common.Build, error) {
return r0, r1 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) ret := m.Called(_a0, _a1)
var r0 *common.Build var r0 *common.Build
@ -294,7 +294,7 @@ func (m *Datastore) BuildSeq(_a0 *common.Commit, _a1 int) (*common.Build, error)
return r0, r1 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) ret := m.Called(_a0)
var r0 []*common.Build var r0 []*common.Build
@ -305,14 +305,14 @@ func (m *Datastore) BuildList(_a0 *common.Commit) ([]*common.Build, error) {
return r0, r1 return r0, r1
} }
func (m *Datastore) SetBuild(_a0 *common.Build) error { func (m *Store) SetBuild(_a0 *common.Build) error {
ret := m.Called(_a0) ret := m.Called(_a0)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) GetBlob(path string) ([]byte, error) { func (m *Store) GetBlob(path string) ([]byte, error) {
ret := m.Called(path) ret := m.Called(path)
var r0 []byte var r0 []byte
@ -323,7 +323,7 @@ func (m *Datastore) GetBlob(path string) ([]byte, error) {
return r0, r1 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) ret := m.Called(path)
r0 := ret.Get(0).(io.ReadCloser) r0 := ret.Get(0).(io.ReadCloser)
@ -331,21 +331,21 @@ func (m *Datastore) GetBlobReader(path string) (io.ReadCloser, error) {
return r0, r1 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) ret := m.Called(path, data)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 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) ret := m.Called(path, r)
r0 := ret.Error(0) r0 := ret.Error(0)
return r0 return r0
} }
func (m *Datastore) DelBlob(path string) error { func (m *Store) DelBlob(path string) error {
ret := m.Called(path) ret := m.Called(path)
r0 := ret.Error(0) r0 := ret.Error(0)

View file

@ -1,4 +1,4 @@
package datastore package store
import ( import (
"io" "io"
@ -6,7 +6,7 @@ import (
"github.com/drone/drone/common" "github.com/drone/drone/common"
) )
type Datastore interface { type Store interface {
// User returns a user by user ID. // User returns a user by user ID.
User(id int64) (*common.User, error) User(id int64) (*common.User, error)

View file

@ -6,8 +6,8 @@ import (
"io" "io"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/datastore" "github.com/drone/drone/pkg/bus"
"github.com/drone/drone/eventbus" "github.com/drone/drone/pkg/store"
"github.com/drone/drone/remote" "github.com/drone/drone/remote"
) )
@ -19,13 +19,13 @@ type Updater interface {
// NewUpdater returns an implementation of the Updater interface // NewUpdater returns an implementation of the Updater interface
// that directly modifies the database and sends messages to the bus. // 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} return &updater{bus, store, rem}
} }
type updater struct { type updater struct {
bus eventbus.Bus bus bus.Bus
store datastore.Datastore store store.Store
remote remote.Remote remote remote.Remote
} }
@ -45,9 +45,9 @@ func (u *updater) SetCommit(user *common.User, r *common.Repo, c *common.Commit)
return err return err
} }
u.bus.Send(&eventbus.Event{ u.bus.Send(&bus.Event{
Name: r.FullName, Name: r.FullName,
Kind: eventbus.EventRepo, Kind: bus.EventRepo,
Msg: msg, Msg: msg,
}) })
return nil return nil
@ -64,9 +64,9 @@ func (u *updater) SetBuild(r *common.Repo, c *common.Commit, b *common.Build) er
return err return err
} }
u.bus.Send(&eventbus.Event{ u.bus.Send(&bus.Event{
Name: r.FullName, Name: r.FullName,
Kind: eventbus.EventRepo, Kind: bus.EventRepo,
Msg: msg, Msg: msg,
}) })
return nil return nil

View file

@ -7,8 +7,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/datastore" "github.com/drone/drone/pkg/bus"
"github.com/drone/drone/eventbus" "github.com/drone/drone/pkg/store"
"github.com/drone/drone/queue" "github.com/drone/drone/queue"
"github.com/drone/drone/remote" "github.com/drone/drone/remote"
"github.com/drone/drone/runner" "github.com/drone/drone/runner"
@ -31,19 +31,19 @@ func ToQueue(c *gin.Context) queue.Queue {
return v.(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) { return func(c *gin.Context) {
c.Set("eventbus", r) c.Set("bus", r)
c.Next() c.Next()
} }
} }
func ToBus(c *gin.Context) eventbus.Bus { func ToBus(c *gin.Context) bus.Bus {
v, ok := c.Get("eventbus") v, ok := c.Get("bus")
if !ok { if !ok {
return nil return nil
} }
return v.(eventbus.Bus) return v.(bus.Bus)
} }
func ToRemote(c *gin.Context) remote.Remote { func ToRemote(c *gin.Context) remote.Remote {
@ -115,15 +115,15 @@ func ToRepo(c *gin.Context) *common.Repo {
return v.(*common.Repo) return v.(*common.Repo)
} }
func ToDatastore(c *gin.Context) datastore.Datastore { func ToDatastore(c *gin.Context) store.Store {
return c.MustGet("datastore").(datastore.Datastore) return c.MustGet("datastore").(store.Store)
} }
func ToSession(c *gin.Context) session.Session { func ToSession(c *gin.Context) session.Session {
return c.MustGet("session").(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) { return func(c *gin.Context) {
c.Set("datastore", ds) c.Set("datastore", ds)
c.Next() c.Next()

View file

@ -8,7 +8,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/drone/drone/eventbus" "github.com/drone/drone/pkg/bus"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -37,14 +37,14 @@ var upgrader = websocket.Upgrader{
// GetRepoEvents will upgrade the connection to a Websocket and will stream // GetRepoEvents will upgrade the connection to a Websocket and will stream
// event updates to the browser. // event updates to the browser.
func GetRepoEvents(c *gin.Context) { func GetRepoEvents(c *gin.Context) {
bus := ToBus(c) bus_ := ToBus(c)
repo := ToRepo(c) repo := ToRepo(c)
c.Writer.Header().Set("Content-Type", "text/event-stream") c.Writer.Header().Set("Content-Type", "text/event-stream")
eventc := make(chan *eventbus.Event, 1) eventc := make(chan *bus.Event, 1)
bus.Subscribe(eventc) bus_.Subscribe(eventc)
defer func() { defer func() {
bus.Unsubscribe(eventc) bus_.Unsubscribe(eventc)
log.Infof("closed event stream") log.Infof("closed event stream")
}() }()
@ -55,7 +55,7 @@ func GetRepoEvents(c *gin.Context) {
log.Infof("nil event received") log.Infof("nil event received")
return false return false
} }
if event.Kind == eventbus.EventRepo && if event.Kind == bus.EventRepo &&
event.Name == repo.FullName { event.Name == repo.FullName {
d := map[string]interface{}{} d := map[string]interface{}{}
json.Unmarshal(event.Msg, &d) json.Unmarshal(event.Msg, &d)