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

[feat]: Output GraphQL rate limit #2807

Merged
merged 2 commits into from
Nov 13, 2023
Merged
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: 7 additions & 1 deletion Octokit.Tests.Integration/Clients/RateLimitClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class RateLimitClientTests
public async Task CanRetrieveResourceRateLimits()
{
var github = Helper.GetAuthenticatedClient();

var result = await github.RateLimit.GetRateLimits();

// Test the core limits
Expand All @@ -26,6 +25,13 @@ public async Task CanRetrieveResourceRateLimits()
Assert.True(result.Resources.Search.ResetAsUtcEpochSeconds > 0);
Assert.NotEqual(default, result.Resources.Search.Reset);

// Test the graphql limits
Assert.True(result.Resources.Graphql.Limit > 0);
Assert.True(result.Resources.Graphql.Remaining > -1);
Assert.True(result.Resources.Graphql.Remaining <= result.Resources.Graphql.Limit);
Assert.True(result.Resources.Graphql.ResetAsUtcEpochSeconds > 0);
Assert.NotEqual(default, result.Resources.Graphql.Reset);

// Test the depreciated rate limits
Assert.True(result.Rate.Limit > 0);
Assert.True(result.Rate.Remaining > -1);
Expand Down
14 changes: 12 additions & 2 deletions Octokit.Tests/Clients/MiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public async Task RequestsTheResourceRateLimitEndpoint()
var rateLimit = new MiscellaneousRateLimit(
new ResourceRateLimit(
new RateLimit(5000, 4999, 1372700873),
new RateLimit(30, 18, 1372700873)
new RateLimit(30, 18, 1372700873),
new RateLimit(5000, 4999, 1372700873)
),
new RateLimit(100, 75, 1372700873)
);
var apiConnection = Substitute.For<IApiConnection>();
apiConnection.Get<MiscellaneousRateLimit>(Arg.Is<Uri>(u => u.ToString() == "rate_limit")).Returns(Task.FromResult(rateLimit));

var client = new MiscellaneousClient(apiConnection);

var result = await client.GetRateLimits();

// Test the core limits
Expand All @@ -125,6 +125,16 @@ public async Task RequestsTheResourceRateLimitEndpoint()
CultureInfo.InvariantCulture);
Assert.Equal(expectedReset, result.Resources.Search.Reset);

// Test the graphql limits
Assert.Equal(5000, result.Resources.Graphql.Limit);
Assert.Equal(4999, result.Resources.Graphql.Remaining);
Assert.Equal(1372700873, result.Resources.Graphql.ResetAsUtcEpochSeconds);
expectedReset = DateTimeOffset.ParseExact(
"Mon 01 Jul 2013 5:47:53 PM -00:00",
"ddd dd MMM yyyy h:mm:ss tt zzz",
CultureInfo.InvariantCulture);
Assert.Equal(expectedReset, result.Resources.Graphql.Reset);

// Test the depreciated rate limits
Assert.Equal(100, result.Rate.Limit);
Assert.Equal(75, result.Rate.Remaining);
Expand Down
13 changes: 12 additions & 1 deletion Octokit.Tests/Clients/RateLimitClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public async Task RequestsTheResourceRateLimitEndpoint()
var rateLimit = new MiscellaneousRateLimit(
new ResourceRateLimit(
new RateLimit(5000, 4999, 1372700873),
new RateLimit(30, 18, 1372700873)
new RateLimit(30, 18, 1372700873),
new RateLimit(5000, 4999, 1372700873)
),
new RateLimit(100, 75, 1372700873)
);
Expand Down Expand Up @@ -47,6 +48,16 @@ public async Task RequestsTheResourceRateLimitEndpoint()
CultureInfo.InvariantCulture);
Assert.Equal(expectedReset, result.Resources.Search.Reset);

// Test the graphql limits
Assert.Equal(5000, result.Resources.Graphql.Limit);
Assert.Equal(4999, result.Resources.Graphql.Remaining);
Assert.Equal(1372700873, result.Resources.Graphql.ResetAsUtcEpochSeconds);
expectedReset = DateTimeOffset.ParseExact(
"Mon 01 Jul 2013 5:47:53 PM -00:00",
"ddd dd MMM yyyy h:mm:ss tt zzz",
CultureInfo.InvariantCulture);
Assert.Equal(expectedReset, result.Resources.Graphql.Reset);

// Test the depreciated rate limits
Assert.Equal(100, result.Rate.Limit);
Assert.Equal(75, result.Rate.Remaining);
Expand Down
17 changes: 14 additions & 3 deletions Octokit/Models/Response/ResourceRateLimit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ public class ResourceRateLimit
{
public ResourceRateLimit() { }

public ResourceRateLimit(RateLimit core, RateLimit search)
public ResourceRateLimit(RateLimit core, RateLimit search, RateLimit graphQL)
{
Ensure.ArgumentNotNull(core, nameof(core));
Ensure.ArgumentNotNull(search, nameof(search));
Ensure.ArgumentNotNull(graphQL, nameof(graphQL));

Core = core;
Search = search;
Graphql = graphQL;
}


/// <summary>
/// Rate limits for core API (rate limit for everything except Search API)
/// Rate limits for core API
/// </summary>
public RateLimit Core { get; private set; }

Expand All @@ -27,11 +30,19 @@ public ResourceRateLimit(RateLimit core, RateLimit search)
/// </summary>
public RateLimit Search { get; private set; }

/// <summary>
/// Rate Limits for GraphQL API
/// </summary>
public RateLimit Graphql { get; private set; }



internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Core: {0}; Search: {1} ", Core.DebuggerDisplay, Search.DebuggerDisplay);
return string.Format(CultureInfo.InvariantCulture, "Core: {0}; Search: {1}; GraphQL: {2} ",
Core.DebuggerDisplay, Search.DebuggerDisplay, Graphql.DebuggerDisplay);
}
}
}
Expand Down
Loading