Merge pull request #139 from jordane/jordane/add_irc_plugin

properly quit irc after sending failure/success
This commit is contained in:
Brad Rydzewski 2014-02-27 16:00:21 -08:00
commit 252a8a9e68

View file

@ -34,16 +34,11 @@ func (i *IRC) Connect() {
connected <- true}) connected <- true})
c.Connect(i.Server) c.Connect(i.Server)
<-connected <-connected
i.Client = c
i.ClientStarted = true i.ClientStarted = true
i.Client = c
} }
func (i *IRC) Send(context *Context) error { func (i *IRC) Send(context *Context) error {
if !i.ClientStarted {
i.Connect()
}
switch { switch {
case context.Commit.Status == "Started" && i.Started: case context.Commit.Status == "Started" && i.Started:
return i.sendStarted(context) return i.sendStarted(context)
@ -64,17 +59,26 @@ func (i *IRC) sendStarted(context *Context) error {
func (i *IRC) sendFailure(context *Context) error { func (i *IRC) sendFailure(context *Context) error {
msg := fmt.Sprintf(ircFailureMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author) msg := fmt.Sprintf(ircFailureMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg) i.send(i.Channel, msg)
if i.ClientStarted {
i.Client.Quit()
}
return nil return nil
} }
func (i *IRC) sendSuccess(context *Context) error { func (i *IRC) sendSuccess(context *Context) error {
msg := fmt.Sprintf(ircSuccessMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author) msg := fmt.Sprintf(ircSuccessMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg) i.send(i.Channel, msg)
if i.ClientStarted {
i.Client.Quit()
}
return nil return nil
} }
func (i *IRC) send(channel string, message string) error { func (i *IRC) send(channel string, message string) error {
if !i.ClientStarted {
i.Connect()
}
i.Client.Notice(channel, message) i.Client.Notice(channel, message)
return nil return nil
} }