Skip to content

Commit

Permalink
Update to greboid/irc/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
greboid committed Sep 29, 2020
1 parent 2dd2dc2 commit ee69c66
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 35 deletions.
10 changes: 5 additions & 5 deletions cmd/github/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"encoding/hex"
"flag"
"fmt"
"github.com/greboid/irc/v2/logger"
"github.com/greboid/irc/v2/plugins"
"github.com/greboid/irc/v2/rpc"
"github.com/greboid/irc/v3/logger"
"github.com/greboid/irc/v3/plugins"
"github.com/greboid/irc/v3/rpc"
"github.com/kouhin/envflag"
"go.uber.org/zap"
"net/http"
Expand All @@ -26,7 +26,7 @@ var (
GithubSecret = flag.String("github-secret", "", "Github secret for validating webhooks")
Debug = flag.Bool("debug", false, "Show debugging info")
log = logger.CreateLogger(*Debug)
helper plugins.PluginHelper
helper *plugins.PluginHelper
)

type github struct {
Expand All @@ -41,7 +41,7 @@ func main() {
log.Fatalf("Unable to load config: %s", err.Error())
return
}
helper, err = plugins.NewHelper(*RPCHost, uint16(*RPCPort), *RPCToken)
helper, err = plugins.NewHelper(fmt.Sprintf("%s:%d", *RPCHost, uint16(*RPCPort)), *RPCToken)
if err != nil {
log.Fatalf("Unable to create plugin helper: %s", err.Error())
return
Expand Down
46 changes: 18 additions & 28 deletions cmd/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ func (g *githubWebhookHandler) handleWebhook(eventType string, bodyBytes []byte)
err := json.Unmarshal(bodyBytes, &data)
if err == nil {
go func() {
err := g.sendMessage([]string{"Ping received."}, false)
if len(err) > 0 {
for index := range err {
log.Errorf("Error handling push: %s", err[index].Error())
}
err := g.sendMessage(false, "Ping received.")
if err != nil {
log.Errorf("Error handling push: %s", err.Error())
}
}()
} else {
Expand All @@ -31,11 +29,9 @@ func (g *githubWebhookHandler) handleWebhook(eventType string, bodyBytes []byte)
err := json.Unmarshal(bodyBytes, &data)
if err == nil {
go func() {
err := g.sendMessage(handler.handlePushEvent(data), data.Repository.IsPrivate)
if len(err) > 0 {
for index := range err {
log.Errorf("Error handling push: %s", err[index].Error())
}
err := g.sendMessage(data.Repository.IsPrivate, handler.handlePushEvent(data)...)
if err != nil {
log.Errorf("Error handling push: %s", err.Error())
}
}()
} else {
Expand All @@ -48,11 +44,9 @@ func (g *githubWebhookHandler) handleWebhook(eventType string, bodyBytes []byte)
err := json.Unmarshal(bodyBytes, &data)
if err == nil {
go func() {
err := g.sendMessage(handler.handlePREvent(data), data.Repository.IsPrivate)
if len(err) > 0 {
for index := range err {
log.Errorf("Error handling push: %s", err[index].Error())
}
err := g.sendMessage(data.Repository.IsPrivate, handler.handlePREvent(data)...)
if err != nil {
log.Errorf("Error handling push: %s", err.Error())
}
}()
} else {
Expand All @@ -65,11 +59,9 @@ func (g *githubWebhookHandler) handleWebhook(eventType string, bodyBytes []byte)
err := json.Unmarshal(bodyBytes, &data)
if err == nil {
go func() {
err := g.sendMessage(handler.handleIssueEvent(data), data.Repository.IsPrivate)
if len(err) > 0 {
for index := range err {
log.Errorf("Error handling push: %s", err[index].Error())
}
err := g.sendMessage(data.Repository.IsPrivate, handler.handleIssueEvent(data)...)
if err != nil {
log.Errorf("Error handling push: %s", err.Error())
}
}()
} else {
Expand All @@ -82,11 +74,9 @@ func (g *githubWebhookHandler) handleWebhook(eventType string, bodyBytes []byte)
err := json.Unmarshal(bodyBytes, &data)
if err == nil {
go func() {
err := g.sendMessage(handler.handleIssueCommentEvent(data), data.Repository.IsPrivate)
if len(err) > 0 {
for index := range err {
log.Errorf("Error handling push: %s", err[index].Error())
}
err := g.sendMessage(data.Repository.IsPrivate, handler.handleIssueCommentEvent(data)...)
if err != nil {
log.Errorf("Error handling push: %s", err.Error())
}
}()
} else {
Expand All @@ -109,14 +99,14 @@ func (g *githubWebhookHandler) handleWebhook(eventType string, bodyBytes []byte)
return nil
}

func (g *githubWebhookHandler) sendMessage(messages []string, isPrivate bool) []error {
func (g *githubWebhookHandler) sendMessage(isPrivate bool, messages ...string) error {
notifyChannel := *Channel
if isPrivate && *HidePrivate {
return []error{}
return nil
}
if isPrivate && len(*PrivateChannel) != 0 {
notifyChannel = *PrivateChannel
}
errors := helper.SendIRCMessage(notifyChannel, messages)
errors := helper.SendChannelMessage(notifyChannel, messages...)
return errors
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/greboid/irc-github/v2
module github.com/greboid/irc-github/v3

go 1.15

require (
github.com/greboid/irc/v2 v2.0.3
github.com/greboid/irc/v3 v3.0.1
github.com/kouhin/envflag v0.0.0-20150818174321-0e9a86061649
github.com/sebdah/goldie/v2 v2.5.1
go.uber.org/zap v1.16.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/greboid/irc/v2 v2.0.3 h1:11R6FT85HszZSfQL+cCT5jGGtg+70W8r3H9lbj/IOAI=
github.com/greboid/irc/v2 v2.0.3/go.mod h1:wG5xtqTL0sBVow9LZw+16M8lZrv+D4IaywXl9H8w3qk=
github.com/greboid/irc/v3 v3.0.1 h1:aSoKDnC0P3eXaUk/OLg7QzJfBF4E47XwcLmufvllhsQ=
github.com/greboid/irc/v3 v3.0.1/go.mod h1:gnc8yyD5npBR4H2uLsPliihaT4Qhu5rtPhdQTMC3VjQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down Expand Up @@ -426,6 +428,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
Expand Down

0 comments on commit ee69c66

Please sign in to comment.