Skip to content

Commit

Permalink
Add fields to RateLimits struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
shokada committed Apr 24, 2022
1 parent 00e4233 commit 942d33d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 6 deletions.
21 changes: 19 additions & 2 deletions github/github.go
Expand Up @@ -1082,15 +1082,26 @@ type RateLimits struct {
// requests are limited to 60 per hour. Authenticated requests are
// limited to 5,000 per hour.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/#rate-limiting
// GitHub API docs: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
Core *Rate `json:"core"`

// The rate limit for search API requests. Unauthenticated requests
// are limited to 10 requests per minutes. Authenticated requests are
// limited to 30 per minute.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/search/#rate-limit
// GitHub API docs: https://docs.github.com/en/rest/search#rate-limit
Search *Rate `json:"search"`

// GitHub API docs: https://docs.github.com/en/graphql/overview/resource-limitations#rate-limit
Graphql *Rate `json:"graphql"`

// GitHub API dos: https://docs.github.com/en/rest/rate-limit
IntegrationManifest *Rate `json:"integration_manifest"`

SourceImport *Rate `json:"source_import"`
CodeScanningUpload *Rate `json:"code_scanning_upload"`
ActionsRunnerRegistration *Rate `json:"actions_runner_registration"`
Scim *Rate `json:"scim"`
}

func (r RateLimits) String() string {
Expand All @@ -1102,6 +1113,12 @@ type rateLimitCategory uint8
const (
coreCategory rateLimitCategory = iota
searchCategory
graphqlCategory
integrationManifestCategory
sourceImportCategory
codeScanningUploadCategory
actionsRunnerRegistrationCategory
scimCategory

categories // An array of this length will be able to contain all rate limit categories.
)
Expand Down
74 changes: 70 additions & 4 deletions github/github_test.go
Expand Up @@ -474,10 +474,16 @@ func TestClient_rateLimits(t *testing.T) {

func TestRateLimits_String(t *testing.T) {
v := RateLimits{
Core: &Rate{},
Search: &Rate{},
}
want := `github.RateLimits{Core:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, Search:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}}`
Core: &Rate{},
Search: &Rate{},
Graphql: &Rate{},
IntegrationManifest: &Rate{},
SourceImport: &Rate{},
CodeScanningUpload: &Rate{},
ActionsRunnerRegistration: &Rate{},
Scim: &Rate{},
}
want := `github.RateLimits{Core:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, Search:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, Graphql:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, IntegrationManifest:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, SourceImport:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, CodeScanningUpload:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, ActionsRunnerRegistration:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}, Scim:github.Rate{Limit:0, Remaining:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}}}`
if got := v.String(); got != want {
t.Errorf("RateLimits.String = %v, want %v", got, want)
}
Expand Down Expand Up @@ -2394,6 +2400,36 @@ func TestRateLimits_Marshal(t *testing.T) {
Remaining: 1,
Reset: Timestamp{referenceTime},
},
Graphql: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
IntegrationManifest: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
SourceImport: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
CodeScanningUpload: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
ActionsRunnerRegistration: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
Scim: &Rate{
Limit: 1,
Remaining: 1,
Reset: Timestamp{referenceTime},
},
}

want := `{
Expand All @@ -2406,6 +2442,36 @@ func TestRateLimits_Marshal(t *testing.T) {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"graphql": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"integration_manifest": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"source_import": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"code_scanning_upload": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"actions_runner_registration": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
},
"scim": {
"limit": 1,
"remaining": 1,
"reset": ` + referenceTimeStr + `
}
}`

Expand Down

0 comments on commit 942d33d

Please sign in to comment.