2017-02-07 21:33:23 +00:00
|
|
|
// Copyright 2015 The go-github AUTHORS. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package github
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
2017-02-07 21:33:23 +00:00
|
|
|
|
|
|
|
// ListHooks lists all Hooks for the specified organization.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#list-hooks
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opt *ListOptions) ([]*Hook, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := fmt.Sprintf("orgs/%v/hooks", org)
|
|
|
|
u, err := addOptions(u, opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
var hooks []*Hook
|
|
|
|
resp, err := s.client.Do(ctx, req, &hooks)
|
2017-02-07 21:33:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return hooks, resp, nil
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetHook returns a single specified Hook.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#get-single-hook
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int) (*Hook, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
hook := new(Hook)
|
2017-04-11 15:10:46 +00:00
|
|
|
resp, err := s.client.Do(ctx, req, hook)
|
2017-02-07 21:33:23 +00:00
|
|
|
return hook, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateHook creates a Hook for the specified org.
|
|
|
|
// Name and Config are required fields.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#create-a-hook
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := fmt.Sprintf("orgs/%v/hooks", org)
|
|
|
|
req, err := s.client.NewRequest("POST", u, hook)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
h := new(Hook)
|
2017-04-11 15:10:46 +00:00
|
|
|
resp, err := s.client.Do(ctx, req, h)
|
2017-02-07 21:33:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return h, resp, nil
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EditHook updates a specified Hook.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#edit-a-hook
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int, hook *Hook) (*Hook, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
|
|
|
|
req, err := s.client.NewRequest("PATCH", u, hook)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
h := new(Hook)
|
2017-04-11 15:10:46 +00:00
|
|
|
resp, err := s.client.Do(ctx, req, h)
|
2017-02-07 21:33:23 +00:00
|
|
|
return h, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// PingHook triggers a 'ping' event to be sent to the Hook.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#ping-a-hook
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int) (*Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id)
|
|
|
|
req, err := s.client.NewRequest("POST", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
return s.client.Do(ctx, req, nil)
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteHook deletes a specified Hook.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/orgs/hooks/#delete-a-hook
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int) (*Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
|
|
|
|
req, err := s.client.NewRequest("DELETE", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-04-11 15:10:46 +00:00
|
|
|
return s.client.Do(ctx, req, nil)
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|