Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fields to RateLimits struct #2340

Merged
merged 5 commits into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
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
gmlewis marked this conversation as resolved.
Show resolved Hide resolved
Search *Rate `json:"search"`

// GitHub API docs: https://docs.github.com/en/graphql/overview/resource-limitations#rate-limit
Graphql *Rate `json:"graphql"`
gmlewis marked this conversation as resolved.
Show resolved Hide resolved

// 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"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no document for source_import, code_scanning_upload, actions_runner_registration, scim.

gmlewis marked this conversation as resolved.
Show resolved Hide resolved
}

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