Source File
repos_stats.go
Belonging Package
github.com/google/go-github/v66/github
// 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.package githubimport ()// ContributorStats represents a contributor to a repository and their// weekly contributions to a given repo.type ContributorStats struct {Author *Contributor `json:"author,omitempty"`Total *int `json:"total,omitempty"`Weeks []*WeeklyStats `json:"weeks,omitempty"`}func ( ContributorStats) () string {return Stringify()}// WeeklyStats represents the number of additions, deletions and commits// a Contributor made in a given week.type WeeklyStats struct {Week *Timestamp `json:"w,omitempty"`Additions *int `json:"a,omitempty"`Deletions *int `json:"d,omitempty"`Commits *int `json:"c,omitempty"`}func ( WeeklyStats) () string {return Stringify()}// 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 method will return an *AcceptedError 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://docs.github.com/rest/metrics/statistics#get-all-contributor-commit-activity////meta:operation GET /repos/{owner}/{repo}/stats/contributorsfunc ( *RepositoriesService) ( context.Context, , string) ([]*ContributorStats, *Response, error) {:= fmt.Sprintf("repos/%v/%v/stats/contributors", , ), := .client.NewRequest("GET", , nil)if != nil {return nil, nil,}var []*ContributorStats, := .client.Do(, , &)if != nil {return nil, ,}return , , nil}// WeeklyCommitActivity represents the weekly commit activity for a repository.// The days array is a group of commits per day, starting on Sunday.type WeeklyCommitActivity struct {Days []int `json:"days,omitempty"`Total *int `json:"total,omitempty"`Week *Timestamp `json:"week,omitempty"`}func ( WeeklyCommitActivity) () string {return Stringify()}// 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 method will return an *AcceptedError 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://docs.github.com/rest/metrics/statistics#get-the-last-year-of-commit-activity////meta:operation GET /repos/{owner}/{repo}/stats/commit_activityfunc ( *RepositoriesService) ( context.Context, , string) ([]*WeeklyCommitActivity, *Response, error) {:= fmt.Sprintf("repos/%v/%v/stats/commit_activity", , ), := .client.NewRequest("GET", , nil)if != nil {return nil, nil,}var []*WeeklyCommitActivity, := .client.Do(, , &)if != nil {return nil, ,}return , , nil}// ListCodeFrequency returns a weekly aggregate of the number of additions and// deletions pushed to a repository. Returned WeeklyStats will contain// additions and deletions, but not total commits.//// If this is the first time these statistics are requested for the given// repository, this method will return an *AcceptedError 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://docs.github.com/rest/metrics/statistics#get-the-weekly-commit-activity////meta:operation GET /repos/{owner}/{repo}/stats/code_frequencyfunc ( *RepositoriesService) ( context.Context, , string) ([]*WeeklyStats, *Response, error) {:= fmt.Sprintf("repos/%v/%v/stats/code_frequency", , ), := .client.NewRequest("GET", , nil)if != nil {return nil, nil,}var [][]int, := .client.Do(, , &)if != nil {return nil, ,}// convert int slices into WeeklyStatsvar []*WeeklyStatsfor , := range {if len() != 3 {continue}:= &WeeklyStats{Week: &Timestamp{time.Unix(int64([0]), 0)},Additions: Int([1]),Deletions: Int([2]),}= append(, )}return , , nil}// 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"`}func ( RepositoryParticipation) () string {return Stringify()}// 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 an *AcceptedError 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://docs.github.com/rest/metrics/statistics#get-the-weekly-commit-count////meta:operation GET /repos/{owner}/{repo}/stats/participationfunc ( *RepositoriesService) ( context.Context, , string) (*RepositoryParticipation, *Response, error) {:= fmt.Sprintf("repos/%v/%v/stats/participation", , ), := .client.NewRequest("GET", , nil)if != nil {return nil, nil,}:= new(RepositoryParticipation), := .client.Do(, , )if != nil {return nil, ,}return , , nil}// PunchCard represents the number of commits made during a given hour of a// day of the week.type PunchCard struct {Day *int // Day of the week (0-6: =Sunday - Saturday).Hour *int // Hour of day (0-23).Commits *int // Number of commits.}// ListPunchCard returns the number of commits per hour in each day.//// If this is the first time these statistics are requested for the given// repository, this method will return an *AcceptedError 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://docs.github.com/rest/metrics/statistics#get-the-hourly-commit-count-for-each-day////meta:operation GET /repos/{owner}/{repo}/stats/punch_cardfunc ( *RepositoriesService) ( context.Context, , string) ([]*PunchCard, *Response, error) {:= fmt.Sprintf("repos/%v/%v/stats/punch_card", , ), := .client.NewRequest("GET", , nil)if != nil {return nil, nil,}var [][]int, := .client.Do(, , &)if != nil {return nil, ,}// convert int slices into Punchcardsvar []*PunchCardfor , := range {if len() != 3 {continue}:= &PunchCard{Day: Int([0]),Hour: Int([1]),Commits: Int([2]),}= append(, )}return , , nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |