Skip to content

Commit

Permalink
Merge pull request #8553 from NuGet/dev
Browse files Browse the repository at this point in the history
[ReleasePrep][2021.04.26] RI of dev into main
  • Loading branch information
drewgillies authored May 5, 2021
2 parents cdb13af + 534245d commit f248171
Show file tree
Hide file tree
Showing 17 changed files with 146 additions and 90 deletions.
12 changes: 9 additions & 3 deletions src/GalleryTools/Commands/BackfillCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Xml;
using System.Xml.Linq;
using GalleryTools.Utils;
using Microsoft.IdentityModel.JsonWebTokens;
using NuGet.Services.Sql;

namespace GalleryTools.Commands
Expand Down Expand Up @@ -116,8 +117,7 @@ public async Task Collect(SqlConnection connection, Uri serviceDiscoveryUri, Dat

var repository = new EntityRepository<Package>(context);

var packages = repository.GetAll()
.Include(p => p.PackageRegistration);
var packages = repository.GetAll().Include(p => p.PackageRegistration);
if (QueryIncludes != null)
{
packages = packages.Include(QueryIncludes);
Expand Down Expand Up @@ -233,6 +233,10 @@ public async Task Update(SqlConnection connection, string fileName)
var repository = new EntityRepository<Package>(context);

var packages = repository.GetAll().Include(p => p.PackageRegistration);
if (QueryIncludes != null)
{
packages = packages.Include(QueryIncludes);
}

using (var csv = CreateCsvReader(fileName))
{
Expand Down Expand Up @@ -355,7 +359,9 @@ private CsvReader CreateCsvReader(string fileName)

var reader = new StreamReader(fileName);

return new CsvReader(reader, configuration);
var csvReader = new CsvReader(reader, configuration);
csvReader.Configuration.MissingFieldFound = null;
return csvReader;
}

private Configuration CreateCsvConfiguration()
Expand Down
56 changes: 28 additions & 28 deletions src/GalleryTools/Commands/BackfillTfmMetadataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,31 @@ protected override List<string> ReadMetadata(IList<string> files, NuspecReader n
try
{
supportedFrameworks = _packageService.GetSupportedFrameworks(nuspecReader, files);
}
catch (ArgumentException)
{
// do nothing--this is a known scenario and we'll skip this package quietly, which will give us a more useful error log file
}

foreach (var tfm in supportedFrameworks)
{
// We wrap this in a try-catch because some poorly-crafted portable TFMs will make it through GetSupportedFrameworks and fail here, e.g. for a
// non-existent profile name like "Profile1", which will cause GetShortFolderName to throw. We want to fail silently for these as this is a known
// scenario (more useful error log) and not failing will allow us to still capture all of the valid TFMs.
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs#L297
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs#L487 }
try
foreach (var tfm in supportedFrameworks)
{
var tfmToAdd = tfm.ToShortNameOrNull();
if (!string.IsNullOrEmpty(tfmToAdd))
// We wrap this in a try-catch because some poorly-crafted portable TFMs will make it through GetSupportedFrameworks and fail here, e.g. for a
// non-existent profile name like "Profile1", which will cause GetShortFolderName to throw. We want to fail silently for these as this is a known
// scenario (more useful error log) and not failing will allow us to still capture all of the valid TFMs.
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/NuGetFramework.cs#L297
// See https://github.com/NuGet/NuGet.Client/blob/ba008e14611f4fa518c2d02ed78dfe5969e4a003/src/NuGet.Core/NuGet.Frameworks/FrameworkNameProvider.cs#L487 }
try
{
supportedTFMs.Add(tfmToAdd);
var tfmToAdd = tfm.ToShortNameOrNull();
if (!string.IsNullOrEmpty(tfmToAdd))
{
supportedTFMs.Add(tfmToAdd);
}
}
catch
{
// skip this TFM and only collect well-formatted ones
}
}
catch
{
// skip this TFM and only collect well-formatted ones
}
}
catch (ArgumentException)
{
// do nothing--this is a known scenario and we'll skip this package quietly, which will give us a more useful error log file
}

return supportedTFMs;
}
Expand All @@ -79,17 +78,18 @@ protected override void UpdatePackage(Package package, List<string> metadata, En
{
// Note that extracting old TFMs may throw for formatting reasons. In this case we'll force a full replacement by leaving the collection empty.
var existingTFMs = Enumerable.Empty<string>();
if (package.SupportedFrameworks != null)
try
{
try
{
existingTFMs = package.SupportedFrameworks.Select(f => f.FrameworkName.GetShortFolderName()).OrderBy(f => f);
}
catch
if (package.SupportedFrameworks != null)
{
// do nothing and replace in full
// We'll force this enumerable to a list to force all potential throws
existingTFMs = package.SupportedFrameworks.Select(f => f.FrameworkName.GetShortFolderName()).OrderBy(f => f).ToList();
}
}
catch
{
// do nothing and replace in full
}

var newTFMs = metadata == null || metadata.Count == 0
? Enumerable.Empty<string>()
Expand Down
12 changes: 12 additions & 0 deletions src/NuGetGallery/App_Data/Files/Content/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@
"SiteAdmins": false,
"Accounts": [],
"Domains": []
},
"NuGetGallery.EmbeddedIcons": {
"All": true,
"SiteAdmins": false,
"Accounts": [],
"Domains": []
},
"NuGetGallery.EmbeddedReadmes": {
"All": true,
"SiteAdmins": false,
"Accounts": [],
"Domains": []
}
}
}
6 changes: 5 additions & 1 deletion src/NuGetGallery/App_Start/AppActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ private static void BundlingPostStart()
.Include("~/Scripts/gallery/clamp.js");
BundleTable.Bundles.Add(displayPackageScriptBundle);

var listPackagesScriptBundle = new ScriptBundle("~/Scripts/gallery/page-list-packages.min.js")
.Include("~/Scripts/gallery/page-list-packages.js");
BundleTable.Bundles.Add(listPackagesScriptBundle);

var managePackagesScriptBundle = new ScriptBundle("~/Scripts/gallery/page-manage-packages.min.js")
.Include("~/Scripts/gallery/page-manage-packages.js");
BundleTable.Bundles.Add(managePackagesScriptBundle);
Expand Down Expand Up @@ -265,7 +269,7 @@ private static void BackgroundJobsPostStart(IAppConfiguration configuration)
if (cloudDownloadCountService != null)
{
// Perform initial refresh + schedule new refreshes every 15 minutes
HostingEnvironment.QueueBackgroundWorkItem(_ => cloudDownloadCountService.Refresh());
HostingEnvironment.QueueBackgroundWorkItem(_ => cloudDownloadCountService.RefreshAsync());
jobs.Add(new CloudDownloadCountServiceRefreshJob(TimeSpan.FromMinutes(15), cloudDownloadCountService));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
<div class="form-field">
<label for="editIssueComment">Add comment</label>
<textarea id="editIssueComment" name="editIssueComment" data-bind="value: editIssueComment" rows="10"
placeholder="Add a comment..." autocomplete="off" autofocus></textarea>
placeholder="Add a comment. If resolving a DMCA request add offender account names (in single quotes, comma-delimited), offending package id, and resolution (no action, withdrawn, upheld). Example: accounts:'foo1','foo2' id:BarPkg resolution: upheld"
autocomplete="off" autofocus></textarea>
</div>
</fieldset>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CloudDownloadCountServiceRefreshJob(TimeSpan interval, CloudDownloadCount

public override Task Execute()
{
return new Task(async () => { await _downloadCountService.Refresh(); });
return new Task(async () => { await _downloadCountService.RefreshAsync(); });
}
}
}
1 change: 1 addition & 0 deletions src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@
<Content Include="App_Data\Files\Content\Symbols-Configuration.json" />
<Content Include="Scripts\gallery\instrumentation.js" />
<Content Include="Scripts\gallery\knockout-3.5.1.js" />
<Content Include="Scripts\gallery\page-list-packages.js" />
<Content Include="Views\Shared\SiteMenu.cshtml">
<SubType>Code</SubType>
</Content>
Expand Down
17 changes: 17 additions & 0 deletions src/NuGetGallery/Scripts/gallery/page-list-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$(function() {
'use strict';

$(".reserved-indicator").each(
function() {
var checkmarkImage = $(this);
checkmarkImage.popover({ trigger: 'hover focus' });
checkmarkImage.click(function() {
checkmarkImage.popover('show');
setTimeout(function() {
checkmarkImage.popover('destroy');
},
1000);
});
}
);
});
10 changes: 5 additions & 5 deletions src/NuGetGallery/Services/CloudDownloadCountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public bool TryGetDownloadCountForPackage(string id, string version, out int dow
return false;
}

public async Task Refresh()
public async Task RefreshAsync()
{
bool shouldRefresh = false;
lock (_refreshLock)
Expand All @@ -104,7 +104,7 @@ public async Task Refresh()
try
{
var stopwatch = Stopwatch.StartNew();
await RefreshCore();
await RefreshCoreAsync();
stopwatch.Stop();
_telemetryService.TrackDownloadJsonRefreshDuration(stopwatch.ElapsedMilliseconds);

Expand Down Expand Up @@ -148,19 +148,19 @@ protected virtual int CalculateSum(ConcurrentDictionary<string, int> versions)
/// This method is added for unit testing purposes. It can return a null stream if the blob does not exist
/// and assumes the caller will properly dispose of the returned stream.
/// </summary>
protected virtual async Task<Stream> GetBlobStream()
protected virtual async Task<Stream> GetBlobStreamAsync()
{
var blob = GetBlobReference();
return await blob.OpenReadIfExistsAsync();
}

private async Task RefreshCore()
private async Task RefreshCoreAsync()
{
try
{
// The data in downloads.v1.json will be an array of Package records - which has Id, Array of Versions and download count.
// Sample.json : [["AutofacContrib.NSubstitute",["2.4.3.700",406],["2.5.0",137]],["Assman.Core",["2.0.7",138]]....
using (var blobStream = await GetBlobStream())
using (var blobStream = await GetBlobStreamAsync())
{
if (blobStream == null)
{
Expand Down
32 changes: 16 additions & 16 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -726,20 +726,20 @@
<table aria-label="Version History of @Model.Id" class="table borderless">
<thead>
<tr>
<th>Version</th>
<th>Downloads</th>
<th>Last updated</th>
<th scope="col">Version</th>
<th scope="col">Downloads</th>
<th scope="col">Last updated</th>
@if (Model.CanDisplayPrivateMetadata)
{
<th>Status</th>
<th scope="col">Status</th>
}
@if (Model.IsCertificatesUIEnabled)
{
<th aria-hidden="true" abbr="Signature Information"></th>
<th scope="col" aria-hidden="true" abbr="Signature Information"></th>
}
@if (Model.IsPackageDeprecationEnabled || Model.IsPackageVulnerabilitiesEnabled)
{
<th aria-hidden="true" abbr="Package Warnings"></th>
<th scope="col" aria-hidden="true" abbr="Package Warnings"></th>
}
</tr>
</thead>
Expand All @@ -759,15 +759,15 @@
rowCount++;
@VersionListDivider(rowCount, versionsExpanded)
<tr class="@(packageVersion.IsCurrent(Model) ? "bg-info" : null)">
<td>
<td tabindex="0">
<a href="@Url.Package(packageVersion)" title="@packageVersion.FullVersion">
@packageVersion.Version.Abbreviate(30)
</a>
</td>
<td>
<td tabindex="0">
@packageVersion.DownloadCount.ToNuGetNumberString()
</td>
<td>
<td tabindex="0">
<span data-datetime="@packageVersion.LastUpdated.ToString("O")">@packageVersion.LastUpdated.ToNuGetShortDateString()</span>
@if (packageVersion.PushedBy != null)
{
Expand All @@ -780,7 +780,7 @@
{
var packageStatusSummary = packageVersion.PackageStatusSummary;

<td>
<td tabindex="0">
@if (packageStatusSummary == PackageStatusSummary.Listed ||
packageStatusSummary == PackageStatusSummary.Unlisted)
{
Expand All @@ -801,7 +801,7 @@
}
else
{
<td class="package-icon-cell">
<td tabindex="0" class="package-icon-cell">
<i class="ms-Icon ms-Icon--Ribbon package-icon" title="@packageVersion.SignatureInformation"></i>
</td>
}
Expand All @@ -813,7 +813,7 @@
}
else
{
<td class="package-icon-cell">
<td tabindex="0" class="package-icon-cell">
<i class="ms-Icon ms-Icon--Warning package-icon" title="@packageVersion.PackageWarningIconTitle"></i>
</td>
}
Expand All @@ -824,16 +824,16 @@
rowCount++;
@VersionListDivider(rowCount, versionsExpanded)
<tr class="deleted">
<td class="version">
<td tabindex="0" class="version">
@packageVersion.Version
</td>
<td>
<td tabindex="0">
@packageVersion.DownloadCount
</td>
<td>
<td tabindex="0">
<span data-datetime="@packageVersion.LastUpdated.ToString("O")">@packageVersion.LastUpdated.ToNuGetShortDateString()</span>
</td>
<td>
<td tabindex="0">
Deleted
</td>
<td colspan="2"></td>
Expand Down
14 changes: 9 additions & 5 deletions src/NuGetGallery/Views/Packages/UploadPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
@ViewHelpers.AjaxAntiForgeryToken(Html)
@ViewHelpers.PackagesBreadcrumb(Url, CurrentUser, true, @<text>Upload</text>)
<div class="text-left">
<p class="message">Your package file will be uploaded and hosted on the @(Config.Current.Brand) server (@(Config.Current.SiteRoot)).</p>
<p class="message">Your package file will be uploaded and on the @(Config.Current.Brand) server (@(Config.Current.SiteRoot)).</p>
<p class="message">
To learn more about authoring great packages, view our
<a href="https://docs.microsoft.com/nuget/create-packages/package-authoring-best-practices" alt="Best Practices" aria-label="Read here about publishing packages">Best Practices</a> page.
</p>
</div>
<div id="upload-package-container">
<h2>
Expand Down Expand Up @@ -60,10 +64,10 @@
</div>
}

<div id="symbols-replace-warning-container" class="hidden">
@ViewHelpers.AlertWarning(@<text>There is an existing symbols package (.snupkg) for the below package ID and version.
Submitting this request will replace the previously uploaded symbols package as well as the corresponding symbol files from the symbol server.</text>)
</div>
<div id="symbols-replace-warning-container" class="hidden">
@ViewHelpers.AlertWarning(@<text>There is an existing symbols package (.snupkg) for the below package ID and version.
Submitting this request will replace the previously uploaded symbols package as well as the corresponding symbol files from the symbol server.</text>)
</div>

@Html.Partial("_VerifyForm")
</div>
Expand Down
Loading

0 comments on commit f248171

Please sign in to comment.