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 4 commits
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
48 changes: 48 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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"`

// 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 //nolint:deadcode,varcheck
integrationManifestCategory //nolint:deadcode,varcheck
sourceImportCategory //nolint:deadcode,varcheck
codeScanningUploadCategory //nolint:deadcode,varcheck
actionsRunnerRegistrationCategory //nolint:deadcode,varcheck
scimCategory //nolint:deadcode,varcheck
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since TestClient_rateLimits does not pass, I have defined unused constants.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of doing this, we actually need to use these values in the category function (lines 1127-1134 below) and in the RateLimits method (lines 1154-1163 below).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the RateLimits method (lines 1154-1163 below).

fixed a6c7bcd

in the category function (lines 1127-1134 below)

I could not figure out how to fix the category function for the following reasons...

Since there is no documentation for source_import, code_scanning_upload, actions_runner_registration, and scim, I did not know which endpoints had the rate limit set, so I did not fix category function.
#2340 (comment)


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