Browse Source

Fix URL for CreateTree

There shouldn't be a SHA in the URL
Also rename 'user' to 'owner'
Will Norris 13 years ago
parent
commit
9597c7dd43
2 changed files with 15 additions and 15 deletions
  1. +11
    -11
      github/git.go
  2. +4
    -4
      github/git_test.go

+ 11
- 11
github/git.go View File

@ -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,


+ 4
- 4
github/git_test.go View File

@ -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)
}


Loading…
Cancel
Save