Browse Source

Add ListParticipation and clean up some typos

ttacon 12 years ago
parent
commit
8bab7de236
2 changed files with 93 additions and 4 deletions
  1. +42
    -3
      github/repos_stats.go
  2. +51
    -1
      github/repos_stats_test.go

+ 42
- 3
github/repos_stats.go View File

@ -25,7 +25,7 @@ type WeeklyHash struct {
}
// ListContributorsStats gets a repo's contributor list with additions, deletions and commit counts.
// If this is the first time these statistics are requested for the given repository, this will method
// If this is the first time these statistics are requested for the given repository, this method
// will return a non-nil error and a status code of 202. This is because this is the status that github
// returns to signify that it is now computing the requested statistics. A follow up request, after
// a delay of a second or so, should result in a successful request.
@ -55,10 +55,10 @@ type WeeklyCommitActivity struct {
Week *int `json:"week,omitempty"`
}
// ListLastYearCommitActivity returns the last year of commit activity
// ListCommitActivity returns the last year of commit activity
// grouped by week. The days array is a group of commits per day,
// starting on Sunday. If this is the first time these statistics are
// requested for the given repository, this will method will return a
// requested for the given repository, this method will return a
// non-nil error and a status code of 202. This is because this is the
// status that github returns to signify that it is now computing the
// requested statistics. A follow up request, after a delay of a second
@ -80,3 +80,42 @@ func (s *RepositoriesService) ListCommitActivity(owner, repo string) (*[]WeeklyC
return weeklyCommitActivity, resp, err
}
// RepositoryParticipation is the number of commits by everyone
// who has contributed to the repository (including the owner)
// as well as the number of commits by the owner themself.
type RepositoryParticipation struct {
All []int `json:"all,omitempty"`
Owner []int `json:"owner,omitempty"`
}
// ListParticipation returns the total commit counts for the 'owner'
// and total commit counts in 'all'. 'all' is everyone combined,
// including the 'owner' in the last 52 weeks. If you’d like to get
// the commit counts for non-owners, you can subtract 'all' from 'owner'.
//
// The array order is oldest week (index 0) to most recent week.
//
// If this is the first time these statistics are requested for the given
// repository, this method will return a non-nil error and a status code
// of 202. This is because this is the status that github returns to
// signify that it is now computing the requested statistics. A follow
// up request, after a delay of a second or so, should result in a
// successful request.
//
// GitHub API Docs: https://developer.github.com/v3/repos/statistics/#participation
func (s *RepositoriesService) ListParticipation(owner, repo string) (*RepositoryParticipation, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/stats/participation", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
participation := new(RepositoryParticipation)
resp, err := s.client.Do(req, participation)
if err != nil {
return nil, resp, err
}
return participation, resp, err
}

+ 51
- 1
github/repos_stats_test.go View File

@ -1,4 +1,4 @@
// Copyright 2013 The go-github AUTHORS. All rights reserved.
// Copyright 2014 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@ -101,3 +101,53 @@ func TestRepositoriesService_ListCommitActivity(t *testing.T) {
t.Errorf("RepositoriesService.ListCommitActivity returned %+v, want %+v", activity, want)
}
}
func TestRepositoriesService_Participation(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/repos/o/r/stats/participation", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `
{
"all": [
11,21,15,2,8,1,8,23,17,21,11,10,33,
91,38,34,22,23,32,3,43,87,71,18,13,5,
13,16,66,27,12,45,110,117,13,8,18,9,19,
26,39,12,20,31,46,91,45,10,24,9,29,7
],
"owner": [
3,2,3,0,2,0,5,14,7,9,1,5,0,
48,19,2,0,1,10,2,23,40,35,8,8,2,
10,6,30,0,2,9,53,104,3,3,10,4,7,
11,21,4,4,22,26,63,11,2,14,1,10,3
]
}
`)
})
participation, _, err := client.Repositories.ListParticipation("o", "r")
if err != nil {
t.Errorf("RepositoriesService.ListParticipation returned error: %v", err)
}
want := &RepositoryParticipation{
All: []int{
11, 21, 15, 2, 8, 1, 8, 23, 17, 21, 11, 10, 33,
91, 38, 34, 22, 23, 32, 3, 43, 87, 71, 18, 13, 5,
13, 16, 66, 27, 12, 45, 110, 117, 13, 8, 18, 9, 19,
26, 39, 12, 20, 31, 46, 91, 45, 10, 24, 9, 29, 7,
},
Owner: []int{
3, 2, 3, 0, 2, 0, 5, 14, 7, 9, 1, 5, 0,
48, 19, 2, 0, 1, 10, 2, 23, 40, 35, 8, 8, 2,
10, 6, 30, 0, 2, 9, 53, 104, 3, 3, 10, 4, 7,
11, 21, 4, 4, 22, 26, 63, 11, 2, 14, 1, 10, 3,
},
}
if !reflect.DeepEqual(participation, want) {
t.Errorf("RepositoriesService.ListParticipation returned %+v, want %+v", participation, want)
}
}

Loading…
Cancel
Save