Browse Source

add support for listing service hooks

Will Norris 12 years ago
parent
commit
bbf03525f8
3 changed files with 75 additions and 0 deletions
  1. +32
    -0
      github/repos_hooks.go
  2. +32
    -0
      github/repos_hooks_test.go
  3. +11
    -0
      tests/integration/repos_test.go

+ 32
- 0
github/repos_hooks.go View File

@ -175,3 +175,35 @@ func (s *RepositoriesService) TestHook(owner, repo string, id int) (*Response, e
} }
return s.client.Do(req, nil) return s.client.Do(req, nil)
} }
// ServiceHook represents a hook that has configuration settings, a list of
// available events, and default events.
type ServiceHook struct {
Name *string `json:"name,omitempty"`
Events []string `json:"events,omitempty"`
SupportedEvents []string `json:"supported_events,omitempty"`
Schema [][]string `json:"schema,omitempty"`
}
func (s *ServiceHook) String() string {
return Stringify(s)
}
// ListServiceHooks lists all of the available service hooks.
//
// GitHub API docs: https://developer.github.com/webhooks/#services
func (s *RepositoriesService) ListServiceHooks() ([]ServiceHook, *Response, error) {
u := "hooks"
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
hooks := new([]ServiceHook)
resp, err := s.client.Do(req, hooks)
if err != nil {
return nil, resp, err
}
return *hooks, resp, err
}

+ 32
- 0
github/repos_hooks_test.go View File

@ -171,3 +171,35 @@ func TestRepositoriesService_TestHook_invalidOwner(t *testing.T) {
_, err := client.Repositories.TestHook("%", "%", 1) _, err := client.Repositories.TestHook("%", "%", 1)
testURLParseError(t, err) testURLParseError(t, err)
} }
func TestRepositoriesService_ListServiceHooks(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/hooks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{
"name":"n",
"events":["e"],
"supported_events":["s"],
"schema":[
["a", "b"]
]
}]`)
})
hooks, _, err := client.Repositories.ListServiceHooks()
if err != nil {
t.Errorf("Repositories.ListHooks returned error: %v", err)
}
want := []ServiceHook{{
Name: String("n"),
Events: []string{"e"},
SupportedEvents: []string{"s"},
Schema: [][]string{{"a", "b"}},
}}
if !reflect.DeepEqual(hooks, want) {
t.Errorf("Repositories.ListServiceHooks returned %+v, want %+v", hooks, want)
}
}

+ 11
- 0
tests/integration/repos_test.go View File

@ -95,3 +95,14 @@ func TestRepositories_BranchesTags(t *testing.T) {
t.Fatalf("Repositories.ListTags('git', 'git') returned no tags") t.Fatalf("Repositories.ListTags('git', 'git') returned no tags")
} }
} }
func TestRepositories_ServiceHooks(t *testing.T) {
hooks, _, err := client.Repositories.ListServiceHooks()
if err != nil {
t.Fatalf("Repositories.ListServiceHooks() returned error: %v", err)
}
if len(hooks) == 0 {
t.Fatalf("Repositories.ListServiceHooks() returned no hooks")
}
}

Loading…
Cancel
Save