Browse Source

add Repositories.Edit method

Will Norris 13 years ago
parent
commit
c28d6939ea
2 changed files with 53 additions and 0 deletions
  1. +18
    -0
      github/repos.go
  2. +35
    -0
      github/repos_test.go

+ 18
- 0
github/repos.go View File

@ -29,6 +29,10 @@ type Repository struct {
CreatedAt *Timestamp `json:"created_at,omitempty"`
PushedAt *Timestamp `json:"pushed_at,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
// Additional mutable fields when creating and editing a repository
HasIssues *bool `json:"has_issues"`
HasWiki *bool `json:"has_wiki"`
}
// RepositoryListOptions specifies the optional parameters to the
@ -181,6 +185,20 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, error) {
return repository, err
}
// Edit updates a repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/#edit
func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (*Repository, error) {
u := fmt.Sprintf("repos/%v/%v", owner, repo)
req, err := s.client.NewRequest("PATCH", u, repository)
if err != nil {
return nil, err
}
r := new(Repository)
_, err = s.client.Do(req, r)
return r, err
}
// RepositoryListForksOptions specifies the optional parameters to the
// RepositoriesService.ListForks method.
type RepositoryListForksOptions struct {


+ 35
- 0
github/repos_test.go View File

@ -201,11 +201,46 @@ func TestRepositoriesService_Get(t *testing.T) {
}
}
func TestRepositoriesService_Edit(t *testing.T) {
setup()
defer teardown()
i := true
input := &Repository{HasIssues: &i}
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
v := new(Repository)
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}`)
})
repo, err := client.Repositories.Edit("o", "r", input)
if err != nil {
t.Errorf("Repositories.Edit returned error: %v", err)
}
want := &Repository{ID: 1}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repositories.Edit returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_Get_invalidOwner(t *testing.T) {
_, err := client.Repositories.Get("%", "r")
testURLParseError(t, err)
}
func TestRepositoriesService_Edit_invalidOwner(t *testing.T) {
_, err := client.Repositories.Edit("%", "r", nil)
testURLParseError(t, err)
}
func TestRepositoriesService_ListForks(t *testing.T) {
setup()
defer teardown()


Loading…
Cancel
Save