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