Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly quit irc after sending failure/success #139

Merged
merged 1 commit into from
Feb 28, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
properly quit irc after sending failure/success
  • Loading branch information
jordane committed Feb 27, 2014
commit bab544261a86644e560d78594a38c0ec1b90f911
36 changes: 20 additions & 16 deletions pkg/plugin/notify/irc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type IRC struct {
Success bool `yaml:"on_success,omitempty"`
Failure bool `yaml:"on_failure,omitempty"`
SSL bool `yaml:"ssl,omitempty"`
ClientStarted bool
Client *irc.Conn
ClientStarted bool
Client *irc.Conn
}

func (i *IRC) Connect() {
Expand All @@ -30,20 +30,15 @@ func (i *IRC) Connect() {
connected := make(chan bool)
c.AddHandler(irc.CONNECTED,
func(conn *irc.Conn, line *irc.Line) {
conn.Join(i.Channel)
conn.Join(i.Channel)
connected <- true})
c.Connect(i.Server)
<-connected
i.Client = c
i.ClientStarted = true
i.Client = c
}

func (i *IRC) Send(context *Context) error {

if !i.ClientStarted {
i.Connect()
}

switch {
case context.Commit.Status == "Started" && i.Started:
return i.sendStarted(context)
Expand All @@ -57,24 +52,33 @@ func (i *IRC) Send(context *Context) error {

func (i *IRC) sendStarted(context *Context) error {
msg := fmt.Sprintf(ircStartedMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg)
return nil
i.send(i.Channel, msg)
return nil
}

func (i *IRC) sendFailure(context *Context) error {
msg := fmt.Sprintf(ircFailureMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg)
return nil
i.send(i.Channel, msg)
if i.ClientStarted {
i.Client.Quit()
}
return nil
}

func (i *IRC) sendSuccess(context *Context) error {
msg := fmt.Sprintf(ircSuccessMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
i.send(i.Channel, msg)
return nil
i.send(i.Channel, msg)
if i.ClientStarted {
i.Client.Quit()
}
return nil
}


func (i *IRC) send(channel string, message string) error {
i.Client.Notice(channel, message)
if !i.ClientStarted {
i.Connect()
}
i.Client.Notice(channel, message)
return nil
}