From 9597c7dd43e6caa3dea942526c42df24226c0449 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 29 Jul 2013 09:49:05 -0700 Subject: [PATCH] Fix URL for CreateTree There shouldn't be a SHA in the URL Also rename 'user' to 'owner' --- github/git.go | 22 +++++++++++----------- github/git_test.go | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/github/git.go b/github/git.go index 830444b..31890bc 100644 --- a/github/git.go +++ b/github/git.go @@ -32,17 +32,11 @@ type TreeEntry struct { Size int `json:"size,omitempty"` } -// createTree represents the body of a CreateTree request. -type createTree struct { - BaseTree string `json:base_tree` - Entries []TreeEntry `json:tree` -} - -// GetTree fetches the Tree object for a given sha hash from a users repository. +// GetTree fetches the Tree object for a given sha hash from a repository. // // GitHub API docs: http://developer.github.com/v3/git/trees/#get-a-tree -func (s *GitService) GetTree(user string, repo string, sha string, recursive bool) (*Tree, error) { - u := fmt.Sprintf("repos/%v/%v/git/trees/%v", user, repo, sha) +func (s *GitService) GetTree(owner string, repo string, sha string, recursive bool) (*Tree, error) { + u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha) if recursive { u += "?recursive=1" } @@ -57,13 +51,19 @@ func (s *GitService) GetTree(user string, repo string, sha string, recursive boo return t, err } +// createTree represents the body of a CreateTree request. +type createTree struct { + BaseTree string `json:base_tree` + Entries []TreeEntry `json:tree` +} + // CreateTree creates a new tree in a repository. If both a tree and a nested // path modifying that tree are specified, it will overwrite the contents of // that tree with the new path contents and write a new tree out. // // GitHub API docs: http://developer.github.com/v3/git/trees/#create-a-tree -func (s *GitService) CreateTree(owner string, repo string, sha string, baseTree string, entries []TreeEntry) (*Tree, error) { - u := fmt.Sprintf("repos/%v/%v/git/trees/%v", owner, repo, sha) +func (s *GitService) CreateTree(owner string, repo string, baseTree string, entries []TreeEntry) (*Tree, error) { + u := fmt.Sprintf("repos/%v/%v/git/trees", owner, repo) body := &createTree{ BaseTree: baseTree, diff --git a/github/git_test.go b/github/git_test.go index c813f19..167e4a6 100644 --- a/github/git_test.go +++ b/github/git_test.go @@ -17,7 +17,7 @@ func TestGitService_GetTree(t *testing.T) { setup() defer teardown() - mux.HandleFunc("/repos/u/r/git/trees/s", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/repos/o/r/git/trees/s", func(w http.ResponseWriter, r *http.Request) { if m := "GET"; m != r.Method { t.Errorf("Request method = %v, want %v", r.Method, m) } @@ -27,7 +27,7 @@ func TestGitService_GetTree(t *testing.T) { }`) }) - tree, err := client.Git.GetTree("u", "r", "s", true) + tree, err := client.Git.GetTree("o", "r", "s", true) if err != nil { t.Errorf("Git.GetTree returned error: %v", err) } @@ -58,7 +58,7 @@ func TestGitService_CreateTree(t *testing.T) { }, } - mux.HandleFunc("/repos/u/r/git/trees/s", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/repos/o/r/git/trees", func(w http.ResponseWriter, r *http.Request) { v := new(createTree) json.NewDecoder(r.Body).Decode(v) @@ -88,7 +88,7 @@ func TestGitService_CreateTree(t *testing.T) { }`) }) - tree, err := client.Git.CreateTree("u", "r", "s", "b", input) + tree, err := client.Git.CreateTree("o", "r", "b", input) if err != nil { t.Errorf("Git.CreateTree returned error: %v", err) }