Skip to content

Commit 89295fe

Browse files
committed
Split hook
1 parent ee6a977 commit 89295fe

File tree

9 files changed

+499
-488
lines changed

9 files changed

+499
-488
lines changed

modules/structs/hook.go

Lines changed: 0 additions & 432 deletions
Large diffs are not rendered by default.

modules/structs/hook_issue.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package structs
2+
3+
import "code.gitea.io/gitea/modules/json"
4+
5+
var (
6+
_ Payloader = &IssuePayload{}
7+
_ Payloader = &IssueCommentPayload{}
8+
)
9+
10+
// .___
11+
// | | ______ ________ __ ____
12+
// | |/ ___// ___/ | \_/ __ \
13+
// | |\___ \ \___ \| | /\ ___/
14+
// |___/____ >____ >____/ \___ >
15+
// \/ \/ \/
16+
17+
// HookIssueAction FIXME
18+
type HookIssueAction string
19+
20+
const (
21+
// HookIssueOpened opened
22+
HookIssueOpened HookIssueAction = "opened"
23+
// HookIssueClosed closed
24+
HookIssueClosed HookIssueAction = "closed"
25+
// HookIssueReOpened reopened
26+
HookIssueReOpened HookIssueAction = "reopened"
27+
// HookIssueEdited edited
28+
HookIssueEdited HookIssueAction = "edited"
29+
// HookIssueAssigned assigned
30+
HookIssueAssigned HookIssueAction = "assigned"
31+
// HookIssueUnassigned unassigned
32+
HookIssueUnassigned HookIssueAction = "unassigned"
33+
// HookIssueLabelUpdated label_updated
34+
HookIssueLabelUpdated HookIssueAction = "label_updated"
35+
// HookIssueLabelCleared label_cleared
36+
HookIssueLabelCleared HookIssueAction = "label_cleared"
37+
// HookIssueSynchronized synchronized
38+
HookIssueSynchronized HookIssueAction = "synchronized"
39+
// HookIssueMilestoned is an issue action for when a milestone is set on an issue.
40+
HookIssueMilestoned HookIssueAction = "milestoned"
41+
// HookIssueDemilestoned is an issue action for when a milestone is cleared on an issue.
42+
HookIssueDemilestoned HookIssueAction = "demilestoned"
43+
// HookIssueReviewed is an issue action for when a pull request is reviewed
44+
HookIssueReviewed HookIssueAction = "reviewed"
45+
// HookIssueReviewRequested is an issue action for when a reviewer is requested for a pull request.
46+
HookIssueReviewRequested HookIssueAction = "review_requested"
47+
// HookIssueReviewRequestRemoved is an issue action for removing a review request to someone on a pull request.
48+
HookIssueReviewRequestRemoved HookIssueAction = "review_request_removed"
49+
)
50+
51+
// IssuePayload represents the payload information that is sent along with an issue event.
52+
type IssuePayload struct {
53+
Action HookIssueAction `json:"action"`
54+
Index int64 `json:"number"`
55+
Changes *ChangesPayload `json:"changes,omitempty"`
56+
Issue *Issue `json:"issue"`
57+
Repository *Repository `json:"repository"`
58+
Sender *User `json:"sender"`
59+
CommitID string `json:"commit_id"`
60+
}
61+
62+
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
63+
func (p *IssuePayload) JSONPayload() ([]byte, error) {
64+
return json.MarshalIndent(p, "", " ")
65+
}
66+
67+
// HookIssueCommentAction defines hook issue comment action
68+
type HookIssueCommentAction string
69+
70+
// all issue comment actions
71+
const (
72+
HookIssueCommentCreated HookIssueCommentAction = "created"
73+
HookIssueCommentEdited HookIssueCommentAction = "edited"
74+
HookIssueCommentDeleted HookIssueCommentAction = "deleted"
75+
)
76+
77+
// IssueCommentPayload represents a payload information of issue comment event.
78+
type IssueCommentPayload struct {
79+
Action HookIssueCommentAction `json:"action"`
80+
Issue *Issue `json:"issue"`
81+
Comment *Comment `json:"comment"`
82+
Changes *ChangesPayload `json:"changes,omitempty"`
83+
Repository *Repository `json:"repository"`
84+
Sender *User `json:"sender"`
85+
IsPull bool `json:"is_pull"`
86+
}
87+
88+
// JSONPayload implements Payload
89+
func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
90+
return json.MarshalIndent(p, "", " ")
91+
}
92+
93+
// ChangesFromPayload FIXME
94+
type ChangesFromPayload struct {
95+
From string `json:"from"`
96+
}
97+
98+
// ChangesPayload represents the payload information of issue change
99+
type ChangesPayload struct {
100+
Title *ChangesFromPayload `json:"title,omitempty"`
101+
Body *ChangesFromPayload `json:"body,omitempty"`
102+
Ref *ChangesFromPayload `json:"ref,omitempty"`
103+
}

modules/structs/hook_package.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package structs
2+
3+
import "code.gitea.io/gitea/modules/json"
4+
5+
var _ Payloader = &PackagePayload{}
6+
7+
// HookPackageAction an action that happens to a package
8+
type HookPackageAction string
9+
10+
const (
11+
// HookPackageCreated created
12+
HookPackageCreated HookPackageAction = "created"
13+
// HookPackageDeleted deleted
14+
HookPackageDeleted HookPackageAction = "deleted"
15+
)
16+
17+
// PackagePayload represents a package payload
18+
type PackagePayload struct {
19+
Action HookPackageAction `json:"action"`
20+
Repository *Repository `json:"repository"`
21+
Package *Package `json:"package"`
22+
Organization *User `json:"organization"`
23+
Sender *User `json:"sender"`
24+
}
25+
26+
// JSONPayload implements Payload
27+
func (p *PackagePayload) JSONPayload() ([]byte, error) {
28+
return json.MarshalIndent(p, "", " ")
29+
}

modules/structs/hook_pr.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package structs
2+
3+
import "code.gitea.io/gitea/modules/json"
4+
5+
var _ Payloader = &PullRequestPayload{}
6+
7+
// __________ .__ .__ __________ __
8+
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
9+
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
10+
// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
11+
// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
12+
// \/ \/ |__| \/ \/
13+
14+
// PullRequestPayload represents a payload information of pull request event.
15+
type PullRequestPayload struct {
16+
Action HookIssueAction `json:"action"`
17+
Index int64 `json:"number"`
18+
Changes *ChangesPayload `json:"changes,omitempty"`
19+
PullRequest *PullRequest `json:"pull_request"`
20+
RequestedReviewer *User `json:"requested_reviewer"`
21+
Repository *Repository `json:"repository"`
22+
Sender *User `json:"sender"`
23+
CommitID string `json:"commit_id"`
24+
Review *ReviewPayload `json:"review"`
25+
}
26+
27+
// JSONPayload FIXME
28+
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
29+
return json.MarshalIndent(p, "", " ")
30+
}
31+
32+
// ReviewPayload FIXME
33+
type ReviewPayload struct {
34+
Type string `json:"type"`
35+
Content string `json:"content"`
36+
}

modules/structs/hook_release.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package structs
2+
3+
import "code.gitea.io/gitea/modules/json"
4+
5+
var _ Payloader = &ReleasePayload{}
6+
7+
// __________ .__
8+
// \______ \ ____ | | ____ _____ ______ ____
9+
// | _// __ \| | _/ __ \\__ \ / ___// __ \
10+
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
11+
// |____|_ /\___ >____/\___ >____ /____ >\___ >
12+
// \/ \/ \/ \/ \/ \/
13+
14+
// HookReleaseAction defines hook release action type
15+
type HookReleaseAction string
16+
17+
// all release actions
18+
const (
19+
HookReleasePublished HookReleaseAction = "published"
20+
HookReleaseUpdated HookReleaseAction = "updated"
21+
HookReleaseDeleted HookReleaseAction = "deleted"
22+
)
23+
24+
// ReleasePayload represents a payload information of release event.
25+
type ReleasePayload struct {
26+
Action HookReleaseAction `json:"action"`
27+
Release *Release `json:"release"`
28+
Repository *Repository `json:"repository"`
29+
Sender *User `json:"sender"`
30+
}
31+
32+
// JSONPayload implements Payload
33+
func (p *ReleasePayload) JSONPayload() ([]byte, error) {
34+
return json.MarshalIndent(p, "", " ")
35+
}

0 commit comments

Comments
 (0)