Skip to content

Commit

Permalink
Allow most package information fields to be overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Ensslen committed Jul 8, 2024
1 parent a010cac commit 6393832
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

namespace NuGetUtility.PackageInformationReader
{
public record struct CustomPackageInformation(string Id, INuGetVersion Version, string License);
public record struct CustomPackageInformation(string Id, INuGetVersion Version, string License, string? Copyright = null, string? Authors = null, string? Title = null, string? ProjectUrl = null, string? Summary = null, string? Description = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private PackageSearchResult TryGetPackageInfoFromCustomInformation(PackageIdenti
return new PackageSearchResult();
}

return new PackageSearchResult(new PackageMetadata(package, resolvedCustomInformation.License, LicenseType.Overwrite));
return new PackageSearchResult(new PackageMetadata(package, LicenseType.Overwrite, resolvedCustomInformation));
}

private static async Task<IPackageMetadataResource?> TryGetPackageMetadataResource(ISourceRepository repository)
Expand Down
19 changes: 11 additions & 8 deletions src/NuGetUtility/PackageInformationReader/PackageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@ public PackageMetadata(PackageIdentity identity)
Identity = identity;
}

public PackageMetadata(PackageIdentity identity, string licenseIdentifier, LicenseType licenseType)
public PackageMetadata(PackageIdentity identity, LicenseType licenseType, CustomPackageInformation customPackageInformation)
{
Identity = identity;
LicenseMetadata = new LicenseMetadata(licenseType, licenseIdentifier);
LicenseMetadata = new LicenseMetadata(licenseType, customPackageInformation.License);
CustomPackageInformation = customPackageInformation;
}

private CustomPackageInformation? CustomPackageInformation { get; }

public PackageIdentity Identity { get; }

public string Title { get; } = string.Empty;
public string? Title => CustomPackageInformation?.Title;

public Uri? LicenseUrl => null;

public string ProjectUrl => string.Empty;
public string? ProjectUrl => CustomPackageInformation?.ProjectUrl;

public string Description => string.Empty;
public string? Description => CustomPackageInformation?.Description;

public string Summary => string.Empty;
public string? Summary => CustomPackageInformation?.Summary;

public string Copyright => string.Empty;
public string? Copyright => CustomPackageInformation?.Copyright;

public string Authors => string.Empty;
public string? Authors => CustomPackageInformation?.Authors;

public LicenseMetadata? LicenseMetadata { get; } = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace NuGetUtility.Wrapper.NuGetWrapper.Packaging
public interface IPackageMetadata
{
PackageIdentity Identity { get; }
string Title { get; }
string? Title { get; }
Uri? LicenseUrl { get; }
string ProjectUrl { get; }
string Description { get; }
string Summary { get; }
string Copyright { get; }
string Authors { get; }
string? ProjectUrl { get; }
string? Description { get; }
string? Summary { get; }
string? Copyright { get; }
string? Authors { get; }
LicenseMetadata? LicenseMetadata { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public WrappedPackageSearchMetadata(IPackageSearchMetadata searchMetadata)

public PackageIdentity Identity { get; }

public string Title => _searchMetadata.Title;
public string? Title => _searchMetadata.Title;

public Uri? LicenseUrl => _searchMetadata.LicenseUrl;

public string ProjectUrl => _searchMetadata.ProjectUrl?.ToString() ?? string.Empty;
public string? ProjectUrl => _searchMetadata.ProjectUrl?.ToString();

public string Description => _searchMetadata.Description;
public string? Description => _searchMetadata.Description;

public string Summary => _searchMetadata.Summary;
public string? Summary => _searchMetadata.Summary;

public string Copyright => string.Empty;
public string? Copyright => null;

public string Authors => _searchMetadata.Authors;
public string? Authors => _searchMetadata.Authors;

public LicenseMetadata? LicenseMetadata { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public WrappedPackageMetadata(ManifestMetadata metadata)

public PackageIdentity Identity { get; }

public string Title => _metadata.Title;
public string? Title => _metadata.Title;

public Uri? LicenseUrl => _metadata.LicenseUrl;

public string ProjectUrl => _metadata.ProjectUrl?.ToString() ?? string.Empty;
public string? ProjectUrl => _metadata.ProjectUrl?.ToString();

public string Description => _metadata.Description;
public string? Description => _metadata.Description;

public string Summary => _metadata.Summary;
public string? Summary => _metadata.Summary;

public string Copyright => _metadata.Copyright;
public string? Copyright => _metadata.Copyright;

public string Authors => string.Join(",", _metadata.Authors); // https://learn.microsoft.com/en-us/nuget/reference/nuspec#authors
public string? Authors => string.Join(",", _metadata.Authors); // https://learn.microsoft.com/en-us/nuget/reference/nuspec#authors

public Packaging.LicenseMetadata? LicenseMetadata { get; }
}
Expand Down

0 comments on commit 6393832

Please sign in to comment.