Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e
return repository, resp, err
}

// GetByID fetches a repository by its numeric ID.
//
// Note: GetByID uses the undocumented GitHub API endpoint /repositories/:id.
func (s *RepositoriesService) GetByID(id int) (*Repository, *Response, error) {
u := fmt.Sprintf("repositories/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

repository := new(Repository)
resp, err := s.client.Do(req, repository)
if err != nil {
return nil, resp, err
}

return repository, resp, err
}

// Edit updates a repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/#edit
Expand Down
20 changes: 20 additions & 0 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,26 @@ func TestRepositoriesService_Get(t *testing.T) {
}
}

func TestRepositoriesService_GetByID(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/repositories/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"}}`)
})

repo, _, err := client.Repositories.GetByID(1)
if err != nil {
t.Errorf("Repositories.GetByID returned error: %v", err)
}

want := &Repository{ID: Int(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repositories.GetByID returned %+v, want %+v", repo, want)
}
}

func TestRepositoriesService_Edit(t *testing.T) {
setup()
defer teardown()
Expand Down