Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit a79c910

Browse files
committed
Add delete hook
1 parent c7c050c commit a79c910

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

gitea/hook.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ type PayloadCommitVerification struct {
156156

157157
var (
158158
_ Payloader = &CreatePayload{}
159+
_ Payloader = &DeletePayload{}
159160
_ Payloader = &PushPayload{}
160161
_ Payloader = &IssuePayload{}
161162
_ Payloader = &PullRequestPayload{}
@@ -208,6 +209,57 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
208209
return hook, nil
209210
}
210211

212+
// ________ .__ __
213+
// \______ \ ____ | | _____/ |_ ____
214+
// | | \_/ __ \| | _/ __ \ __\/ __ \
215+
// | ` \ ___/| |_\ ___/| | \ ___/
216+
// /_______ /\___ >____/\___ >__| \___ >
217+
// \/ \/ \/ \/
218+
219+
// PusherType represents the pusher type
220+
type PusherType string
221+
222+
const (
223+
// PusherTypeUser represents the user pusher type
224+
PusherTypeUser PusherType = "user"
225+
)
226+
227+
// DeletePayload represents a payload information of a delete event.
228+
type DeletePayload struct {
229+
Secret string `json:"secret"`
230+
Ref string `json:"ref"`
231+
RefType string `json:"ref_type"`
232+
PusherType PusherType `json:"pusher_type"`
233+
Repo *Repository `json:"repository"`
234+
Sender *User `json:"sender"`
235+
}
236+
237+
// SetSecret FIXME
238+
func (p *DeletePayload) SetSecret(secret string) {
239+
p.Secret = secret
240+
}
241+
242+
// JSONPayload return payload information
243+
func (p *DeletePayload) JSONPayload() ([]byte, error) {
244+
return json.MarshalIndent(p, "", " ")
245+
}
246+
247+
// ParseDeleteHook parses push event hook content.
248+
func ParseDeleteHook(raw []byte) (*DeletePayload, error) {
249+
hook := new(DeletePayload)
250+
if err := json.Unmarshal(raw, hook); err != nil {
251+
return nil, err
252+
}
253+
254+
switch {
255+
case hook.Repo == nil:
256+
return nil, ErrInvalidReceiveHook
257+
case len(hook.Ref) == 0:
258+
return nil, ErrInvalidReceiveHook
259+
}
260+
return hook, nil
261+
}
262+
211263
// __________ .__
212264
// \______ \__ __ _____| |__
213265
// | ___/ | \/ ___/ | \

0 commit comments

Comments
 (0)