some fixes + xmpp update
This commit is contained in:
parent
caf0dfe497
commit
5d57274202
|
@ -6,16 +6,15 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/bdlm/log"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
libHTTP "github.com/genofire/golang-lib/http"
|
||||
xmpp "github.com/mattn/go-xmpp"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
"dev.sum7.eu/genofire/hook2xmpp/runtime"
|
||||
)
|
||||
|
||||
const hookType = "circleci"
|
||||
|
||||
|
||||
type requestBody struct {
|
||||
Payload struct {
|
||||
VCSURL string `mapstructure:"vcs_url"`
|
||||
|
@ -33,6 +32,7 @@ func (r requestBody) String() string {
|
|||
|
||||
func init() {
|
||||
runtime.HookRegister[hookType] = func(client *xmpp.Client, hooks []runtime.Hook) func(w http.ResponseWriter, r *http.Request) {
|
||||
log.WithField("type", hookType).Info("loaded")
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
logger := log.WithField("type", hookType)
|
||||
|
||||
|
|
13
git/main.go
13
git/main.go
|
@ -6,19 +6,20 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/bdlm/log"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
libHTTP "github.com/genofire/golang-lib/http"
|
||||
xmpp "github.com/mattn/go-xmpp"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
"dev.sum7.eu/genofire/hook2xmpp/runtime"
|
||||
)
|
||||
|
||||
var eventHeader = []string{"X-GitHub-Event", "X-Gogs-Event"}
|
||||
var eventHeader = []string{"X-GitHub-Event", "X-Gogs-Event", "X-Gitlab-Event"}
|
||||
|
||||
const hookType = "git"
|
||||
|
||||
func init() {
|
||||
runtime.HookRegister[hookType] = func(client *xmpp.Client, hooks []runtime.Hook) func(w http.ResponseWriter, r *http.Request) {
|
||||
log.WithField("type", hookType).Info("loaded")
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
logger := log.WithField("type", hookType)
|
||||
|
||||
|
@ -31,7 +32,7 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
if event == "status" {
|
||||
if event == "" || event == "status" {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -45,13 +46,13 @@ func init() {
|
|||
return
|
||||
}
|
||||
logger = logger.WithFields(map[string]interface{}{
|
||||
"url": request.Repository.HTMLURL,
|
||||
"url": request.Repository.URL,
|
||||
"msg": request.String(event),
|
||||
})
|
||||
|
||||
ok := false
|
||||
for _, hook := range hooks {
|
||||
if request.Repository.HTMLURL != hook.URL {
|
||||
if request.Repository.URL != hook.URL {
|
||||
continue
|
||||
}
|
||||
logger.Infof("run hook")
|
||||
|
@ -60,7 +61,7 @@ func init() {
|
|||
}
|
||||
if !ok {
|
||||
logger.Warnf("no hook found")
|
||||
http.Error(w, fmt.Sprintf("no configuration for %s for url: %s", hookType, request.Repository.HTMLURL), http.StatusNotFound)
|
||||
http.Error(w, fmt.Sprintf("no configuration for %s for url: %s", hookType, request.Repository.URL), http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,9 +49,9 @@ var eventMsg = map[string]string{
|
|||
"gollum_edited": "Wiki: edited page",
|
||||
}
|
||||
|
||||
|
||||
type requestBody struct {
|
||||
Repository struct {
|
||||
URL string `mapstructure:"url"`
|
||||
HTMLURL string `mapstructure:"html_url"`
|
||||
FullName string `mapstructure:"full_name"`
|
||||
} `mapstructure:"repository"`
|
||||
|
|
|
@ -2,20 +2,19 @@ package circleci
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/bdlm/log"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
libHTTP "github.com/genofire/golang-lib/http"
|
||||
xmpp "github.com/mattn/go-xmpp"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
"dev.sum7.eu/genofire/hook2xmpp/runtime"
|
||||
)
|
||||
|
||||
const hookType = "grafana"
|
||||
|
||||
|
||||
type evalMatch struct {
|
||||
Tags map[string]string `mapstructure:"tags,omitempty"`
|
||||
Metric string `mapstructure:"metric"`
|
||||
|
@ -43,6 +42,7 @@ func (r requestBody) String() string {
|
|||
|
||||
func init() {
|
||||
runtime.HookRegister[hookType] = func(client *xmpp.Client, hooks []runtime.Hook) func(w http.ResponseWriter, r *http.Request) {
|
||||
log.WithField("type", hookType).Info("loaded")
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
logger := log.WithField("type", hookType)
|
||||
|
||||
|
|
5
main.go
5
main.go
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
_ "dev.sum7.eu/genofire/hook2xmpp/circleci"
|
||||
_ "dev.sum7.eu/genofire/hook2xmpp/git"
|
||||
_ "dev.sum7.eu/genofire/hook2xmpp/grafana"
|
||||
"dev.sum7.eu/genofire/hook2xmpp/runtime"
|
||||
)
|
||||
|
||||
|
@ -31,7 +32,9 @@ func main() {
|
|||
options := xmpp.Options{
|
||||
Host: config.XMPP.Host,
|
||||
User: config.XMPP.Username,
|
||||
Resource: config.XMPP.Resource,
|
||||
Password: config.XMPP.Password,
|
||||
StartTLS: config.XMPP.StartTLS,
|
||||
NoTLS: config.XMPP.NoTLS,
|
||||
Debug: config.XMPP.Debug,
|
||||
Session: config.XMPP.Session,
|
||||
|
@ -48,7 +51,7 @@ func main() {
|
|||
for hookType, getHandler := range runtime.HookRegister {
|
||||
hooks, ok := config.Hooks[hookType]
|
||||
if ok {
|
||||
http.HandleFunc(hookType, getHandler(client, hooks))
|
||||
http.HandleFunc("/"+hookType, getHandler(client, hooks))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,11 @@ type Config struct {
|
|||
XMPP struct {
|
||||
Host string `toml:"host"`
|
||||
Username string `toml:"username"`
|
||||
Resource string `toml:"resource"`
|
||||
Password string `toml:"password"`
|
||||
Debug bool `toml:"debug"`
|
||||
NoTLS bool `toml:"no_tls"`
|
||||
StartTLS bool `toml:"start_tls"`
|
||||
Session bool `toml:"session"`
|
||||
Status string `toml:"status"`
|
||||
StatusMessage string `toml:"status_message"`
|
||||
|
|
Loading…
Reference in New Issue