This commit is contained in:
Adam Majer 2024-08-24 22:03:30 +02:00
parent 6106b96a49
commit aadb57588c
2 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,20 @@
package common
type IssueDetail struct {
Id int
Number int
Html_url string
User *User
Title string
Body string
State string
}
type IssueWebhookEvent struct {
Action string
Issue *IssueDetail
Repository *Repository
Sender *User
}

View File

@ -94,6 +94,22 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
org = release.Repository.Owner
extraAction = release.Action
case "issues":
issue := common.IssueWebhookEvent{}
if err = json.Unmarshal(data, &issue); err != nil {
return
}
switch issue.Action {
case "opened", "closed", "reopened", "edited":
break
default:
err = fmt.Errorf("Unknown Issue webhook action type: %s", issue.Action)
return
}
org = issue.Repository.Owner
extraAction = issue.Action
default:
err = fmt.Errorf("Unknown webhook request type: %s", reqType)
}
@ -151,7 +167,7 @@ func main() {
org, extraAction, err := parseRequestJSON(reqType, data)
if err != nil {
res.WriteHeader(http.StatusBadRequest)
log.Printf("error parsing webhook %s JSON. err: %v", reqType, err)
log.Printf("error parsing webhook %s JSON. err: %v", reqType, err)
if DebugMode {
dumpUnhandledData(reqType, data)
}
@ -161,7 +177,9 @@ func main() {
// write to file for review
id++
os.WriteFile("test_data."+fmt.Sprint(id), data, 0644)
log.Println(id, org.Username, reqType, extraAction)
if org != nil {
log.Println(id, org.Username, reqType, extraAction)
}
/*
err = PublishMessage(org.Name, reqType, extraAction, data)