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

Commit 8742a5b

Browse files
committed
Add delete hook
1 parent c7c050c commit 8742a5b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

gitea/hook.go

Lines changed: 48 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,53 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
208209
return hook, nil
209210
}
210211

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

0 commit comments

Comments
 (0)