Skip to content

Commit 8e31c67

Browse files
committed
[GH Usage] Moved sorting logic to NuGetPackage info class
1 parent 596ab1a commit 8e31c67

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/NuGetGallery.Core/GitHub/GitHubUsageConfiguration.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace NuGetGallery.GitHub
66
{
77
public class GitHubUsageConfiguration : IGitHubUsageConfiguration
88
{
9-
public const int ReposPerPackage = 10;
109
private readonly Dictionary<string, NuGetPackageGitHubInformation> _nuGetPackagesGitHubDependencies;
1110

1211
public GitHubUsageConfiguration(IReadOnlyList<RepositoryInformation> repositories)
@@ -56,9 +55,7 @@ private static Dictionary<string, NuGetPackageGitHubInformation> GetNuGetPackage
5655
entry => entry.Key,
5756
entry => new NuGetPackageGitHubInformation(
5857
entry.Value.Count,
59-
entry.Value
60-
.OrderByDescending(x => x.Stars)
61-
.ThenBy(x => x.Id).Take(ReposPerPackage).ToList()),
58+
entry.Value),
6259
StringComparer.InvariantCultureIgnoreCase);
6360
}
6461
}

src/NuGetGallery.Core/GitHub/NuGetPackageGitHubInformation.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace NuGetGallery.GitHub
66
{
77
public class NuGetPackageGitHubInformation
88
{
9+
public const int ReposPerPackage = 10;
10+
911
public readonly static NuGetPackageGitHubInformation Empty = new NuGetPackageGitHubInformation(
1012
0,
1113
new List<RepositoryInformation>());
@@ -17,8 +19,17 @@ public NuGetPackageGitHubInformation(int totalRepos, IReadOnlyList<RepositoryInf
1719
throw new IndexOutOfRangeException(string.Format("{0} cannot have a negative value!", nameof(totalRepos)));
1820
}
1921

22+
if( repos == null)
23+
{
24+
throw new ArgumentNullException(nameof(repos));
25+
}
26+
2027
TotalRepos = totalRepos;
21-
Repos = repos ?? throw new ArgumentNullException(nameof(repos));
28+
Repos = repos
29+
.OrderByDescending(x => x.Stars)
30+
.ThenBy(x => x.Id)
31+
.Take(ReposPerPackage)
32+
.ToList();
2233
}
2334

2435
public int TotalRepos { get; }

src/NuGetGallery.Core/GitHub/RepositoryInformation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public RepositoryInformation(
2626
}
2727
else
2828
{
29-
throw new ArgumentException(string.Format("{0} has an invalid format! It should be \"owner/repositoryName\", instead it is: {1}", nameof(Id), Id));
29+
throw new ArgumentException(string.Format("{0} has an invalid format! It should be \"owner/repositoryName\"!", nameof(Id)));
3030
}
3131

3232
Url = url ?? throw new ArgumentNullException(nameof(url));

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@
522522
@(Model.Id), including the following:
523523
</p>
524524

525-
@foreach (var dep in Model.GitHubDependenciesInformation.Repos.Take(10))
525+
@foreach (var dep in Model.GitHubDependenciesInformation.Repos)
526526
{
527527
<div class="row top-buffer">
528528
<div class="col-xs-12">

tests/NuGetGallery.Core.Facts/GitHub/GitHubUsageConfigurationFacts.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private static GitHubUsageConfiguration GenConfig(params RepositoryInformation[]
2020
{
2121
return new GitHubUsageConfiguration(repos);
2222
}
23+
2324
public class TheConstructor
2425
{
2526
[Fact]
@@ -31,7 +32,6 @@ public void InvalidRepoCache()
3132

3233
public class TheGetPackageInformationMethod
3334
{
34-
3535
[Fact]
3636
public void EmptyRepoCache()
3737
{
@@ -106,7 +106,7 @@ public void MultiReposSameDependencyOrderedByStarCount()
106106
var gh = GenConfig(expectedRepos);
107107
var nupkgInformation = gh.GetPackageInformation("nupkg1");
108108

109-
Assert.Equal(Math.Min(expectedRepos.Length, GitHubUsageConfiguration.ReposPerPackage), nupkgInformation.Repos.Count);
109+
Assert.Equal(Math.Min(expectedRepos.Length, NuGetPackageGitHubInformation.ReposPerPackage), nupkgInformation.Repos.Count);
110110
Assert.Equal(expectedRepos.Length, nupkgInformation.TotalRepos);
111111

112112
// Make sure they're ordered by descending order of stars
@@ -140,7 +140,7 @@ public void OrderedByStarCountThenByIdThenTrimmed()
140140
var gh = GenConfig(expectedRepos);
141141
var nupkgInformation = gh.GetPackageInformation("nupkg1");
142142

143-
Assert.Equal(Math.Min(expectedRepos.Length, GitHubUsageConfiguration.ReposPerPackage), nupkgInformation.Repos.Count);
143+
Assert.Equal(Math.Min(expectedRepos.Length, NuGetPackageGitHubInformation.ReposPerPackage), nupkgInformation.Repos.Count);
144144
Assert.Equal(expectedRepos.Length, nupkgInformation.TotalRepos);
145145

146146
Assert.Equal(

0 commit comments

Comments
 (0)