Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/github-accessors.go

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

8 changes: 8 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.

6 changes: 6 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ const (
DependencySnapshotsCategory
CodeSearchCategory
AuditLogCategory
DependencySBOMCategory

Categories // An array of this length will be able to contain all rate limit categories.
)
Expand Down Expand Up @@ -1573,6 +1574,11 @@ func GetRateLimitCategory(method, path string) RateLimitCategory {
// https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/orgs?apiVersion=2022-11-28#get-the-audit-log-for-an-organization
case strings.HasSuffix(path, "/audit-log"):
return AuditLogCategory

// https://docs.github.com/en/rest/dependency-graph/sboms?apiVersion=2022-11-28#export-a-software-bill-of-materials-sbom-for-a-repository
case strings.HasPrefix(path, "/repos/") &&
strings.HasSuffix(path, "/dependency-graph/sbom"):
return DependencySBOMCategory
}
}

Expand Down
5 changes: 5 additions & 0 deletions github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,11 @@ func TestDo_rateLimitCategory(t *testing.T) {
url: "/orgs/google/audit-log",
category: AuditLogCategory,
},
{
method: "GET",
url: "/repos/google/go-github/dependency-graph/sbom",
category: DependencySBOMCategory,
},
// missing a check for actionsRunnerRegistrationCategory: API not found
}

Expand Down
4 changes: 4 additions & 0 deletions github/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type RateLimits struct {
DependencySnapshots *Rate `json:"dependency_snapshots"`
CodeSearch *Rate `json:"code_search"`
AuditLog *Rate `json:"audit_log"`
DependencySBOM *Rate `json:"dependency_sbom"`
}

func (r RateLimits) String() string {
Expand Down Expand Up @@ -126,6 +127,9 @@ func (s *RateLimitService) Get(ctx context.Context) (*RateLimits, *Response, err
if response.Resources.AuditLog != nil {
s.client.rateLimits[AuditLogCategory] = *response.Resources.AuditLog
}
if response.Resources.DependencySBOM != nil {
s.client.rateLimits[DependencySBOMCategory] = *response.Resources.DependencySBOM
}
s.client.rateMu.Unlock()
}

Expand Down
41 changes: 38 additions & 3 deletions github/rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func TestRateLimits_String(t *testing.T) {
DependencySnapshots: &Rate{},
CodeSearch: &Rate{},
AuditLog: &Rate{},
DependencySBOM: &Rate{},
}
want := `github.RateLimits{Core:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, Search:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, GraphQL:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, IntegrationManifest:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, SourceImport:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, CodeScanningUpload:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, ActionsRunnerRegistration:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, SCIM:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, DependencySnapshots:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, CodeSearch:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, AuditLog:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}}`
want := `github.RateLimits{Core:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, Search:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, GraphQL:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, IntegrationManifest:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, SourceImport:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, CodeScanningUpload:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, ActionsRunnerRegistration:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, SCIM:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, DependencySnapshots:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, CodeSearch:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, AuditLog:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}, DependencySBOM:github.Rate{Limit:0, Remaining:0, Used:0, Reset:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Resource:""}}`
if got := v.String(); got != want {
t.Errorf("RateLimits.String = %v, want %v", got, want)
}
Expand All @@ -52,7 +53,8 @@ func TestRateLimits(t *testing.T) {
"scim": {"limit":9,"remaining":8,"used":1,"reset":1372700880},
"dependency_snapshots": {"limit":10,"remaining":9,"used":1,"reset":1372700881},
"code_search": {"limit":11,"remaining":10,"used":1,"reset":1372700882},
"audit_log": {"limit": 12,"remaining":11,"used":1,"reset":1372700883}
"audit_log": {"limit": 12,"remaining":11,"used":1,"reset":1372700883},
"dependency_sbom": {"limit": 100,"remaining":100,"used":0,"reset":1372700884}
}}`)
})

Expand Down Expand Up @@ -129,6 +131,12 @@ func TestRateLimits(t *testing.T) {
Used: 1,
Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 3, 0, time.UTC).Local()},
},
DependencySBOM: &Rate{
Limit: 100,
Remaining: 100,
Used: 0,
Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 4, 0, time.UTC).Local()},
},
}
if !cmp.Equal(rate, want) {
t.Errorf("RateLimits returned %+v, want %+v", rate, want)
Expand Down Expand Up @@ -181,6 +189,10 @@ func TestRateLimits(t *testing.T) {
category: AuditLogCategory,
rate: want.AuditLog,
},
{
category: DependencySBOMCategory,
rate: want.DependencySBOM,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -225,7 +237,8 @@ func TestRateLimits_overQuota(t *testing.T) {
"scim": {"limit":9,"remaining":8,"used":1,"reset":1372700880},
"dependency_snapshots": {"limit":10,"remaining":9,"used":1,"reset":1372700881},
"code_search": {"limit":11,"remaining":10,"used":1,"reset":1372700882},
"audit_log": {"limit":12,"remaining":11,"used":1,"reset":1372700883}
"audit_log": {"limit":12,"remaining":11,"used":1,"reset":1372700883},
"dependency_sbom": {"limit":13,"remaining":12,"used":1,"reset":1372700884}
}}`)
})

Expand Down Expand Up @@ -302,6 +315,12 @@ func TestRateLimits_overQuota(t *testing.T) {
Used: 1,
Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 3, 0, time.UTC).Local()},
},
DependencySBOM: &Rate{
Limit: 13,
Remaining: 12,
Used: 1,
Reset: Timestamp{time.Date(2013, time.July, 1, 17, 48, 4, 0, time.UTC).Local()},
},
}
if !cmp.Equal(rate, want) {
t.Errorf("RateLimits returned %+v, want %+v", rate, want)
Expand Down Expand Up @@ -355,6 +374,10 @@ func TestRateLimits_overQuota(t *testing.T) {
category: AuditLogCategory,
rate: want.AuditLog,
},
{
category: DependencySBOMCategory,
rate: want.DependencySBOM,
},
}
for _, tt := range tests {
if got, want := client.rateLimits[tt.category], *tt.rate; got != want {
Expand Down Expand Up @@ -434,6 +457,12 @@ func TestRateLimits_Marshal(t *testing.T) {
Used: 0,
Reset: Timestamp{referenceTime},
},
DependencySBOM: &Rate{
Limit: 1,
Remaining: 1,
Used: 0,
Reset: Timestamp{referenceTime},
},
}

want := `{
Expand Down Expand Up @@ -502,6 +531,12 @@ func TestRateLimits_Marshal(t *testing.T) {
"remaining": 1,
"used": 0,
"reset": ` + referenceTimeStr + `
},
"dependency_sbom": {
"limit": 1,
"remaining": 1,
"used": 0,
"reset": ` + referenceTimeStr + `
}
}`

Expand Down
Loading