gitee.com/openeuler/go-gitee@v0.0.0-20220530104019-3af895bc380c/gitee/hook_events.go (about) 1 package gitee 2 3 import ( 4 "encoding/json" 5 "time" 6 ) 7 8 // HookEvent represents a Gitee hook event. 9 type HookEvent struct { 10 Type *string `json:"type,omitempty"` 11 RawPayload *json.RawMessage `json:"payload,omitempty"` 12 Actor *User `json:"actor,omitempty"` 13 CreatedAt *time.Time `json:"created_at,omitempty"` 14 ID *string `json:"id,omitempty"` 15 } 16 17 // ParsePayload parses the event payload. For recognized event types, 18 // a value of the corresponding struct type will be returned. 19 func (e *HookEvent) ParsePayload() (payload interface{}, err error) { 20 switch *e.Type { 21 case "NoteEvent": 22 payload = &NoteEvent{} 23 case "PushEvent": 24 payload = &PushEvent{} 25 case "IssueEvent": 26 payload = &IssueEvent{} 27 case "PullRequestEvent": 28 payload = &PullRequestEvent{} 29 case "TagPushEvent": 30 payload = &TagPushEvent{} 31 } 32 33 err = json.Unmarshal(*e.RawPayload, &payload) 34 return payload, err 35 }