-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create GetGitTrendsStatistics API (#241)
* Create GetGitTrendsStatistics * Update GitTrendsStatisticsService to use Azure Functions Backend * Fix GitTrendsStatisticsServiceTests
- Loading branch information
1 parent
b9a3317
commit 26014eb
Showing
15 changed files
with
124 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Threading.Tasks; | ||
using GitTrends.Shared; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GitTrends.Functions | ||
{ | ||
class GetGitTrendsStatistics | ||
{ | ||
readonly BlobStorageService _blobStorageService; | ||
|
||
public GetGitTrendsStatistics(BlobStorageService blobStorageService) => _blobStorageService = blobStorageService; | ||
|
||
[FunctionName(nameof(GetGitTrendsStatistics))] | ||
public Task<GitTrendsStatisticsDTO> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest request, ILogger log) => _blobStorageService.GetGitTrendsStatistics(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
GitTrends.Functions/Functions/UpdateGitTrendsStatistics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GitTrends.Shared; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GitTrends.Functions | ||
{ | ||
class UpdateGitTrendsStatistics | ||
{ | ||
readonly GitHubApiV3Service _gitHubApiV3Service; | ||
readonly BlobStorageService _blobStorageService; | ||
|
||
public UpdateGitTrendsStatistics(GitHubApiV3Service gitHubApiV3Service, BlobStorageService blobStorageService) => | ||
(_gitHubApiV3Service, _blobStorageService) = (gitHubApiV3Service, blobStorageService); | ||
|
||
[FunctionName(nameof(UpdateGitTrendsStatistics))] | ||
public async Task Run([TimerTrigger("0 0 0 * * *")] TimerInfo myTimer, ILogger log) | ||
{ | ||
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(2)); | ||
|
||
var getRepositoryTask = _gitHubApiV3Service.GetRepository(GitHubConstants.GitTrendsRepoOwner, GitHubConstants.GitTrendsRepoName, cancellationTokenSource.Token); | ||
var getGitTrendsContributorsTask = _gitHubApiV3Service.GetGitTrendsContributors(cancellationTokenSource.Token); | ||
|
||
await Task.WhenAll(getRepositoryTask, getGitTrendsContributorsTask).ConfigureAwait(false); | ||
|
||
var repository = await getRepositoryTask.ConfigureAwait(false); | ||
var contributors = await getGitTrendsContributorsTask.ConfigureAwait(false); | ||
|
||
var statistics = new GitTrendsStatisticsDTO(new Uri(repository.Url ?? throw new NullReferenceException()), | ||
repository.StarCount ?? throw new NullReferenceException(), | ||
repository.WatchersCount, | ||
repository.ForkCount, | ||
contributors); | ||
|
||
var blobName = $"Statistics_{DateTime.UtcNow:o}.json"; | ||
log.LogInformation($"Saving Statistics to Blob Storage: {blobName}"); | ||
|
||
await _blobStorageService.UploadStatistics(statistics, blobName).ConfigureAwait(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GitTrends.Shared | ||
{ | ||
public record GitTrendsStatisticsDTO(Uri GitHubUri, long Stars, long Watchers, long Forks, IReadOnlyList<Contributor> Contributors); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters