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

Commit 7b8bad3

Browse files
committed
Add delete hook
1 parent c7c050c commit 7b8bad3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

gitea/hook.go

Lines changed: 51 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,56 @@ 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+
func (p *DeletePayload) JSONPayload() ([]byte, error) {
243+
return json.MarshalIndent(p, "", " ")
244+
}
245+
246+
// ParseDeleteHook parses push event hook content.
247+
func ParseDeleteHook(raw []byte) (*DeletePayload, error) {
248+
hook := new(DeletePayload)
249+
if err := json.Unmarshal(raw, hook); err != nil {
250+
return nil, err
251+
}
252+
253+
switch {
254+
case hook.Repo == nil:
255+
return nil, ErrInvalidReceiveHook
256+
case len(hook.Ref) == 0:
257+
return nil, ErrInvalidReceiveHook
258+
}
259+
return hook, nil
260+
}
261+
211262
// __________ .__
212263
// \______ \__ __ _____| |__
213264
// | ___/ | \/ ___/ | \

0 commit comments

Comments
 (0)