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

Add delete hook #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions gitea/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type PayloadCommitVerification struct {

var (
_ Payloader = &CreatePayload{}
_ Payloader = &DeletePayload{}
_ Payloader = &PushPayload{}
_ Payloader = &IssuePayload{}
_ Payloader = &PullRequestPayload{}
Expand Down Expand Up @@ -208,6 +209,57 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
return hook, nil
}

// ________ .__ __
// \______ \ ____ | | _____/ |_ ____
// | | \_/ __ \| | _/ __ \ __\/ __ \
// | ` \ ___/| |_\ ___/| | \ ___/
// /_______ /\___ >____/\___ >__| \___ >
// \/ \/ \/ \/

// PusherType represents the pusher type
type PusherType string

const (
// PusherTypeUser represents the user pusher type
PusherTypeUser PusherType = "user"
)

// DeletePayload represents a payload information of a delete event.
type DeletePayload struct {
Secret string `json:"secret"`
Ref string `json:"ref"`
RefType string `json:"ref_type"`
PusherType PusherType `json:"pusher_type"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}

// SetSecret FIXME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetSecret of DeleteWebhook payload ? 😉

func (p *DeletePayload) SetSecret(secret string) {
p.Secret = secret
}

// JSONPayload return payload information
func (p *DeletePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}

// ParseDeleteHook parses push event hook content.
func ParseDeleteHook(raw []byte) (*DeletePayload, error) {
hook := new(DeletePayload)
if err := json.Unmarshal(raw, hook); err != nil {
return nil, err
}

switch {
case hook.Repo == nil:
return nil, ErrInvalidReceiveHook
case len(hook.Ref) == 0:
return nil, ErrInvalidReceiveHook
}
return hook, nil
}

// __________ .__
// \______ \__ __ _____| |__
// | ___/ | \/ ___/ | \
Expand Down