Browse Source

Add support for Activities.ListStargazers response with timestamp.

Add custom header to request to get an alternate response with star creation timestamp.

Solves #319
Closes #320
Andrew Ryabchun 10 years ago
committed by Will Norris
parent
commit
eea6140a0a
2 changed files with 14 additions and 4 deletions
  1. +11
    -2
      github/activity_star.go
  2. +3
    -2
      github/activity_star_test.go

+ 11
- 2
github/activity_star.go View File

@ -13,10 +13,16 @@ type StarredRepository struct {
Repository *Repository `json:"repo,omitempty"`
}
// Stargazer represents a user that has starred a repository.
type Stargazer struct {
StarredAt *Timestamp `json:"starred_at,omitempty"`
User *User `json:"user,omitempty"`
}
// ListStargazers lists people who have starred the specified repo.
//
// GitHub API Docs: https://developer.github.com/v3/activity/starring/#list-stargazers
func (s *ActivityService) ListStargazers(owner, repo string, opt *ListOptions) ([]User, *Response, error) {
func (s *ActivityService) ListStargazers(owner, repo string, opt *ListOptions) ([]Stargazer, *Response, error) {
u := fmt.Sprintf("repos/%s/%s/stargazers", owner, repo)
u, err := addOptions(u, opt)
if err != nil {
@ -28,7 +34,10 @@ func (s *ActivityService) ListStargazers(owner, repo string, opt *ListOptions) (
return nil, nil, err
}
stargazers := new([]User)
// TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeStarringPreview)
stargazers := new([]Stargazer)
resp, err := s.client.Do(req, stargazers)
if err != nil {
return nil, resp, err


+ 3
- 2
github/activity_star_test.go View File

@ -19,11 +19,12 @@ func TestActivityService_ListStargazers(t *testing.T) {
mux.HandleFunc("/repos/o/r/stargazers", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeStarringPreview)
testFormValues(t, r, values{
"page": "2",
})
fmt.Fprint(w, `[{"id":1}]`)
fmt.Fprint(w, `[{"starred_at":"2002-02-10T15:30:00Z","user":{"id":1}}]`)
})
stargazers, _, err := client.Activity.ListStargazers("o", "r", &ListOptions{Page: 2})
@ -31,7 +32,7 @@ func TestActivityService_ListStargazers(t *testing.T) {
t.Errorf("Activity.ListStargazers returned error: %v", err)
}
want := []User{{ID: Int(1)}}
want := []Stargazer{{StarredAt: &Timestamp{time.Date(2002, time.February, 10, 15, 30, 0, 0, time.UTC)}, User: &User{ID: Int(1)}}}
if !reflect.DeepEqual(stargazers, want) {
t.Errorf("Activity.ListStargazers returned %+v, want %+v", stargazers, want)
}


Loading…
Cancel
Save