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

Commit 7fa627f

Browse files
authored
add more webhook types (#106)
1 parent 40e36e1 commit 7fa627f

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

gitea/hook.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ type PayloadCommitVerification struct {
172172

173173
var (
174174
_ Payloader = &CreatePayload{}
175+
_ Payloader = &DeletePayload{}
176+
_ Payloader = &ForkPayload{}
175177
_ Payloader = &PushPayload{}
176178
_ Payloader = &IssuePayload{}
179+
_ Payloader = &IssueCommentPayload{}
177180
_ Payloader = &PullRequestPayload{}
181+
_ Payloader = &RepositoryPayload{}
182+
_ Payloader = &ReleasePayload{}
178183
)
179184

180185
// _________ __
@@ -224,6 +229,123 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
224229
return hook, nil
225230
}
226231

232+
// ________ .__ __
233+
// \______ \ ____ | | _____/ |_ ____
234+
// | | \_/ __ \| | _/ __ \ __\/ __ \
235+
// | ` \ ___/| |_\ ___/| | \ ___/
236+
// /_______ /\___ >____/\___ >__| \___ >
237+
// \/ \/ \/ \/
238+
239+
// PusherType define the type to push
240+
type PusherType string
241+
242+
// describe all the PusherTypes
243+
const (
244+
PusherTypeUser PusherType = "user"
245+
)
246+
247+
// DeletePayload represents delete payload
248+
type DeletePayload struct {
249+
Ref string `json:"ref"`
250+
RefType string `json:"ref_type"`
251+
PusherType PusherType `json:"pusher_type"`
252+
Repo *Repository `json:"repository"`
253+
Sender *User `json:"sender"`
254+
}
255+
256+
// SetSecret implements Payload
257+
func (p *DeletePayload) SetSecret(secret string) {
258+
}
259+
260+
// JSONPayload implements Payload
261+
func (p *DeletePayload) JSONPayload() ([]byte, error) {
262+
return json.MarshalIndent(p, "", " ")
263+
}
264+
265+
// ___________ __
266+
// \_ _____/__________| | __
267+
// | __)/ _ \_ __ \ |/ /
268+
// | \( <_> ) | \/ <
269+
// \___ / \____/|__| |__|_ \
270+
// \/ \/
271+
272+
// ForkPayload represents fork payload
273+
type ForkPayload struct {
274+
Forkee *Repository `json:"forkee"`
275+
Repo *Repository `json:"repository"`
276+
Sender *User `json:"sender"`
277+
}
278+
279+
// SetSecret implements Payload
280+
func (p *ForkPayload) SetSecret(secret string) {
281+
}
282+
283+
// JSONPayload implements Payload
284+
func (p *ForkPayload) JSONPayload() ([]byte, error) {
285+
return json.MarshalIndent(p, "", " ")
286+
}
287+
288+
// HookIssueCommentAction defines hook issue comment action
289+
type HookIssueCommentAction string
290+
291+
// all issue comment actions
292+
const (
293+
HookIssueCommentCreated HookIssueCommentAction = "created"
294+
HookIssueCommentEdited HookIssueCommentAction = "edited"
295+
HookIssueCommentDeleted HookIssueCommentAction = "deleted"
296+
)
297+
298+
// IssueCommentPayload represents a payload information of issue comment event.
299+
type IssueCommentPayload struct {
300+
Action HookIssueCommentAction `json:"action"`
301+
Issue *Issue `json:"issue"`
302+
Comment *Comment `json:"comment"`
303+
Changes *ChangesPayload `json:"changes,omitempty"`
304+
Repository *Repository `json:"repository"`
305+
Sender *User `json:"sender"`
306+
}
307+
308+
// SetSecret implements Payload
309+
func (p *IssueCommentPayload) SetSecret(secret string) {
310+
}
311+
312+
// JSONPayload implements Payload
313+
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
314+
return json.MarshalIndent(p, "", " ")
315+
}
316+
317+
// __________ .__
318+
// \______ \ ____ | | ____ _____ ______ ____
319+
// | _// __ \| | _/ __ \\__ \ / ___// __ \
320+
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
321+
// |____|_ /\___ >____/\___ >____ /____ >\___ >
322+
// \/ \/ \/ \/ \/ \/
323+
324+
// HookReleaseAction defines hook release action type
325+
type HookReleaseAction string
326+
327+
// all release actions
328+
const (
329+
HookReleasePublished HookReleaseAction = "published"
330+
)
331+
332+
// ReleasePayload represents a payload information of release event.
333+
type ReleasePayload struct {
334+
Action HookReleaseAction `json:"action"`
335+
Release *Release `json:"release"`
336+
Repository *Repository `json:"repository"`
337+
Sender *User `json:"sender"`
338+
}
339+
340+
// SetSecret implements Payload
341+
func (p *ReleasePayload) SetSecret(secret string) {
342+
}
343+
344+
// JSONPayload implements Payload
345+
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
346+
return json.MarshalIndent(p, "", " ")
347+
}
348+
227349
// __________ .__
228350
// \______ \__ __ _____| |__
229351
// | ___/ | \/ ___/ | \

0 commit comments

Comments
 (0)