From c28d6939ead319462e248628f46b225b941e020c Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 9 Jul 2013 10:20:37 -0700 Subject: [PATCH] add Repositories.Edit method --- github/repos.go | 18 ++++++++++++++++++ github/repos_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/github/repos.go b/github/repos.go index beb31f1..9fcd372 100644 --- a/github/repos.go +++ b/github/repos.go @@ -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 { diff --git a/github/repos_test.go b/github/repos_test.go index 0ca48b5..8b7c8fa 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -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()