From d16bde59927f7720b3f30479e4998344490a8a68 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Fri, 10 Feb 2017 23:32:59 +0100 Subject: [PATCH 01/11] Add Issue webhook payload --- gitea/hook.go | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index 4e04275..1b2501c 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -147,6 +147,7 @@ type PayloadCommit struct { var ( _ Payloader = &CreatePayload{} _ Payloader = &PushPayload{} + _ Payloader = &IssuePayload{} _ Payloader = &PullRequestPayload{} ) @@ -277,8 +278,39 @@ const ( HookIssueLabelCleared HookIssueAction = "label_cleared" // HookIssueSynchronized synchronized HookIssueSynchronized HookIssueAction = "synchronized" + // HookIssueMilestoneSet is an issue action for when a milestone is set on an issue. + HookIssueMilestoneSet HookIssueAction = "milestone_set" + // HookIssueMilestoneCleared is an issue action for when a milestone is cleared on an issue. + HookIssueMilestoneCleared HookIssueAction = "milestone_cleared" + // HookIssueCommentAdded is an issue action sent when a comment is added to an issue. + HookIssueCommentAdded HookIssueAction = "comment_added" + // HookIssueCommentDeleted is an issue action sent when a comment on an issue is deleted. + HookIssueCommentDeleted HookIssueAction = "comment_deleted" + // HookIssueCommentEdited is an issue action sent when a comment on an issue is edited. + HookIssueCommentEdited HookIssueAction = "comment_edited" ) +// 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 FIXME +func (p *IssuePayload) SetSecret(secret string) { + p.Secret = secret +} + +// JSONPayload FIXME +func (p *IssuePayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + // ChangesFromPayload FIXME type ChangesFromPayload struct { From string `json:"from"` @@ -286,8 +318,9 @@ type ChangesFromPayload struct { // ChangesPayload FIXME type ChangesPayload struct { - Title *ChangesFromPayload `json:"title,omitempty"` - Body *ChangesFromPayload `json:"body,omitempty"` + Title *ChangesFromPayload `json:"title,omitempty"` + Body *ChangesFromPayload `json:"body,omitempty"` + Comment *Comment `json:"comment,omitempty"` } // __________ .__ .__ __________ __ From df85a6b9080f6d94c70c8d5bcb3588bf12dd7dec Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 09:44:49 +0100 Subject: [PATCH 02/11] Add copyright header --- gitea/issue.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gitea/issue.go b/gitea/issue.go index adb283a..cbdf344 100644 --- a/gitea/issue.go +++ b/gitea/issue.go @@ -2,6 +2,10 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. +// 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. + package gitea import ( From 29dbed0cf0d38197f61f41dc6b38624952ef71a7 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 09:58:22 +0100 Subject: [PATCH 03/11] Whoops, wrote license header in wrong file... --- gitea/hook.go | 4 ++++ gitea/issue.go | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index 1b2501c..7fc7f21 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -2,6 +2,10 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. +// 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. + package gitea import ( diff --git a/gitea/issue.go b/gitea/issue.go index cbdf344..adb283a 100644 --- a/gitea/issue.go +++ b/gitea/issue.go @@ -2,10 +2,6 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -// 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. - package gitea import ( From 27c69b7f1439a345352039e23553b26b8e08b333 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 12:37:51 +0100 Subject: [PATCH 04/11] Move fields of PR/Issue payload to BaseIssuePayload --- gitea/hook.go | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index 7fc7f21..fa3ff25 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -260,6 +260,22 @@ func (p *PushPayload) Branch() string { // |___/____ >____ >____/ \___ > // \/ \/ \/ +// BaseIssuePayload is the information about a pull request or an issue that +// is included as an embedded struct in both pull requests and issues. +type BaseIssuePayload struct { + Secret string `json:"secret"` + Action HookIssueAction `json:"action"` + Index int64 `json:"number"` + Changes *ChangesPayload `json:"changes,omitempty"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +// SetSecret modifies the secret of the BaseIssuePayload. +func (p *BaseIssuePayload) SetSecret(secret string) { + p.Secret = secret +} + // HookIssueAction FIXME type HookIssueAction string @@ -296,18 +312,8 @@ const ( // 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 FIXME -func (p *IssuePayload) SetSecret(secret string) { - p.Secret = secret + BaseIssuePayload + Issue *Issue `json:"issue"` } // JSONPayload FIXME @@ -336,18 +342,8 @@ type ChangesPayload struct { // PullRequestPayload represents a payload information of pull request event. type PullRequestPayload struct { - Secret string `json:"secret"` - Action HookIssueAction `json:"action"` - Index int64 `json:"number"` - Changes *ChangesPayload `json:"changes,omitempty"` - PullRequest *PullRequest `json:"pull_request"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -// SetSecret FIXME -func (p *PullRequestPayload) SetSecret(secret string) { - p.Secret = secret + BaseIssuePayload + PullRequest *PullRequest `json:"pull_request"` } // JSONPayload FIXME From 995332fa24c657abc7d9cc6d3197cf9a37642870 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 13:15:47 +0100 Subject: [PATCH 05/11] Fix license header --- gitea/hook.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index fa3ff25..15d6cdc 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -1,7 +1,4 @@ // Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - // 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. From ddf61963d366ab03bb7d41492e322a7aa809444b Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 14:47:25 +0100 Subject: [PATCH 06/11] remove BaseIssuePayload --- gitea/hook.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index 15d6cdc..4c1bd80 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -257,22 +257,6 @@ func (p *PushPayload) Branch() string { // |___/____ >____ >____/ \___ > // \/ \/ \/ -// BaseIssuePayload is the information about a pull request or an issue that -// is included as an embedded struct in both pull requests and issues. -type BaseIssuePayload struct { - Secret string `json:"secret"` - Action HookIssueAction `json:"action"` - Index int64 `json:"number"` - Changes *ChangesPayload `json:"changes,omitempty"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -// SetSecret modifies the secret of the BaseIssuePayload. -func (p *BaseIssuePayload) SetSecret(secret string) { - p.Secret = secret -} - // HookIssueAction FIXME type HookIssueAction string @@ -309,8 +293,18 @@ const ( // IssuePayload represents the payload information that is sent along with an issue event. type IssuePayload struct { - BaseIssuePayload - Issue *Issue `json:"issue"` + Secret string `json:"secret"` + Action HookIssueAction `json:"action"` + Index int64 `json:"number"` + Changes *ChangesPayload `json:"changes,omitempty"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` + Issue *Issue `json:"issue"` +} + +// SetSecret modifies the secret of the IssuePayload. +func (p *IssuePayload) SetSecret(secret string) { + p.Secret = secret } // JSONPayload FIXME @@ -339,8 +333,18 @@ type ChangesPayload struct { // PullRequestPayload represents a payload information of pull request event. type PullRequestPayload struct { - BaseIssuePayload - PullRequest *PullRequest `json:"pull_request"` + Secret string `json:"secret"` + Action HookIssueAction `json:"action"` + Index int64 `json:"number"` + Changes *ChangesPayload `json:"changes,omitempty"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` + PullRequest *PullRequest `json:"pull_request"` +} + +// SetSecret modifies the secret of the IssuePayload. +func (p *PullRequestPayload) SetSecret(secret string) { + p.Secret = secret } // JSONPayload FIXME From 381ac3f497be45e8f74ac5c4627f74698efbc2c7 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 14:51:35 +0100 Subject: [PATCH 07/11] Add comment to IssuePayload.JSONPayload --- gitea/hook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/hook.go b/gitea/hook.go index 4c1bd80..8c11e31 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -307,7 +307,7 @@ func (p *IssuePayload) SetSecret(secret string) { p.Secret = secret } -// JSONPayload FIXME +// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces. func (p *IssuePayload) JSONPayload() ([]byte, error) { return json.MarshalIndent(p, "", " ") } From 7bc5c943dad1354f0ababd8768274543def79853 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 14:52:32 +0100 Subject: [PATCH 08/11] Fix comment mentioning IssuePayload --- gitea/hook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/hook.go b/gitea/hook.go index 8c11e31..eea31fd 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -342,7 +342,7 @@ type PullRequestPayload struct { PullRequest *PullRequest `json:"pull_request"` } -// SetSecret modifies the secret of the IssuePayload. +// SetSecret modifies the secret of the PullRequestPayload. func (p *PullRequestPayload) SetSecret(secret string) { p.Secret = secret } From c937e382a4ec4c4d43a64ee278a965a59a796d4e Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 14:52:55 +0100 Subject: [PATCH 09/11] Reorder structs --- gitea/hook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index eea31fd..979099b 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -297,9 +297,9 @@ type IssuePayload struct { 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"` - Issue *Issue `json:"issue"` } // SetSecret modifies the secret of the IssuePayload. @@ -337,9 +337,9 @@ type PullRequestPayload struct { Action HookIssueAction `json:"action"` Index int64 `json:"number"` Changes *ChangesPayload `json:"changes,omitempty"` + PullRequest *PullRequest `json:"pull_request"` Repository *Repository `json:"repository"` Sender *User `json:"sender"` - PullRequest *PullRequest `json:"pull_request"` } // SetSecret modifies the secret of the PullRequestPayload. From 36a8ef536e84063df03876a2b1681123c3c0f193 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 18:16:47 +0100 Subject: [PATCH 10/11] 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. --- gitea/hook.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index 979099b..6dd646e 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -280,15 +280,9 @@ const ( // HookIssueSynchronized synchronized HookIssueSynchronized HookIssueAction = "synchronized" // HookIssueMilestoneSet is an issue action for when a milestone is set on an issue. - HookIssueMilestoneSet HookIssueAction = "milestone_set" + HookIssueMilestoneSet HookIssueAction = "milestoned" // HookIssueMilestoneCleared is an issue action for when a milestone is cleared on an issue. - HookIssueMilestoneCleared HookIssueAction = "milestone_cleared" - // HookIssueCommentAdded is an issue action sent when a comment is added to an issue. - HookIssueCommentAdded HookIssueAction = "comment_added" - // HookIssueCommentDeleted is an issue action sent when a comment on an issue is deleted. - HookIssueCommentDeleted HookIssueAction = "comment_deleted" - // HookIssueCommentEdited is an issue action sent when a comment on an issue is edited. - HookIssueCommentEdited HookIssueAction = "comment_edited" + HookIssueMilestoneCleared HookIssueAction = "demilestoned" ) // IssuePayload represents the payload information that is sent along with an issue event. @@ -319,9 +313,8 @@ type ChangesFromPayload struct { // ChangesPayload FIXME type ChangesPayload struct { - Title *ChangesFromPayload `json:"title,omitempty"` - Body *ChangesFromPayload `json:"body,omitempty"` - Comment *Comment `json:"comment,omitempty"` + Title *ChangesFromPayload `json:"title,omitempty"` + Body *ChangesFromPayload `json:"body,omitempty"` } // __________ .__ .__ __________ __ From 1b922b106bd83f27411a8419a25b7e964bfdffd4 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Sat, 11 Feb 2017 18:23:44 +0100 Subject: [PATCH 11/11] Change also constant names --- gitea/hook.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gitea/hook.go b/gitea/hook.go index 6dd646e..c2f88f4 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -279,10 +279,10 @@ const ( HookIssueLabelCleared HookIssueAction = "label_cleared" // HookIssueSynchronized synchronized HookIssueSynchronized HookIssueAction = "synchronized" - // HookIssueMilestoneSet is an issue action for when a milestone is set on an issue. - HookIssueMilestoneSet HookIssueAction = "milestoned" - // HookIssueMilestoneCleared is an issue action for when a milestone is cleared on an issue. - HookIssueMilestoneCleared HookIssueAction = "demilestoned" + // 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.