Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from brminnick/Add-Time-Range
Browse files Browse the repository at this point in the history
Fix Date Range Support
  • Loading branch information
brminnick authored Jan 4, 2021
2 parents a6bb87f + 87b23ed commit 729ce8b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 3 additions & 0 deletions AzureAdvocates.Functions/AzureAdvocates.Functions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous,
{
log.LogInformation($"{nameof(GetMicrosoftLearnContributors)} Started");

var timeSpan = to - from;
if (timeSpan.TotalDays > 365)
return new BadRequestObjectResult($"Invalid Timespan: {timeSpan.TotalDays} days. Timespan must be less than 365 days");

var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(2));
var gitHubApiStatus = await _gitHubApiStatusService.GetApiRateLimits(cancellationTokenSource.Token).ConfigureAwait(false);
if (gitHubApiStatus.GraphQLApi.RemainingRequestCount < 4000)
Expand Down Expand Up @@ -71,7 +67,7 @@ public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous,
var cloudAdvocateContributions = new List<GitHubContributorModel>();
foreach (var cloudAdvocate in cloudAdvocateList)
{
var cloudAdvocateContributorModel = new GitHubContributorModel(microsoftLearnPullRequests.Where(x => x.Author.Equals(cloudAdvocate.GitHubUserName, StringComparison.OrdinalIgnoreCase)), cloudAdvocate);
var cloudAdvocateContributorModel = new GitHubContributorModel(microsoftLearnPullRequests.Where(x => x.Author.Equals(cloudAdvocate.GitHubUserName, StringComparison.OrdinalIgnoreCase) && x.CreatedAt.IsWithinRange(from, to)), cloudAdvocate);

cloudAdvocateContributions.Add(cloudAdvocateContributorModel);

Expand All @@ -81,4 +77,9 @@ public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous,
return new OkObjectResult(cloudAdvocateContributions);
}
}

static class DateTimeExtensions
{
public static bool IsWithinRange(this DateTimeOffset dateTimeOffset, DateTimeOffset start, DateTimeOffset end) => dateTimeOffset >= start && dateTimeOffset <= end;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class GitHubGraphQLApiService
{
readonly static IReadOnlyList<(string Owner, string Repository)> _microsoftLearnRepositories = new[]
{
("microsoftdocs", "learn-bizapps-pr"),
("microsoftdocs", "learnshared"),
("microsoftdocs", "learn-certs-pr"),
("microsoftdocs", "learn-dynamics-pr"),
("microsoftdocs", "learn-m365-pr"),
("microsoftdocs", "learn-bizapps-pr"),
("microsoftdocs", "learn-dynamics-pr"),
("microsoftdocs", "learn-pr"),
("microsoftdocs", "learnshared")
};

readonly IGitHubGraphQLApiClient _gitHubGraphQLApiClient;
Expand Down
3 changes: 0 additions & 3 deletions GitHubReadmeWebTrends.Common/Services/StartupService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using GitHubApiStatus.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Polly.Extensions.Http;
using Refit;

namespace GitHubReadmeWebTrends.Common
Expand Down

0 comments on commit 729ce8b

Please sign in to comment.