1package webhook
 2
 3import "time"
 4
 5// EventPayload is a webhook event payload.
 6type EventPayload interface {
 7	// Event returns the event type.
 8	Event() Event
 9	// RepositoryID returns the repository ID.
10	RepositoryID() int64
11}
12
13// Common is a common payload.
14type Common struct {
15	// EventType is the event type.
16	EventType Event `json:"event" url:"event"`
17	// Repository is the repository payload.
18	Repository Repository `json:"repository" url:"repository"`
19	// Sender is the sender payload.
20	Sender User `json:"sender" url:"sender"`
21}
22
23// Event returns the event type.
24// Implements EventPayload.
25func (c Common) Event() Event {
26	return c.EventType
27}
28
29// RepositoryID returns the repository ID.
30// Implements EventPayload.
31func (c Common) RepositoryID() int64 {
32	return c.Repository.ID
33}
34
35// User represents a user in an event.
36type User struct {
37	// ID is the owner ID.
38	ID int64 `json:"id" url:"id"`
39	// Username is the owner username.
40	Username string `json:"username" url:"username"`
41}
42
43// Repository represents an event repository.
44type Repository struct {
45	// ID is the repository ID.
46	ID int64 `json:"id" url:"id"`
47	// Name is the repository name.
48	Name string `json:"name" url:"name"`
49	// ProjectName is the repository project name.
50	ProjectName string `json:"project_name" url:"project_name"`
51	// Description is the repository description.
52	Description string `json:"description" url:"description"`
53	// DefaultBranch is the repository default branch.
54	DefaultBranch string `json:"default_branch" url:"default_branch"`
55	// Private is whether the repository is private.
56	Private bool `json:"private" url:"private"`
57	// Owner is the repository owner.
58	Owner User `json:"owner" url:"owner"`
59	// HTTPURL is the repository HTTP URL.
60	HTTPURL string `json:"http_url" url:"http_url"`
61	// SSHURL is the repository SSH URL.
62	SSHURL string `json:"ssh_url" url:"ssh_url"`
63	// GitURL is the repository Git URL.
64	GitURL string `json:"git_url" url:"git_url"`
65	// CreatedAt is the repository creation time.
66	CreatedAt time.Time `json:"created_at" url:"created_at"`
67	// UpdatedAt is the repository last update time.
68	UpdatedAt time.Time `json:"updated_at" url:"updated_at"`
69}
70
71// Author is a commit author.
72type Author struct {
73	// Name is the author name.
74	Name string `json:"name" url:"name"`
75	// Email is the author email.
76	Email string `json:"email" url:"email"`
77	// Date is the author date.
78	Date time.Time `json:"date" url:"date"`
79}
80
81// Commit represents a Git commit.
82type Commit struct {
83	// ID is the commit ID.
84	ID string `json:"id" url:"id"`
85	// Message is the commit message.
86	Message string `json:"message" url:"message"`
87	// Title is the commit title.
88	Title string `json:"title" url:"title"`
89	// Author is the commit author.
90	Author Author `json:"author" url:"author"`
91	// Committer is the commit committer.
92	Committer Author `json:"committer" url:"committer"`
93	// Timestamp is the commit timestamp.
94	Timestamp time.Time `json:"timestamp" url:"timestamp"`
95}