This commit is contained in:
Adam Majer 2024-08-24 18:37:08 +02:00
parent 87ab2e0af5
commit 8fafd623ac
2 changed files with 20 additions and 10 deletions

View File

@ -32,11 +32,11 @@ func connectToRabbitMQ() {
go ConnectToExchangeForPublish(host, username, password)
}
var id int
func dumpUnhandledData(reqType string, data []byte) {
id++
os.WriteFile("/tmp/unhandled-json-" + reqType + "-" + fmt.Sprint(id) + ".json", data, 0600);
os.WriteFile("/tmp/unhandled-json-"+reqType+"-"+fmt.Sprint(id)+".json", data, 0600)
}
func main() {
@ -132,18 +132,32 @@ func main() {
}
return
}
switch repoAction.Action {
case "created", "deleted":
break
default:
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
dumpUnhandledData(reqType, data)
}
}
org = repoAction.Organization
extraAction = repoAction.Action
default:
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
dumpUnhandledData(reqType, data)
}
}
// err = PublishMessage(repo.Owner.Username, reqType, data)
// err = PublishMessage(repo.Owner.Username, reqType, data)
// write to file for review
os.WriteFile("test_data."+fmt.Sprint(connectionId), data, 0644)
connectionId++
log.Println(id, org.Username, extraAction)
/*
err = PublishMessage(repo.Name, reqType, data)
err = PublishMessage(org.Name, reqType, extraAction, data)
if err != nil {
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
res.Header().Add("Content-Type", "plain/text")

View File

@ -25,7 +25,7 @@ type Message struct {
var messageQueue chan Message
func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) error {
func PublishActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) error {
if messageQueue == nil {
return fmt.Errorf("Queue not initialized")
}
@ -47,10 +47,6 @@ func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte)
}
}
if len(action) > 0 {
msg.Topic = msg.Topic + "." + action
}
select {
case messageQueue <- msg:
default:
@ -60,7 +56,7 @@ func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte)
}
func PublishMessage(giteaOrg, giteaWebhookType string, data []byte) error {
return PublicActionMessage(giteaOrg, giteaWebhookType, "", data)
return PublishActionMessage(giteaOrg, giteaWebhookType, "", data)
}
func ConnectToExchangeForPublish(host, username, password string) {