diff --git a/gitea/hook.go b/gitea/hook.go index bdc80a1..fe42b7c 100644 --- a/gitea/hook.go +++ b/gitea/hook.go @@ -62,6 +62,14 @@ func (c *Client) ListOrgHooks(org string, opt ListHooksOptions) ([]*Hook, *Respo return hooks, resp, err } +// ListMyHooks list all the hooks of the authenticated user +func (c *Client) ListMyHooks(opt ListHooksOptions) ([]*Hook, *Response, error) { + opt.setDefaults() + hooks := make([]*Hook, 0, opt.PageSize) + resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/hooks?%s", opt.getURLQuery().Encode()), nil, nil, &hooks) + return hooks, resp, err +} + // ListRepoHooks list all the hooks of one repository func (c *Client) ListRepoHooks(user, repo string, opt ListHooksOptions) ([]*Hook, *Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { @@ -83,6 +91,13 @@ func (c *Client) GetOrgHook(org string, id int64) (*Hook, *Response, error) { return h, resp, err } +// GetMyHook get a hook of the authenticated user +func (c *Client) GetMyHook(id int64) (*Hook, *Response, error) { + h := new(Hook) + resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/hooks/%d", id), nil, nil, h) + return h, resp, err +} + // GetRepoHook get a hook of a repository func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, *Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { @@ -128,6 +143,20 @@ func (c *Client) CreateOrgHook(org string, opt CreateHookOption) (*Hook, *Respon return h, resp, err } +// CreateMyHook create one hook for the authenticated user, with options +func (c *Client) CreateMyHook(opt CreateHookOption) (*Hook, *Response, error) { + if err := opt.Validate(); err != nil { + return nil, nil, err + } + body, err := json.Marshal(&opt) + if err != nil { + return nil, nil, err + } + h := new(Hook) + resp, err := c.getParsedResponse("POST", "/user/hooks", jsonHeader, bytes.NewReader(body), h) + return h, resp, err +} + // CreateRepoHook create one hook for a repository, with options func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, *Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { @@ -164,6 +193,16 @@ func (c *Client) EditOrgHook(org string, id int64, opt EditHookOption) (*Respons return resp, err } +// EditMyHook modify one hook of the authenticated user, with hook id and options +func (c *Client) EditMyHook(id int64, opt EditHookOption) (*Response, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + _, resp, err := c.getResponse("PATCH", fmt.Sprintf("/user/hooks/%d", id), jsonHeader, bytes.NewReader(body)) + return resp, err +} + // EditRepoHook modify one hook of a repository, with hook id and options func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) (*Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil { @@ -186,6 +225,12 @@ func (c *Client) DeleteOrgHook(org string, id int64) (*Response, error) { return resp, err } +// DeleteMyHook delete one hook from the authenticated user, with hook id +func (c *Client) DeleteMyHook(id int64) (*Response, error) { + _, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/hooks/%d", id), nil, nil) + return resp, err +} + // DeleteRepoHook delete one hook from a repository, with hook id func (c *Client) DeleteRepoHook(user, repo string, id int64) (*Response, error) { if err := escapeValidatePathSegments(&user, &repo); err != nil {