This commit is contained in:
Adam Majer 2024-08-24 17:20:46 +02:00
parent 3a869126e7
commit 1db814b5d3
3 changed files with 31 additions and 3 deletions

View File

@ -1,6 +1,6 @@
package common
type CreateWebhook struct {
type CreateWebhookEvent struct {
Sha string
Ref string // name of tag/branch
Ref_type string // tag, branch

View File

@ -0,0 +1,7 @@
package common
type ForkWebhookEvent struct {
Forkee Repository
Repository
Sender User
}

View File

@ -91,14 +91,35 @@ func main() {
// repo := common.Repository{}
switch reqType {
case "create", "delete":
create := common.CreateWebhook{}
create := common.CreateWebhookEvent{}
if err = json.Unmarshal(data, &create); err != nil {
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
dumpUnhandledData(reqType, data)
}
return
}
// repo = create.Repository
case "fork":
fork := common.ForkWebhookEvent{}
if err = json.Unmarshal(data, &fork); err != nil {
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
dumpUnhandledData(reqType, data)
}
return
}
// repo = fork.Forkee
case "push":
push := common.PushRequest{}
if err = json.Unmarshal(data, &push); err != nil {
res.WriteHeader(http.StatusBadRequest)
if DebugMode {
dumpUnhandledData(reqType, data)
}
return
}
// repo = push.Repository
}
// err = PublishMessage(repo.Owner.Username, reqType, data)
@ -107,7 +128,7 @@ func main() {
connectionId++
/*
err = PublishMessage(reqType, req.PathValue("Org"), data)
err = PublishMessage(repo.Name, reqType, data)
if err != nil {
errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err)
res.Header().Add("Content-Type", "plain/text")