Skip to content

Commit c7b613c

Browse files
committed
Account for source repo name/ownership changes for nuget stats
Packages may have specified a certain owner/repo information, which can later be changed on github. Repositories can be renamed, and ownership transferred, which would now leave an inconsistency in how we report since the current info on github wouldn't match a published package. We account for this by first resolving the full name of the owner/repo we find in package metadata, which would account for any renaming that happened.
1 parent 193ef09 commit c7b613c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Commands/NuGetStatsCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using NuGet.Packaging;
1313
using NuGet.Packaging.Core;
1414
using NuGet.Protocol.Core.Types;
15+
using NuGet.Protocol.Providers;
1516
using NuGet.Versioning;
1617
using Polly;
1718
using Spectre.Console;
@@ -386,10 +387,15 @@ await Parallel.ForEachAsync(tasks, paralell, async (source, cancellation) =>
386387

387388
if (ownerRepo != null)
388389
{
390+
// Account for repo renames/ownership transfers
391+
if (await graph.QueryAsync(GraphQueries.RepositoryFullName(ownerRepo)) is { } fullName)
392+
ownerRepo = fullName;
393+
389394
// Check contributors only once per repo, since multiple packages can come out of the same repository
390395
if (!model.Repositories.ContainsKey(ownerRepo))
391396
{
392397
var contribs = await graph.QueryAsync(GraphQueries.RepositoryContributors(ownerRepo));
398+
393399
if (contribs?.Length == 0)
394400
{
395401
// Make sure we haven't exhausted the GH API rate limit

src/Core/GraphQueries.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,14 @@ ... on Organization {
886886
}
887887
};
888888

889+
/// <summary>
890+
/// Gets the current full name of the specified owner/repo (might have been renamed and/or moved to another owner).
891+
/// </summary>
892+
public static GraphQuery<string> RepositoryFullName(string ownerRepo) => new($"/repos/{ownerRepo}", ".full_name")
893+
{
894+
IsLegacy = true,
895+
};
896+
889897
/// <summary>
890898
/// Gets rate limit information.
891899
/// </summary>

0 commit comments

Comments
 (0)