-
Notifications
You must be signed in to change notification settings - Fork 643
/
BackfillRepositoryMetadataCommand.cs
56 lines (48 loc) · 1.85 KB
/
BackfillRepositoryMetadataCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.CommandLineUtils;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Services.Entities;
using NuGetGallery;
namespace GalleryTools.Commands
{
public sealed class BackfillRepositoryMetadataCommand : BackfillCommand<RepositoryMetadata>
{
protected override string MetadataFileName => "repositoryMetadata.txt";
public static void Configure(CommandLineApplication config)
{
Configure<BackfillRepositoryMetadataCommand>(config);
}
protected override RepositoryMetadata ReadMetadata(NuspecReader reader)
{
return reader.GetRepositoryMetadata();
}
protected override bool ShouldWriteMetadata(RepositoryMetadata metadata)
{
return !string.IsNullOrEmpty(metadata.Branch)
|| !string.IsNullOrEmpty(metadata.Commit)
|| !string.IsNullOrEmpty(metadata.Type)
|| !string.IsNullOrEmpty(metadata.Url);
}
protected override void ConfigureClassMap(PackageMetadataClassMap map)
{
map.Map(x => x.Metadata.Type).Index(3);
map.Map(x => x.Metadata.Url).Index(4);
map.Map(x => x.Metadata.Branch).Index(5);
map.Map(x => x.Metadata.Commit).Index(6);
}
protected override void UpdatePackage(Package package, RepositoryMetadata metadata, EntitiesContext context)
{
package.RepositoryUrl = metadata.Url;
if (metadata.Type.Length >= 100)
{
// TODO: Log error.
}
else
{
package.RepositoryType = metadata.Type;
}
}
}
}