|
|
@ -14,9 +14,11 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
|
|
|
|
// ErrInvalidReceiveHook FIXME
|
|
|
|
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook") |
|
|
|
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook") |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Hook a hook is a web hook when one repository changed
|
|
|
|
type Hook struct { |
|
|
|
type Hook struct { |
|
|
|
ID int64 `json:"id"` |
|
|
|
ID int64 `json:"id"` |
|
|
|
Type string `json:"type"` |
|
|
|
Type string `json:"type"` |
|
|
@ -28,11 +30,13 @@ type Hook struct { |
|
|
|
Created time.Time `json:"created_at"` |
|
|
|
Created time.Time `json:"created_at"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ListRepoHooks list all the hooks of one repository
|
|
|
|
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) { |
|
|
|
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) { |
|
|
|
hooks := make([]*Hook, 0, 10) |
|
|
|
hooks := make([]*Hook, 0, 10) |
|
|
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks) |
|
|
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CreateHookOption options when create a hook
|
|
|
|
type CreateHookOption struct { |
|
|
|
type CreateHookOption struct { |
|
|
|
Type string `json:"type" binding:"Required"` |
|
|
|
Type string `json:"type" binding:"Required"` |
|
|
|
Config map[string]string `json:"config" binding:"Required"` |
|
|
|
Config map[string]string `json:"config" binding:"Required"` |
|
|
@ -40,6 +44,7 @@ type CreateHookOption struct { |
|
|
|
Active bool `json:"active"` |
|
|
|
Active bool `json:"active"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CreateRepoHook create one hook with options
|
|
|
|
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) { |
|
|
|
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) { |
|
|
|
body, err := json.Marshal(&opt) |
|
|
|
body, err := json.Marshal(&opt) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -49,12 +54,14 @@ func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, |
|
|
|
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h) |
|
|
|
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// EditHookOption options when modify one hook
|
|
|
|
type EditHookOption struct { |
|
|
|
type EditHookOption struct { |
|
|
|
Config map[string]string `json:"config"` |
|
|
|
Config map[string]string `json:"config"` |
|
|
|
Events []string `json:"events"` |
|
|
|
Events []string `json:"events"` |
|
|
|
Active *bool `json:"active"` |
|
|
|
Active *bool `json:"active"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// EditRepoHook modify one hook with hook id and options
|
|
|
|
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error { |
|
|
|
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error { |
|
|
|
body, err := json.Marshal(&opt) |
|
|
|
body, err := json.Marshal(&opt) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -64,23 +71,26 @@ func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) e |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DeleteRepoHook delete one hook with hook id
|
|
|
|
func (c *Client) DeleteRepoHook(user, repo string, id int64) error { |
|
|
|
func (c *Client) DeleteRepoHook(user, repo string, id int64) error { |
|
|
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil) |
|
|
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Payloader payload is some part of one hook
|
|
|
|
type Payloader interface { |
|
|
|
type Payloader interface { |
|
|
|
SetSecret(string) |
|
|
|
SetSecret(string) |
|
|
|
JSONPayload() ([]byte, error) |
|
|
|
JSONPayload() ([]byte, error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PayloadUser FIXME
|
|
|
|
type PayloadUser struct { |
|
|
|
type PayloadUser struct { |
|
|
|
Name string `json:"name"` |
|
|
|
Name string `json:"name"` |
|
|
|
Email string `json:"email"` |
|
|
|
Email string `json:"email"` |
|
|
|
UserName string `json:"username"` |
|
|
|
UserName string `json:"username"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: consider use same format as API when commits API are added.
|
|
|
|
// PayloadCommit FIXME: consider use same format as API when commits API are added.
|
|
|
|
type PayloadCommit struct { |
|
|
|
type PayloadCommit struct { |
|
|
|
ID string `json:"id"` |
|
|
|
ID string `json:"id"` |
|
|
|
Message string `json:"message"` |
|
|
|
Message string `json:"message"` |
|
|
@ -103,18 +113,22 @@ var ( |
|
|
|
// \______ /|__| \___ >____ /__| \___ >
|
|
|
|
// \______ /|__| \___ >____ /__| \___ >
|
|
|
|
// \/ \/ \/ \/
|
|
|
|
// \/ \/ \/ \/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CreatePayload FIXME
|
|
|
|
type CreatePayload struct { |
|
|
|
type CreatePayload struct { |
|
|
|
Secret string `json:"secret"` |
|
|
|
Secret string `json:"secret"` |
|
|
|
|
|
|
|
Sha string `json:"sha"` |
|
|
|
Ref string `json:"ref"` |
|
|
|
Ref string `json:"ref"` |
|
|
|
RefType string `json:"ref_type"` |
|
|
|
RefType string `json:"ref_type"` |
|
|
|
Repo *Repository `json:"repository"` |
|
|
|
Repo *Repository `json:"repository"` |
|
|
|
Sender *User `json:"sender"` |
|
|
|
Sender *User `json:"sender"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SetSecret FIXME
|
|
|
|
func (p *CreatePayload) SetSecret(secret string) { |
|
|
|
func (p *CreatePayload) SetSecret(secret string) { |
|
|
|
p.Secret = secret |
|
|
|
p.Secret = secret |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JSONPayload return payload information
|
|
|
|
func (p *CreatePayload) JSONPayload() ([]byte, error) { |
|
|
|
func (p *CreatePayload) JSONPayload() ([]byte, error) { |
|
|
|
return json.MarshalIndent(p, "", " ") |
|
|
|
return json.MarshalIndent(p, "", " ") |
|
|
|
} |
|
|
|
} |
|
|
@ -159,10 +173,12 @@ type PushPayload struct { |
|
|
|
Sender *User `json:"sender"` |
|
|
|
Sender *User `json:"sender"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SetSecret FIXME
|
|
|
|
func (p *PushPayload) SetSecret(secret string) { |
|
|
|
func (p *PushPayload) SetSecret(secret string) { |
|
|
|
p.Secret = secret |
|
|
|
p.Secret = secret |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JSONPayload FIXME
|
|
|
|
func (p *PushPayload) JSONPayload() ([]byte, error) { |
|
|
|
func (p *PushPayload) JSONPayload() ([]byte, error) { |
|
|
|
return json.MarshalIndent(p, "", " ") |
|
|
|
return json.MarshalIndent(p, "", " ") |
|
|
|
} |
|
|
|
} |
|
|
@ -195,24 +211,36 @@ func (p *PushPayload) Branch() string { |
|
|
|
// |___/____ >____ >____/ \___ >
|
|
|
|
// |___/____ >____ >____/ \___ >
|
|
|
|
// \/ \/ \/
|
|
|
|
// \/ \/ \/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HookIssueAction FIXME
|
|
|
|
type HookIssueAction string |
|
|
|
type HookIssueAction string |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
HookIssueOpened HookIssueAction = "opened" |
|
|
|
// HookIssueOpened opened
|
|
|
|
HookIssueClosed HookIssueAction = "closed" |
|
|
|
HookIssueOpened HookIssueAction = "opened" |
|
|
|
HookIssueReopened HookIssueAction = "reopened" |
|
|
|
// HookIssueClosed closed
|
|
|
|
HookIssueEdited HookIssueAction = "edited" |
|
|
|
HookIssueClosed HookIssueAction = "closed" |
|
|
|
HookIssueAssigned HookIssueAction = "assigned" |
|
|
|
// HookIssueReOpened reopened
|
|
|
|
HookIssueUnassigned HookIssueAction = "unassigned" |
|
|
|
HookIssueReOpened HookIssueAction = "reopened" |
|
|
|
|
|
|
|
// HookIssueEdited edited
|
|
|
|
|
|
|
|
HookIssueEdited HookIssueAction = "edited" |
|
|
|
|
|
|
|
// HookIssueAssigned assigned
|
|
|
|
|
|
|
|
HookIssueAssigned HookIssueAction = "assigned" |
|
|
|
|
|
|
|
// HookIssueUnassigned unassigned
|
|
|
|
|
|
|
|
HookIssueUnassigned HookIssueAction = "unassigned" |
|
|
|
|
|
|
|
// HookIssueLabelUpdated label_updated
|
|
|
|
HookIssueLabelUpdated HookIssueAction = "label_updated" |
|
|
|
HookIssueLabelUpdated HookIssueAction = "label_updated" |
|
|
|
|
|
|
|
// HookIssueLabelCleared label_cleared
|
|
|
|
HookIssueLabelCleared HookIssueAction = "label_cleared" |
|
|
|
HookIssueLabelCleared HookIssueAction = "label_cleared" |
|
|
|
HookIssueSynchronized HookIssueAction = "synchronized" |
|
|
|
// HookIssueSynchronized synchronized
|
|
|
|
|
|
|
|
HookIssueSynchronized HookIssueAction = "synchronized" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ChangesFromPayload FIXME
|
|
|
|
type ChangesFromPayload struct { |
|
|
|
type ChangesFromPayload struct { |
|
|
|
From string `json:"from"` |
|
|
|
From string `json:"from"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ChangesPayload FIXME
|
|
|
|
type ChangesPayload struct { |
|
|
|
type ChangesPayload struct { |
|
|
|
Title *ChangesFromPayload `json:"title,omitempty"` |
|
|
|
Title *ChangesFromPayload `json:"title,omitempty"` |
|
|
|
Body *ChangesFromPayload `json:"body,omitempty"` |
|
|
|
Body *ChangesFromPayload `json:"body,omitempty"` |
|
|
@ -236,10 +264,12 @@ type PullRequestPayload struct { |
|
|
|
Sender *User `json:"sender"` |
|
|
|
Sender *User `json:"sender"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SetSecret FIXME
|
|
|
|
func (p *PullRequestPayload) SetSecret(secret string) { |
|
|
|
func (p *PullRequestPayload) SetSecret(secret string) { |
|
|
|
p.Secret = secret |
|
|
|
p.Secret = secret |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JSONPayload FIXME
|
|
|
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) { |
|
|
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) { |
|
|
|
return json.MarshalIndent(p, "", " ") |
|
|
|
return json.MarshalIndent(p, "", " ") |
|
|
|
} |
|
|
|
} |
|
|
|