diff --git a/src/Konmaripo.Web.Tests.Unit/Helpers/RepositoryBuilder.cs b/src/Konmaripo.Web.Tests.Unit/Helpers/RepositoryBuilder.cs index 3f19f68..1d47394 100644 --- a/src/Konmaripo.Web.Tests.Unit/Helpers/RepositoryBuilder.cs +++ b/src/Konmaripo.Web.Tests.Unit/Helpers/RepositoryBuilder.cs @@ -22,6 +22,7 @@ public class RepositoryBuilder private bool _isPrivate = false; private DateTimeOffset _pushedDate = DateTimeOffset.Now; private string _repoUrl = ""; + private int _watcherCount = 0; public RepositoryBuilder() { @@ -48,7 +49,7 @@ public Repository Build() _createdDate, _updatedDate, repositoryPermissions, dummyInternalRepository, dummyInternalRepository, licenseMetadata, - false, false, false, false, 0, 0, false, false, false, _isArchived, 0); + false, false, false, false, 0, 0, false, false, false, _isArchived, _watcherCount); return repo; } @@ -118,6 +119,12 @@ public RepositoryBuilder WithUrlOf(string url) _repoUrl = url; return this; } + + public RepositoryBuilder WithWatcherCount(int watcherCount) + { + _watcherCount = watcherCount; + return this; + } } } diff --git a/src/Konmaripo.Web.Tests.Unit/Services/CachedGitHubServiceTests.cs b/src/Konmaripo.Web.Tests.Unit/Services/CachedGitHubServiceTests.cs index 3bb2acb..df2d607 100644 --- a/src/Konmaripo.Web.Tests.Unit/Services/CachedGitHubServiceTests.cs +++ b/src/Konmaripo.Web.Tests.Unit/Services/CachedGitHubServiceTests.cs @@ -124,7 +124,7 @@ public GitHubRepoBuilder WithId(long id) public GitHubRepo Build() { - return new GitHubRepo(_id,string.Empty,0,false,0,0,DateTimeOffset.Now,DateTimeOffset.Now, string.Empty,false,DateTimeOffset.Now, string.Empty); + return new GitHubRepo(_id,string.Empty,0,false,0,0,DateTimeOffset.Now,DateTimeOffset.Now, string.Empty,false,DateTimeOffset.Now, string.Empty, 0); } } diff --git a/src/Konmaripo.Web.Tests.Unit/Services/GitHubServiceTests.cs b/src/Konmaripo.Web.Tests.Unit/Services/GitHubServiceTests.cs index e833c32..c72de87 100644 --- a/src/Konmaripo.Web.Tests.Unit/Services/GitHubServiceTests.cs +++ b/src/Konmaripo.Web.Tests.Unit/Services/GitHubServiceTests.cs @@ -313,6 +313,27 @@ public async Task ReturnsRepoUrlFromTheGithubClient() resultUrls.Should().BeEquivalentTo(urlList); } + [Fact] + public async Task ReturnsTheWatcherCountFromTheGitHubClient() + { + var watcherCountList = new List<int> { 1, 123, 123_456 }; + + var repositoryObjects = watcherCountList.Select(watcherCount => + { + var repo = new RepositoryBuilder().WithWatcherCount(watcherCount).Build(); + return repo; + }).ToList().As<IReadOnlyList<Repository>>(); + + _mockRepoClient.Setup(x => + x.GetAllForOrg(It.IsAny<string>())) + .Returns(Task.FromResult(repositoryObjects)); + + var result = await _sut.GetRepositoriesForOrganizationAsync(); + var resultWatcherCounts = result.Select(repoResult => repoResult.WatcherCount).ToList(); + + resultWatcherCounts.Should().BeEquivalentTo(watcherCountList); + } + [Fact] public async Task UsesTheOrganizationNameFromSettings() { diff --git a/src/Konmaripo.Web/Models/GitHubRepo.cs b/src/Konmaripo.Web/Models/GitHubRepo.cs index 5bd38e7..2c0be2a 100644 --- a/src/Konmaripo.Web/Models/GitHubRepo.cs +++ b/src/Konmaripo.Web/Models/GitHubRepo.cs @@ -17,8 +17,9 @@ public class GitHubRepo public bool IsPrivate { get; } public Maybe<DateTimeOffset> PushedDate { get; } public string RepoUrl { get; } + public int WatcherCount { get; } - public GitHubRepo(long repoId, string name, int starCount, bool isArchived, int forkCount, int openIssues, DateTimeOffset createdDate, DateTimeOffset updatedDate, string description, bool isPrivate, DateTimeOffset? pushedDate, string url) + public GitHubRepo(long repoId, string name, int starCount, bool isArchived, int forkCount, int openIssues, DateTimeOffset createdDate, DateTimeOffset updatedDate, string description, bool isPrivate, DateTimeOffset? pushedDate, string url, int watcherCount) { Name = name; StarCount = starCount; @@ -32,6 +33,7 @@ public GitHubRepo(long repoId, string name, int starCount, bool isArchived, int IsPrivate = isPrivate; PushedDate = pushedDate.ToMaybe(); RepoUrl = url; + WatcherCount = watcherCount; } } } \ No newline at end of file diff --git a/src/Konmaripo.Web/Services/CachedGitHubService.cs b/src/Konmaripo.Web/Services/CachedGitHubService.cs index fc8ef70..6238a33 100644 --- a/src/Konmaripo.Web/Services/CachedGitHubService.cs +++ b/src/Konmaripo.Web/Services/CachedGitHubService.cs @@ -57,7 +57,7 @@ public async Task ArchiveRepository(long repoId, string repoName) var repos = _memoryCache.Get<List<GitHubRepo>>(RepoCacheKey); var item = repos.First(x => x.Id == repoId); - var archivedItem = new GitHubRepo(item.Id, item.Name, item.StarCount, true, item.ForkCount, item.OpenIssueCount, item.CreatedDate, item.UpdatedDate, item.Description, item.IsPrivate, item.PushedDate.ToNullable(), item.RepoUrl); + var archivedItem = new GitHubRepo(item.Id, item.Name, item.StarCount, true, item.ForkCount, item.OpenIssueCount, item.CreatedDate, item.UpdatedDate, item.Description, item.IsPrivate, item.PushedDate.ToNullable(), item.RepoUrl, item.WatcherCount); repos.Remove(item); repos.Add(archivedItem); diff --git a/src/Konmaripo.Web/Services/GitHubService.cs b/src/Konmaripo.Web/Services/GitHubService.cs index 513f3db..088fce9 100644 --- a/src/Konmaripo.Web/Services/GitHubService.cs +++ b/src/Konmaripo.Web/Services/GitHubService.cs @@ -25,7 +25,7 @@ public async Task<List<GitHubRepo>> GetRepositoriesForOrganizationAsync() var repos = await _githubClient.Repository.GetAllForOrg(orgName); - return repos.Select(x => new GitHubRepo(x.Id, x.Name, x.StargazersCount, x.Archived, x.ForksCount, x.OpenIssuesCount, x.CreatedAt, x.UpdatedAt, x.Description, x.Private, x.PushedAt, x.HtmlUrl)).ToList(); + return repos.Select(x => new GitHubRepo(x.Id, x.Name, x.StargazersCount, x.Archived, x.ForksCount, x.OpenIssuesCount, x.CreatedAt, x.UpdatedAt, x.Description, x.Private, x.PushedAt, x.HtmlUrl, x.WatchersCount)).ToList(); } public async Task<ExtendedRepoInformation> GetExtendedRepoInformationFor(long repoId) diff --git a/src/Konmaripo.Web/Views/Sunsetting/Index.cshtml b/src/Konmaripo.Web/Views/Sunsetting/Index.cshtml index 16b9025..b848d77 100644 --- a/src/Konmaripo.Web/Views/Sunsetting/Index.cshtml +++ b/src/Konmaripo.Web/Views/Sunsetting/Index.cshtml @@ -14,6 +14,7 @@ <th scope="col"><!--Private icon--></th> <th scope="col">Name</th> <th scope="col" title="Stars"><i class="fas fa-star"></i></th> + <th scope="col" title="Watchers"><i class="fas fa-eye"></i></th> <th scope="col" title="Forks"><i class="fas fa-code-branch"></i></th> <th scope="col" title="Issues"><i class="fas fa-exclamation-circle"></i></th> <th scope="col" title="Date the repository was created">Created</th> @@ -49,7 +50,7 @@ } else { - <td>Never</td> + <td>Never</td> } </tr> } diff --git a/src/Konmaripo.Web/Views/Sunsetting/Repo.cshtml b/src/Konmaripo.Web/Views/Sunsetting/Repo.cshtml index 9d9c9c8..9f8d0ca 100644 --- a/src/Konmaripo.Web/Views/Sunsetting/Repo.cshtml +++ b/src/Konmaripo.Web/Views/Sunsetting/Repo.cshtml @@ -16,6 +16,7 @@ <th scope="col"><!--Private icon--></th> <th scope="col">Name</th> <th scope="col" title="Stars"><i class="fas fa-star"></i></th> + <th scope="col" title="Watchers"><i class="fas fa-eye"></i></th> <th scope="col" title="Forks"><i class="fas fa-code-branch"></i></th> <th scope="col" title="Issues"><i class="fas fa-exclamation-circle"></i></th> <th scope="col" title="Date the repository was created">Created</th> @@ -40,6 +41,7 @@ } <th scope="row" title="@item.Description"><a href="@item.RepoUrl" target="_blank"><i class="fas fa-external-link-alt"></i></a> @item.Name</th> <td>@item.StarCount</td> + <td>@item.WatcherCount</td> <td>@item.ForkCount</td> <td>@item.OpenIssueCount</td> <td title="@item.CreatedDate">@item.CreatedDate.Humanize()</td> @@ -64,7 +66,7 @@ <table class="table table-striped"> <thead class="thead-dark"> <tr> - <th scope="col">Number of Watchers</th> + <th scope="col">Watchers</th> <th scope="col">Views in Past 14 days</th> <th scope="col">Commit Activity in Last 4 Weeks</th> </tr>