Browse Source

Add support for RepositoriesService ListBranches

Chris Schaefer 12 years ago
committed by Will Norris
parent
commit
871e9750ea
3 changed files with 46 additions and 0 deletions
  1. +1
    -0
      github/git_commits.go
  2. +25
    -0
      github/repos.go
  3. +20
    -0
      github/repos_test.go

+ 1
- 0
github/git_commits.go View File

@ -19,6 +19,7 @@ type Commit struct {
Tree *Tree `json:"tree,omitempty"`
Parents []Commit `json:"parents,omitempty"`
Stats *CommitStats `json:"stats,omitempty"`
URL *string `json:url,omitempty"`
}
func (c Commit) String() string {


+ 25
- 0
github/repos.go View File

@ -309,3 +309,28 @@ func (s *RepositoriesService) ListLanguages(owner string, repository string) (ma
return languages, resp, err
}
// Branch represents a repository branch
type Branch struct {
Name *string `json:"name,omitempty"`
Commit *Commit
}
// ListBranches lists branches for the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/#list-branches
func (s *RepositoriesService) ListBranches(owner string, repository string) ([]Branch, *Response, error) {
u := fmt.Sprintf("/repos/%v/%v/branches", owner, repository)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
branches := new([]Branch)
resp, err := s.client.Do(req, branches)
if err != nil {
return nil, resp, err
}
return *branches, resp, err
}

+ 20
- 0
github/repos_test.go View File

@ -286,6 +286,26 @@ func TestRepositoriesService_ListLanguages(t *testing.T) {
}
}
func TestRepositoriesService_ListBranches(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/branches", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"name":"master", "commit" : {"sha" : "a57781", "url" : "https://api.github.com/repos/o/r/commits/a57781"}}]`)
})
branches, _, err := client.Repositories.ListBranches("o", "r")
if err != nil {
t.Errorf("Repositories.ListBranches returned error: %v", err)
}
want := []Branch{{Name: String("master"), Commit: &Commit{SHA: String("a57781"), URL: String("https://api.github.com/repos/o/r/commits/a57781")}}}
if !reflect.DeepEqual(branches, want) {
t.Errorf("Repositories.ListBranches returned %+v, want %+v", branches, want)
}
}
func TestRepositoriesService_ListLanguages_invalidOwner(t *testing.T) {
_, _, err := client.Repositories.ListLanguages("%", "%")
testURLParseError(t, err)


Loading…
Cancel
Save