Skip to content

Commit

Permalink
Account for source repo name/ownership changes for nuget stats
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kzu committed Oct 4, 2024
1 parent 193ef09 commit c7b613c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Commands/NuGetStatsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Protocol.Core.Types;
using NuGet.Protocol.Providers;
using NuGet.Versioning;
using Polly;
using Spectre.Console;
Expand Down Expand Up @@ -386,10 +387,15 @@ await Parallel.ForEachAsync(tasks, paralell, async (source, cancellation) =>

if (ownerRepo != null)
{
// Account for repo renames/ownership transfers
if (await graph.QueryAsync(GraphQueries.RepositoryFullName(ownerRepo)) is { } fullName)
ownerRepo = fullName;

// Check contributors only once per repo, since multiple packages can come out of the same repository
if (!model.Repositories.ContainsKey(ownerRepo))
{
var contribs = await graph.QueryAsync(GraphQueries.RepositoryContributors(ownerRepo));

if (contribs?.Length == 0)
{
// Make sure we haven't exhausted the GH API rate limit
Expand Down
8 changes: 8 additions & 0 deletions src/Core/GraphQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,14 @@ ... on Organization {
}
};

/// <summary>
/// Gets the current full name of the specified owner/repo (might have been renamed and/or moved to another owner).
/// </summary>
public static GraphQuery<string> RepositoryFullName(string ownerRepo) => new($"/repos/{ownerRepo}", ".full_name")
{
IsLegacy = true,
};

/// <summary>
/// Gets rate limit information.
/// </summary>
Expand Down

0 comments on commit c7b613c

Please sign in to comment.