Issue webhook payload (#38)

* Add Issue webhook payload

* Add copyright header

* Whoops, wrote license header in wrong file...

* Move fields of PR/Issue payload to BaseIssuePayload

* Fix license header

* remove BaseIssuePayload

* Add comment to IssuePayload.JSONPayload

* Fix comment mentioning IssuePayload

* Reorder structs

* Mimic GitHub webhooks

Since the Gitea webhooks currently mimic for a big part the way GitHub does webhook, issue comments HookIssueActions have been removed to be added again at a later stage and milestone_set and milestone_cleared have been changed to milestoned and demilestoned, respectively.

* Change also constant names
This commit is contained in:
Morgan Bazalgette 2017-02-13 12:50:09 +01:00 committed by Lunny Xiao
parent 014bf8c4f2
commit 87b8065c0d

View file

@ -1,4 +1,5 @@
// Copyright 2014 The Gogs Authors. All rights reserved.
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
@ -147,6 +148,7 @@ type PayloadCommit struct {
var (
_ Payloader = &CreatePayload{}
_ Payloader = &PushPayload{}
_ Payloader = &IssuePayload{}
_ Payloader = &PullRequestPayload{}
)
@ -277,8 +279,33 @@ const (
HookIssueLabelCleared HookIssueAction = "label_cleared"
// HookIssueSynchronized synchronized
HookIssueSynchronized HookIssueAction = "synchronized"
// HookIssueMilestoned is an issue action for when a milestone is set on an issue.
HookIssueMilestoned HookIssueAction = "milestoned"
// HookIssueDemilestoned is an issue action for when a milestone is cleared on an issue.
HookIssueDemilestoned HookIssueAction = "demilestoned"
)
// IssuePayload represents the payload information that is sent along with an issue event.
type IssuePayload struct {
Secret string `json:"secret"`
Action HookIssueAction `json:"action"`
Index int64 `json:"number"`
Changes *ChangesPayload `json:"changes,omitempty"`
Issue *Issue `json:"issue"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}
// SetSecret modifies the secret of the IssuePayload.
func (p *IssuePayload) SetSecret(secret string) {
p.Secret = secret
}
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
func (p *IssuePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
// ChangesFromPayload FIXME
type ChangesFromPayload struct {
From string `json:"from"`
@ -308,7 +335,7 @@ type PullRequestPayload struct {
Sender *User `json:"sender"`
}
// SetSecret FIXME
// SetSecret modifies the secret of the PullRequestPayload.
func (p *PullRequestPayload) SetSecret(secret string) {
p.Secret = secret
}