.
This commit is contained in:
parent
cde327406c
commit
4aa44dbf83
@ -5,6 +5,6 @@ type CreateWebhookEvent struct {
|
|||||||
Ref string // name of tag/branch
|
Ref string // name of tag/branch
|
||||||
Ref_type string // tag, branch
|
Ref_type string // tag, branch
|
||||||
|
|
||||||
Repository
|
Repository *Repository
|
||||||
Sender User
|
Sender *User
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ go 1.22.3
|
|||||||
replace src.opensuse.org/autogits/common => ../bots-common
|
replace src.opensuse.org/autogits/common => ../bots-common
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
|
||||||
github.com/rabbitmq/amqp091-go v1.10.0
|
github.com/rabbitmq/amqp091-go v1.10.0
|
||||||
src.opensuse.org/autogits/common v0.0.0-00010101000000-000000000000
|
src.opensuse.org/autogits/common v0.0.0-00010101000000-000000000000
|
||||||
)
|
)
|
||||||
|
@ -40,8 +40,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
|
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
|
||||||
|
@ -372,7 +372,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PublishActionMessage(org.Username, reqType, extraAction, data)
|
err = PublishMessage(org.Username, reqType, extraAction, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
|
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
|
||||||
res.Header().Add("Content-Type", "plain/text")
|
res.Header().Add("Content-Type", "plain/text")
|
||||||
@ -386,51 +386,5 @@ func main() {
|
|||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("POST /rabbitmq-forwarder/{Org}", func(res http.ResponseWriter, req *http.Request) {
|
|
||||||
if len(req.Header.Get("Content-Type")) == 0 ||
|
|
||||||
req.Header["Content-Type"][0] != "application/json" ||
|
|
||||||
req.Method != "POST" {
|
|
||||||
|
|
||||||
res.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
hdr := req.Header[common.GiteaRequestHeader]
|
|
||||||
if len(hdr) != 1 {
|
|
||||||
res.WriteHeader(http.StatusInternalServerError)
|
|
||||||
log.Printf("Multiple Gitea headers received. %#v\n", hdr)
|
|
||||||
if DebugMode {
|
|
||||||
log.Println(req.Header)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
reqType := hdr[0]
|
|
||||||
data, err := io.ReadAll(req.Body)
|
|
||||||
if err != nil {
|
|
||||||
errorStr := fmt.Sprintf("error reading hook info: %v", err)
|
|
||||||
res.Header().Add("Content-Type", "plain/text")
|
|
||||||
res.Write([]byte(errorStr))
|
|
||||||
res.WriteHeader(http.StatusBadRequest)
|
|
||||||
|
|
||||||
if DebugMode {
|
|
||||||
log.Printf(errorStr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = PublishMessage(req.PathValue("Org"), reqType, data)
|
|
||||||
if err != nil {
|
|
||||||
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
|
|
||||||
res.Header().Add("Content-Type", "plain/text")
|
|
||||||
res.Write([]byte(errorStr))
|
|
||||||
res.WriteHeader(http.StatusBadRequest)
|
|
||||||
|
|
||||||
if DebugMode {
|
|
||||||
log.Println(errorStr)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res.WriteHeader(http.StatusOK)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(listenAddr, nil))
|
log.Fatal(http.ListenAndServe(listenAddr, nil))
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ type Message struct {
|
|||||||
|
|
||||||
var messageQueue chan Message
|
var messageQueue chan Message
|
||||||
|
|
||||||
func PublishActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) error {
|
func PublishMessage(giteaOrg, giteaWebhookType, action string, data []byte) error {
|
||||||
if messageQueue == nil {
|
if messageQueue == nil {
|
||||||
return fmt.Errorf("Queue not initialized")
|
return fmt.Errorf("Queue not initialized")
|
||||||
}
|
}
|
||||||
@ -55,10 +55,6 @@ func PublishActionMessage(giteaOrg, giteaWebhookType, action string, data []byte
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishMessage(giteaOrg, giteaWebhookType string, data []byte) error {
|
|
||||||
return PublishActionMessage(giteaOrg, giteaWebhookType, "", data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ConnectToExchangeForPublish(host, username, password string) {
|
func ConnectToExchangeForPublish(host, username, password string) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user