.
This commit is contained in:
parent
8fafd623ac
commit
6cb2860319
20
bots-common/request_release.go
Normal file
20
bots-common/request_release.go
Normal file
@ -0,0 +1,20 @@
|
||||
package common
|
||||
|
||||
type ReleaseWebhookDetail struct {
|
||||
Tag_name string
|
||||
Name string
|
||||
Body string
|
||||
Draft bool
|
||||
Author User
|
||||
Created_at string
|
||||
Published_at string
|
||||
}
|
||||
|
||||
type ReleaseWebhookEvent struct {
|
||||
Action string
|
||||
|
||||
Release ReleaseWebhookDetail
|
||||
Repository Repository
|
||||
Sender User
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ func dumpUnhandledData(reqType string, data []byte) {
|
||||
id++
|
||||
os.WriteFile("/tmp/unhandled-json-"+reqType+"-"+fmt.Sprint(id)+".json", data, 0600)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var listenAddr string
|
||||
|
||||
@ -48,8 +47,6 @@ func main() {
|
||||
|
||||
connectToRabbitMQ()
|
||||
|
||||
connectionId := 1
|
||||
|
||||
http.HandleFunc("POST /test", func(res http.ResponseWriter, req *http.Request) {
|
||||
if len(req.Header.Get("Content-Type")) == 0 ||
|
||||
req.Header["Content-Type"][0] != "application/json" ||
|
||||
@ -143,6 +140,28 @@ func main() {
|
||||
}
|
||||
org = repoAction.Organization
|
||||
extraAction = repoAction.Action
|
||||
case "release":
|
||||
release := common.ReleaseWebhookEvent{}
|
||||
if err = json.Unmarshal(data, &release); err != nil {
|
||||
res.WriteHeader(http.StatusBadRequest)
|
||||
if DebugMode {
|
||||
dumpUnhandledData(reqType, data)
|
||||
}
|
||||
return
|
||||
}
|
||||
switch release.Action {
|
||||
case "published", "updated", "deleted":
|
||||
break
|
||||
default:
|
||||
res.WriteHeader(http.StatusBadRequest)
|
||||
if DebugMode {
|
||||
dumpUnhandledData(reqType, data)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
org = *release.Repository.Owner
|
||||
extraAction = release.Action
|
||||
default:
|
||||
res.WriteHeader(http.StatusBadRequest)
|
||||
if DebugMode {
|
||||
@ -152,8 +171,8 @@ func main() {
|
||||
|
||||
// err = PublishMessage(repo.Owner.Username, reqType, data)
|
||||
// write to file for review
|
||||
os.WriteFile("test_data."+fmt.Sprint(connectionId), data, 0644)
|
||||
connectionId++
|
||||
id++
|
||||
os.WriteFile("test_data."+fmt.Sprint(id), data, 0644)
|
||||
log.Println(id, org.Username, extraAction)
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user