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

Commit 87b8065

Browse files
thehowllunny
authored andcommitted
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
1 parent 014bf8c commit 87b8065

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

gitea/hook.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2014 The Gogs Authors. All rights reserved.
2+
// Copyright 2017 The Gitea Authors. All rights reserved.
23
// Use of this source code is governed by a MIT-style
34
// license that can be found in the LICENSE file.
45

@@ -147,6 +148,7 @@ type PayloadCommit struct {
147148
var (
148149
_ Payloader = &CreatePayload{}
149150
_ Payloader = &PushPayload{}
151+
_ Payloader = &IssuePayload{}
150152
_ Payloader = &PullRequestPayload{}
151153
)
152154

@@ -277,8 +279,33 @@ const (
277279
HookIssueLabelCleared HookIssueAction = "label_cleared"
278280
// HookIssueSynchronized synchronized
279281
HookIssueSynchronized HookIssueAction = "synchronized"
282+
// HookIssueMilestoned is an issue action for when a milestone is set on an issue.
283+
HookIssueMilestoned HookIssueAction = "milestoned"
284+
// HookIssueDemilestoned is an issue action for when a milestone is cleared on an issue.
285+
HookIssueDemilestoned HookIssueAction = "demilestoned"
280286
)
281287

288+
// IssuePayload represents the payload information that is sent along with an issue event.
289+
type IssuePayload struct {
290+
Secret string `json:"secret"`
291+
Action HookIssueAction `json:"action"`
292+
Index int64 `json:"number"`
293+
Changes *ChangesPayload `json:"changes,omitempty"`
294+
Issue *Issue `json:"issue"`
295+
Repository *Repository `json:"repository"`
296+
Sender *User `json:"sender"`
297+
}
298+
299+
// SetSecret modifies the secret of the IssuePayload.
300+
func (p *IssuePayload) SetSecret(secret string) {
301+
p.Secret = secret
302+
}
303+
304+
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
305+
func (p *IssuePayload) JSONPayload() ([]byte, error) {
306+
return json.MarshalIndent(p, "", " ")
307+
}
308+
282309
// ChangesFromPayload FIXME
283310
type ChangesFromPayload struct {
284311
From string `json:"from"`
@@ -308,7 +335,7 @@ type PullRequestPayload struct {
308335
Sender *User `json:"sender"`
309336
}
310337

311-
// SetSecret FIXME
338+
// SetSecret modifies the secret of the PullRequestPayload.
312339
func (p *PullRequestPayload) SetSecret(secret string) {
313340
p.Secret = secret
314341
}

0 commit comments

Comments
 (0)