Browse Source

Restructured Repository Service files.

Billy Lynch 13 years ago
parent
commit
a468563b73
8 changed files with 531 additions and 456 deletions
  1. +0
    -215
      github/repos.go
  2. +70
    -0
      github/repos_forks.go
  3. +67
    -0
      github/repos_forks_test.go
  4. +116
    -0
      github/repos_hooks.go
  5. +143
    -0
      github/repos_hooks_test.go
  6. +63
    -0
      github/repos_statuses.go
  7. +72
    -0
      github/repos_statuses_test.go
  8. +0
    -241
      github/repos_test.go

+ 0
- 215
github/repos.go View File

@ -9,7 +9,6 @@ import (
"fmt" "fmt"
"net/url" "net/url"
"strconv" "strconv"
"time"
) )
// RepositoriesService handles communication with the repository related // RepositoriesService handles communication with the repository related
@ -199,117 +198,6 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
return r, err return r, err
} }
// RepositoryListForksOptions specifies the optional parameters to the
// RepositoriesService.ListForks method.
type RepositoryListForksOptions struct {
// How to sort the forks list. Possible values are: newest, oldest,
// watchers. Default is "newest".
Sort string
}
// ListForks lists the forks of the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListForksOptions) ([]Repository, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil {
params := url.Values{
"sort": []string{opt.Sort},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
}
// RepositoryCreateForkOptions specifies the optional parameters to the
// RepositoriesService.CreateFork method.
type RepositoryCreateForkOptions struct {
// The organization to fork the repository into.
Organization string
}
// CreateFork creates a fork of the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil {
params := url.Values{
"organization": []string{opt.Organization},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
fork := new(Repository)
_, err = s.client.Do(req, fork)
return fork, err
}
// RepoStatus represents the status of a repository at a particular reference.
type RepoStatus struct {
ID int `json:"id,omitempty"`
// State is the current state of the repository. Possible values are:
// pending, success, error, or failure.
State string `json:"state,omitempty"`
// TargetURL is the URL of the page representing this status. It will be
// linked from the GitHub UI to allow users to see the source of the status.
TargetURL string `json:"target_url,omitempty"`
// Description is a short high level summary of the status.
Description string `json:"description,omitempty"`
Creator *User `json:"creator,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
// ListStatuses lists the statuses of a repository at the specified
// reference. ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
func (s *RepositoriesService) ListStatuses(owner, repo, ref string) ([]RepoStatus, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
statuses := new([]RepoStatus)
_, err = s.client.Do(req, statuses)
return *statuses, err
}
// CreateStatus creates a new status for a repository at the specified
// reference. Ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: http://developer.github.com/v3/repos/statuses/#create-a-status
func (s *RepositoriesService) CreateStatus(owner, repo, ref string, status *RepoStatus) (*RepoStatus, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
req, err := s.client.NewRequest("POST", u, status)
if err != nil {
return nil, err
}
statuses := new(RepoStatus)
_, err = s.client.Do(req, statuses)
return statuses, err
}
// ListLanguages lists languages for the specified repository. The returned map // ListLanguages lists languages for the specified repository. The returned map
// specifies the languages and the number of bytes of code written in that // specifies the languages and the number of bytes of code written in that
// language. For example: // language. For example:
@ -331,106 +219,3 @@ func (s *RepositoriesService) ListLanguages(owner string, repository string) (ma
_, err = s.client.Do(req, &languages) _, err = s.client.Do(req, &languages)
return languages, err return languages, err
} }
// Hook represents a GitHub (web and service) hook for a repository.
type Hook struct {
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Name string `json:"name,omitempty"`
Events []string `json:"events,omitempty"`
Active bool `json:"active,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
ID int `json:"id,omitempty"`
}
// CreateHook creates a Hook for the specified repository.
// Name and Config are required fields.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#create-a-hook
func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
req, err := s.client.NewRequest("POST", u, hook)
if err != nil {
return nil, err
}
h := new(Hook)
_, err = s.client.Do(req, h)
return h, err
}
// ListHooks lists all Hooks for the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#list
func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([]Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
hooks := new([]Hook)
_, err = s.client.Do(req, hooks)
return *hooks, err
}
// GetHook returns a single specified Hook.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#get-single-hook
func (s *RepositoriesService) GetHook(owner, repo string, id int) (*Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
hook := new(Hook)
_, err = s.client.Do(req, hook)
return hook, err
}
// EditHook updates a specified Hook.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#edit-a-hook
func (s *RepositoriesService) EditHook(owner, repo string, id int, hook *Hook) (*Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, hook)
if err != nil {
return nil, err
}
h := new(Hook)
_, err = s.client.Do(req, h)
return h, err
}
// DeleteHook deletes a specified Hook.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#delete-a-hook
func (s *RepositoriesService) DeleteHook(owner, repo string, id int) error {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return err
}
_, err = s.client.Do(req, nil)
return err
}
// TestHook triggers a test Hook by github.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#test-a-push-hook
func (s *RepositoriesService) TestHook(owner, repo string, id int) error {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return err
}
_, err = s.client.Do(req, nil)
return err
}

+ 70
- 0
github/repos_forks.go View File

@ -0,0 +1,70 @@
// Copyright 2013 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
import (
"fmt"
"net/url"
)
// RepositoryListForksOptions specifies the optional parameters to the
// RepositoriesService.ListForks method.
type RepositoryListForksOptions struct {
// How to sort the forks list. Possible values are: newest, oldest,
// watchers. Default is "newest".
Sort string
}
// ListForks lists the forks of the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) ListForks(owner, repo string, opt *RepositoryListForksOptions) ([]Repository, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil {
params := url.Values{
"sort": []string{opt.Sort},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
repos := new([]Repository)
_, err = s.client.Do(req, repos)
return *repos, err
}
// RepositoryCreateForkOptions specifies the optional parameters to the
// RepositoriesService.CreateFork method.
type RepositoryCreateForkOptions struct {
// The organization to fork the repository into.
Organization string
}
// CreateFork creates a fork of the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/forks/#list-forks
func (s *RepositoriesService) CreateFork(owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, error) {
u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
if opt != nil {
params := url.Values{
"organization": []string{opt.Organization},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return nil, err
}
fork := new(Repository)
_, err = s.client.Do(req, fork)
return fork, err
}

+ 67
- 0
github/repos_forks_test.go View File

@ -0,0 +1,67 @@
// Copyright 2013 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
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRepositoriesService_ListForks(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"sort": "newest"})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &RepositoryListForksOptions{Sort: "newest"}
repos, err := client.Repositories.ListForks("o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListForks returned error: %v", err)
}
want := []Repository{Repository{ID: 1}, Repository{ID: 2}}
if !reflect.DeepEqual(repos, want) {
t.Errorf("Repositories.ListForks returned %+v, want %+v", repos, want)
}
}
func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) {
_, err := client.Repositories.ListForks("%", "r", nil)
testURLParseError(t, err)
}
func TestRepositoriesService_CreateFork(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testFormValues(t, r, values{"organization": "o"})
fmt.Fprint(w, `{"id":1}`)
})
opt := &RepositoryCreateForkOptions{Organization: "o"}
repo, err := client.Repositories.CreateFork("o", "r", opt)
if err != nil {
t.Errorf("Repositories.CreateFork returned error: %v", err)
}
want := &Repository{ID: 1}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repositories.CreateFork returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) {
_, err := client.Repositories.CreateFork("%", "r", nil)
testURLParseError(t, err)
}

+ 116
- 0
github/repos_hooks.go View File

@ -0,0 +1,116 @@
// Copyright 2013 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
import (
"fmt"
"net/url"
"strconv"
"time"
)
// Hook represents a GitHub (web and service) hook for a repository.
type Hook struct {
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Name string `json:"name,omitempty"`
Events []string `json:"events,omitempty"`
Active bool `json:"active,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
ID int `json:"id,omitempty"`
}
// CreateHook creates a Hook for the specified repository.
// Name and Config are required fields.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#create-a-hook
func (s *RepositoriesService) CreateHook(owner, repo string, hook *Hook) (*Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
req, err := s.client.NewRequest("POST", u, hook)
if err != nil {
return nil, err
}
h := new(Hook)
_, err = s.client.Do(req, h)
return h, err
}
// ListHooks lists all Hooks for the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#list
func (s *RepositoriesService) ListHooks(owner, repo string, opt *ListOptions) ([]Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks", owner, repo)
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
hooks := new([]Hook)
_, err = s.client.Do(req, hooks)
return *hooks, err
}
// GetHook returns a single specified Hook.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#get-single-hook
func (s *RepositoriesService) GetHook(owner, repo string, id int) (*Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
hook := new(Hook)
_, err = s.client.Do(req, hook)
return hook, err
}
// EditHook updates a specified Hook.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#edit-a-hook
func (s *RepositoriesService) EditHook(owner, repo string, id int, hook *Hook) (*Hook, error) {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("PATCH", u, hook)
if err != nil {
return nil, err
}
h := new(Hook)
_, err = s.client.Do(req, h)
return h, err
}
// DeleteHook deletes a specified Hook.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#delete-a-hook
func (s *RepositoriesService) DeleteHook(owner, repo string, id int) error {
u := fmt.Sprintf("repos/%v/%v/hooks/%d", owner, repo, id)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return err
}
_, err = s.client.Do(req, nil)
return err
}
// TestHook triggers a test Hook by github.
//
// GitHub API docs: http://developer.github.com/v3/repos/hooks/#test-a-push-hook
func (s *RepositoriesService) TestHook(owner, repo string, id int) error {
u := fmt.Sprintf("repos/%v/%v/hooks/%d/tests", owner, repo, id)
req, err := s.client.NewRequest("POST", u, nil)
if err != nil {
return err
}
_, err = s.client.Do(req, nil)
return err
}

+ 143
- 0
github/repos_hooks_test.go View File

@ -0,0 +1,143 @@
// Copyright 2013 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
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRepositoriesService_CreateHook(t *testing.T) {
setup()
defer teardown()
input := &Hook{Name: "t"}
mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) {
v := new(Hook)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1}`)
})
hook, err := client.Repositories.CreateHook("o", "r", input)
if err != nil {
t.Errorf("Repositories.CreateHook returned error: %v", err)
}
want := &Hook{ID: 1}
if !reflect.DeepEqual(hook, want) {
t.Errorf("Repositories.CreateHook returned %+v, want %+v", hook, want)
}
}
func TestRepositoriesService_ListHooks(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
})
opt := &ListOptions{2}
hooks, err := client.Repositories.ListHooks("o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListHooks returned error: %v", err)
}
want := []Hook{Hook{ID: 1}, Hook{ID: 2}}
if !reflect.DeepEqual(hooks, want) {
t.Errorf("Repositories.ListHooks returned %+v, want %+v", hooks, want)
}
}
func TestRepositoriesService_GetHook(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
hook, err := client.Repositories.GetHook("o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetHook returned error: %v", err)
}
want := &Hook{ID: 1}
if !reflect.DeepEqual(hook, want) {
t.Errorf("Repositories.GetHook returned %+v, want %+v", hook, want)
}
}
func TestRepositoriesService_EditHook(t *testing.T) {
setup()
defer teardown()
input := &Hook{Name: "t"}
mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) {
v := new(Hook)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1}`)
})
hook, err := client.Repositories.EditHook("o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.EditHook returned error: %v", err)
}
want := &Hook{ID: 1}
if !reflect.DeepEqual(hook, want) {
t.Errorf("Repositories.EditHook returned %+v, want %+v", hook, want)
}
}
func TestRepositoriesService_DeleteHook(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
err := client.Repositories.DeleteHook("o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteHook returned error: %v", err)
}
}
func TestRepositoriesService_TestHook(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks/1/tests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
})
err := client.Repositories.TestHook("o", "r", 1)
if err != nil {
t.Errorf("Repositories.TestHook returned error: %v", err)
}
}

+ 63
- 0
github/repos_statuses.go View File

@ -0,0 +1,63 @@
// Copyright 2013 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
import (
"fmt"
"time"
)
// RepoStatus represents the status of a repository at a particular reference.
type RepoStatus struct {
ID int `json:"id,omitempty"`
// State is the current state of the repository. Possible values are:
// pending, success, error, or failure.
State string `json:"state,omitempty"`
// TargetURL is the URL of the page representing this status. It will be
// linked from the GitHub UI to allow users to see the source of the status.
TargetURL string `json:"target_url,omitempty"`
// Description is a short high level summary of the status.
Description string `json:"description,omitempty"`
Creator *User `json:"creator,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
// ListStatuses lists the statuses of a repository at the specified
// reference. ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
func (s *RepositoriesService) ListStatuses(owner, repo, ref string) ([]RepoStatus, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
statuses := new([]RepoStatus)
_, err = s.client.Do(req, statuses)
return *statuses, err
}
// CreateStatus creates a new status for a repository at the specified
// reference. Ref can be a SHA, a branch name, or a tag name.
//
// GitHub API docs: http://developer.github.com/v3/repos/statuses/#create-a-status
func (s *RepositoriesService) CreateStatus(owner, repo, ref string, status *RepoStatus) (*RepoStatus, error) {
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
req, err := s.client.NewRequest("POST", u, status)
if err != nil {
return nil, err
}
statuses := new(RepoStatus)
_, err = s.client.Do(req, statuses)
return statuses, err
}

+ 72
- 0
github/repos_statuses_test.go View File

@ -0,0 +1,72 @@
// Copyright 2013 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
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRepositoriesService_ListStatuses(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1}]`)
})
statuses, err := client.Repositories.ListStatuses("o", "r", "r")
if err != nil {
t.Errorf("Repositories.ListStatuses returned error: %v", err)
}
want := []RepoStatus{RepoStatus{ID: 1}}
if !reflect.DeepEqual(statuses, want) {
t.Errorf("Repositories.ListStatuses returned %+v, want %+v", statuses, want)
}
}
func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) {
_, err := client.Repositories.ListStatuses("%", "r", "r")
testURLParseError(t, err)
}
func TestRepositoriesService_CreateStatus(t *testing.T) {
setup()
defer teardown()
input := &RepoStatus{State: "s", TargetURL: "t", Description: "d"}
mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) {
v := new(RepoStatus)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1}`)
})
status, err := client.Repositories.CreateStatus("o", "r", "r", input)
if err != nil {
t.Errorf("Repositories.CreateStatus returned error: %v", err)
}
want := &RepoStatus{ID: 1}
if !reflect.DeepEqual(status, want) {
t.Errorf("Repositories.CreateStatus returned %+v, want %+v", status, want)
}
}
func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) {
_, err := client.Repositories.CreateStatus("%", "r", "r", nil)
testURLParseError(t, err)
}

+ 0
- 241
github/repos_test.go View File

@ -240,118 +240,6 @@ func TestRepositoriesService_Edit_invalidOwner(t *testing.T) {
testURLParseError(t, err) testURLParseError(t, err)
} }
func TestRepositoriesService_ListForks(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"sort": "newest"})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &RepositoryListForksOptions{Sort: "newest"}
repos, err := client.Repositories.ListForks("o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListForks returned error: %v", err)
}
want := []Repository{Repository{ID: 1}, Repository{ID: 2}}
if !reflect.DeepEqual(repos, want) {
t.Errorf("Repositories.ListForks returned %+v, want %+v", repos, want)
}
}
func TestRepositoriesService_ListForks_invalidOwner(t *testing.T) {
_, err := client.Repositories.ListForks("%", "r", nil)
testURLParseError(t, err)
}
func TestRepositoriesService_CreateFork(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/forks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testFormValues(t, r, values{"organization": "o"})
fmt.Fprint(w, `{"id":1}`)
})
opt := &RepositoryCreateForkOptions{Organization: "o"}
repo, err := client.Repositories.CreateFork("o", "r", opt)
if err != nil {
t.Errorf("Repositories.CreateFork returned error: %v", err)
}
want := &Repository{ID: 1}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repositories.CreateFork returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_CreateFork_invalidOwner(t *testing.T) {
_, err := client.Repositories.CreateFork("%", "r", nil)
testURLParseError(t, err)
}
func TestRepositoriesService_ListStatuses(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1}]`)
})
statuses, err := client.Repositories.ListStatuses("o", "r", "r")
if err != nil {
t.Errorf("Repositories.ListStatuses returned error: %v", err)
}
want := []RepoStatus{RepoStatus{ID: 1}}
if !reflect.DeepEqual(statuses, want) {
t.Errorf("Repositories.ListStatuses returned %+v, want %+v", statuses, want)
}
}
func TestRepositoriesService_ListStatuses_invalidOwner(t *testing.T) {
_, err := client.Repositories.ListStatuses("%", "r", "r")
testURLParseError(t, err)
}
func TestRepositoriesService_CreateStatus(t *testing.T) {
setup()
defer teardown()
input := &RepoStatus{State: "s", TargetURL: "t", Description: "d"}
mux.HandleFunc("/repos/o/r/statuses/r", func(w http.ResponseWriter, r *http.Request) {
v := new(RepoStatus)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1}`)
})
status, err := client.Repositories.CreateStatus("o", "r", "r", input)
if err != nil {
t.Errorf("Repositories.CreateStatus returned error: %v", err)
}
want := &RepoStatus{ID: 1}
if !reflect.DeepEqual(status, want) {
t.Errorf("Repositories.CreateStatus returned %+v, want %+v", status, want)
}
}
func TestRepositoriesService_CreateStatus_invalidOwner(t *testing.T) {
_, err := client.Repositories.CreateStatus("%", "r", "r", nil)
testURLParseError(t, err)
}
func TestRepositoriesService_ListLanguages(t *testing.T) { func TestRepositoriesService_ListLanguages(t *testing.T) {
setup() setup()
defer teardown() defer teardown()
@ -371,132 +259,3 @@ func TestRepositoriesService_ListLanguages(t *testing.T) {
t.Errorf("Repositories.ListLanguages returned %+v, want %+v", languages, want) t.Errorf("Repositories.ListLanguages returned %+v, want %+v", languages, want)
} }
} }
func TestRepositoriesService_CreateHook(t *testing.T) {
setup()
defer teardown()
input := &Hook{Name: "t"}
mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) {
v := new(Hook)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1}`)
})
hook, err := client.Repositories.CreateHook("o", "r", input)
if err != nil {
t.Errorf("Repositories.CreateHook returned error: %v", err)
}
want := &Hook{ID: 1}
if !reflect.DeepEqual(hook, want) {
t.Errorf("Repositories.CreateHook returned %+v, want %+v", hook, want)
}
}
func TestRepositoriesService_ListHooks(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}, {"id":2}]`)
})
opt := &ListOptions{2}
hooks, err := client.Repositories.ListHooks("o", "r", opt)
if err != nil {
t.Errorf("Repositories.ListHooks returned error: %v", err)
}
want := []Hook{Hook{ID: 1}, Hook{ID: 2}}
if !reflect.DeepEqual(hooks, want) {
t.Errorf("Repositories.ListHooks returned %+v, want %+v", hooks, want)
}
}
func TestRepositoriesService_GetHook(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
hook, err := client.Repositories.GetHook("o", "r", 1)
if err != nil {
t.Errorf("Repositories.GetHook returned error: %v", err)
}
want := &Hook{ID: 1}
if !reflect.DeepEqual(hook, want) {
t.Errorf("Repositories.GetHook returned %+v, want %+v", hook, want)
}
}
func TestRepositoriesService_EditHook(t *testing.T) {
setup()
defer teardown()
input := &Hook{Name: "t"}
mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) {
v := new(Hook)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1}`)
})
hook, err := client.Repositories.EditHook("o", "r", 1, input)
if err != nil {
t.Errorf("Repositories.EditHook returned error: %v", err)
}
want := &Hook{ID: 1}
if !reflect.DeepEqual(hook, want) {
t.Errorf("Repositories.EditHook returned %+v, want %+v", hook, want)
}
}
func TestRepositoriesService_DeleteHook(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
err := client.Repositories.DeleteHook("o", "r", 1)
if err != nil {
t.Errorf("Repositories.DeleteHook returned error: %v", err)
}
}
func TestRepositoriesService_TestHook(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/hooks/1/tests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
})
err := client.Repositories.TestHook("o", "r", 1)
if err != nil {
t.Errorf("Repositories.TestHook returned error: %v", err)
}
}

Loading…
Cancel
Save