.
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++
|
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() {
|
func main() {
|
||||||
var listenAddr string
|
var listenAddr string
|
||||||
|
|
||||||
@ -48,8 +47,6 @@ func main() {
|
|||||||
|
|
||||||
connectToRabbitMQ()
|
connectToRabbitMQ()
|
||||||
|
|
||||||
connectionId := 1
|
|
||||||
|
|
||||||
http.HandleFunc("POST /test", func(res http.ResponseWriter, req *http.Request) {
|
http.HandleFunc("POST /test", func(res http.ResponseWriter, req *http.Request) {
|
||||||
if len(req.Header.Get("Content-Type")) == 0 ||
|
if len(req.Header.Get("Content-Type")) == 0 ||
|
||||||
req.Header["Content-Type"][0] != "application/json" ||
|
req.Header["Content-Type"][0] != "application/json" ||
|
||||||
@ -143,6 +140,28 @@ func main() {
|
|||||||
}
|
}
|
||||||
org = repoAction.Organization
|
org = repoAction.Organization
|
||||||
extraAction = repoAction.Action
|
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:
|
default:
|
||||||
res.WriteHeader(http.StatusBadRequest)
|
res.WriteHeader(http.StatusBadRequest)
|
||||||
if DebugMode {
|
if DebugMode {
|
||||||
@ -152,8 +171,8 @@ func main() {
|
|||||||
|
|
||||||
// err = PublishMessage(repo.Owner.Username, reqType, data)
|
// err = PublishMessage(repo.Owner.Username, reqType, data)
|
||||||
// write to file for review
|
// write to file for review
|
||||||
os.WriteFile("test_data."+fmt.Sprint(connectionId), data, 0644)
|
id++
|
||||||
connectionId++
|
os.WriteFile("test_data."+fmt.Sprint(id), data, 0644)
|
||||||
log.Println(id, org.Username, extraAction)
|
log.Println(id, org.Username, extraAction)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user