From b890f757318b0b6cef5d1a1234818ff07cb7f6ba Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Tue, 23 Jun 2020 16:05:03 -0400 Subject: [PATCH 1/7] Add timezone ID that defaults to Eastern --- src/Konmaripo.Web/appsettings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Konmaripo.Web/appsettings.json b/src/Konmaripo.Web/appsettings.json index a0ccb9c..16430ce 100644 --- a/src/Konmaripo.Web/appsettings.json +++ b/src/Konmaripo.Web/appsettings.json @@ -1,7 +1,8 @@ { "GitHubSettings": { "AccessToken": "CHANGE_ME", - "OrganizationName": "CHANGE_ME" + "OrganizationName": "CHANGE_ME", + "TimeZoneDisplayId": "US Eastern Standard Time" }, "AzureAd": { "Instance": "https://login.microsoftonline.com/", From 83c896ffd63e27bce883aab40b6a7d40747d2460 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Tue, 23 Jun 2020 16:05:15 -0400 Subject: [PATCH 2/7] Add settings --- src/Konmaripo.Web/Models/GitHubSettings.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Konmaripo.Web/Models/GitHubSettings.cs b/src/Konmaripo.Web/Models/GitHubSettings.cs index f44b0ba..54a1e9e 100644 --- a/src/Konmaripo.Web/Models/GitHubSettings.cs +++ b/src/Konmaripo.Web/Models/GitHubSettings.cs @@ -1,8 +1,12 @@ -namespace Konmaripo.Web.Models +using System; +using System.Linq; + +namespace Konmaripo.Web.Models { public class GitHubSettings { public string AccessToken { get; set; } public string OrganizationName { get; set; } + public string TimeZoneDisplayId { get; set; } } } \ No newline at end of file From 219b0c7782e89bd4d0d438b7d37dcce579374596 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Tue, 23 Jun 2020 16:05:27 -0400 Subject: [PATCH 3/7] Implement the API token date return --- src/Konmaripo.Web/Services/CachedGitHubService.cs | 5 +++++ src/Konmaripo.Web/Services/GitHubService.cs | 10 ++++++++++ src/Konmaripo.Web/Services/IGitHubService.cs | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Konmaripo.Web/Services/CachedGitHubService.cs b/src/Konmaripo.Web/Services/CachedGitHubService.cs index 397ce6a..55cc107 100644 --- a/src/Konmaripo.Web/Services/CachedGitHubService.cs +++ b/src/Konmaripo.Web/Services/CachedGitHubService.cs @@ -79,5 +79,10 @@ public Task CreateIssueInRepo(NewIssue issue, long repoId) { return _gitHubService.CreateIssueInRepo(issue, repoId); } + + public DateTimeOffset APITokenResetTime() + { + return _gitHubService.APITokenResetTime(); + } } } diff --git a/src/Konmaripo.Web/Services/GitHubService.cs b/src/Konmaripo.Web/Services/GitHubService.cs index f75046f..21db3ed 100644 --- a/src/Konmaripo.Web/Services/GitHubService.cs +++ b/src/Konmaripo.Web/Services/GitHubService.cs @@ -88,5 +88,15 @@ public Task CreateIssueInRepo(NewIssue issue, long repoId) { return _githubClient.Issue.Create(repoId, issue); } + + public DateTimeOffset APITokenResetTime() + { + var reset = _githubClient.GetLastApiInfo().RateLimit.Reset; + var timeZoneToConvertTo = TimeZoneInfo.FindSystemTimeZoneById(_gitHubSettings.TimeZoneDisplayId); + + var resultingTime = TimeZoneInfo.ConvertTime(reset, timeZoneToConvertTo); + + return resultingTime; + } } } diff --git a/src/Konmaripo.Web/Services/IGitHubService.cs b/src/Konmaripo.Web/Services/IGitHubService.cs index 92bdef7..45a9560 100644 --- a/src/Konmaripo.Web/Services/IGitHubService.cs +++ b/src/Konmaripo.Web/Services/IGitHubService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using Konmaripo.Web.Models; using Octokit; @@ -14,5 +15,6 @@ public interface IGitHubService Task GetRepoQuotaForOrg(); int RemainingAPIRequests(); Task CreateIssueInRepo(NewIssue issue, long repoId); + DateTimeOffset APITokenResetTime(); } } \ No newline at end of file From 5acb1c0cd37636e74395da7f986fc12a1f4f97f2 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Tue, 23 Jun 2020 16:05:42 -0400 Subject: [PATCH 4/7] Use the call to the reset time and add to VM --- src/Konmaripo.Web/Controllers/MassIssuesController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Konmaripo.Web/Controllers/MassIssuesController.cs b/src/Konmaripo.Web/Controllers/MassIssuesController.cs index 184436c..460c0bb 100644 --- a/src/Konmaripo.Web/Controllers/MassIssuesController.cs +++ b/src/Konmaripo.Web/Controllers/MassIssuesController.cs @@ -37,17 +37,19 @@ public class MassIssueViewModel public MassIssue MassIssue { get; set; } public int NonArchivedRepos { get; set; } public int RemainingAPIRequests { get; set; } + public DateTimeOffset APITokenResetTime { get; set; } // ReSharper disable once UnusedMember.Global public MassIssueViewModel() { // This is here because the model binding uses it } - public MassIssueViewModel(MassIssue massIssue, int nonArchivedRepos, int remainingApiRequests) + public MassIssueViewModel(MassIssue massIssue, int nonArchivedRepos, int remainingApiRequests, DateTimeOffset apiTokenResetTime) { MassIssue = massIssue; NonArchivedRepos = nonArchivedRepos; RemainingAPIRequests = remainingApiRequests; + APITokenResetTime = apiTokenResetTime; } } @@ -68,10 +70,11 @@ public MassIssuesController(ILogger logger, IGitHubService gitHubService, IMassI public async Task Index() { var remainingRequests = _gitHubService.RemainingAPIRequests(); + var tokenResetTime = _gitHubService.APITokenResetTime(); var nonArchivedRepos = await NonArchivedReposCount(); var issue = new MassIssue(string.Empty, string.Empty); - var vm = new MassIssueViewModel(issue, nonArchivedRepos, remainingRequests); + var vm = new MassIssueViewModel(issue, nonArchivedRepos, remainingRequests, tokenResetTime); return View(vm); } @@ -87,6 +90,7 @@ public async Task Index(MassIssueViewModel vm) vm.MassIssue.IssueBody = vm.MassIssue.IssueBody; vm.NonArchivedRepos = nonArchivedReposCount; vm.RemainingAPIRequests = _gitHubService.RemainingAPIRequests(); + vm.APITokenResetTime = _gitHubService.APITokenResetTime(); return View(vm); } From 184d5c32fd187203a547fbc199eb7c671504e5b8 Mon Sep 17 00:00:00 2001 From: Sean Killeen Date: Tue, 23 Jun 2020 16:05:48 -0400 Subject: [PATCH 5/7] Update view to humanize datetime --- src/Konmaripo.Web/Views/MassIssues/Index.cshtml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Konmaripo.Web/Views/MassIssues/Index.cshtml b/src/Konmaripo.Web/Views/MassIssues/Index.cshtml index 65f3a00..d4d8b95 100644 --- a/src/Konmaripo.Web/Views/MassIssues/Index.cshtml +++ b/src/Konmaripo.Web/Views/MassIssues/Index.cshtml @@ -1,4 +1,5 @@ -@model Konmaripo.Web.Controllers.MassIssueViewModel +@using Humanizer +@model Konmaripo.Web.Controllers.MassIssueViewModel @{ ViewData["Title"] = "Home Page"; } @@ -40,7 +41,7 @@

Double-check: Distribution

This will be sent to @Model.NonArchivedRepos repositories

-

We have @Model.RemainingAPIRequests API requests remaining before it resets.

+

We have @Model.RemainingAPIRequests API requests remaining before it resets @Model.APITokenResetTime.Humanize().