|
13 | 13 | using Microsoft.IdentityModel.JsonWebTokens; |
14 | 14 | using System; |
15 | 15 | using System.Collections.Frozen; |
| 16 | +using System.Collections.Generic; |
16 | 17 | using System.Diagnostics; |
17 | 18 | using System.IO; |
| 19 | +using System.Linq; |
18 | 20 | using System.Reflection; |
19 | 21 | using System.Threading; |
20 | 22 | using System.Threading.Tasks; |
@@ -53,19 +55,43 @@ namespace publisher; |
53 | 55 |
|
54 | 56 | file delegate ValueTask<Option<BinaryData>> TryGetFileContentsInCommit(FileInfo fileInfo, CommitId commitId, CancellationToken cancellationToken); |
55 | 57 |
|
56 | | -file sealed class GetPublisherFilesHandler(TryGetCommitId tryGetCommitId, ManagementServiceDirectory serviceDirectory) |
| 58 | +file sealed class GetPublisherFilesHandler(TryGetCommitId tryGetCommitId, TryParseApiName tryParseApiName, ManagementServiceDirectory serviceDirectory) |
57 | 59 | { |
58 | | - private readonly Lazy<FrozenSet<FileInfo>> lazy = new(() => GetPublisherFiles(tryGetCommitId, serviceDirectory)); |
| 60 | + private readonly Lazy<FrozenSet<FileInfo>> lazy = new(() => GetPublisherFiles(tryGetCommitId, tryParseApiName, serviceDirectory)); |
59 | 61 |
|
60 | 62 | public FrozenSet<FileInfo> Handle() => lazy.Value; |
61 | 63 |
|
62 | | - private static FrozenSet<FileInfo> GetPublisherFiles(TryGetCommitId tryGetCommitId, ManagementServiceDirectory serviceDirectory) => |
| 64 | + private static FrozenSet<FileInfo> GetPublisherFiles(TryGetCommitId tryGetCommitId, TryParseApiName tryParseApiName, |
| 65 | + ManagementServiceDirectory serviceDirectory) => |
63 | 66 | tryGetCommitId() |
64 | | - .Map(commitId => GetPublisherFiles(commitId, serviceDirectory)) |
65 | | - .IfNone(serviceDirectory.GetFilesRecursively); |
| 67 | + .Map(commitId => GetPublisherFiles(commitId, tryParseApiName, serviceDirectory)) |
| 68 | + .IfNone(() => |
| 69 | + serviceDirectory.GetFilesRecursively().ToList() |
| 70 | + .Concat(GetManagedGatewayApis(serviceDirectory)) |
| 71 | + .ToFrozenSet(x => x.FullName) |
| 72 | + ); |
| 73 | + |
| 74 | + private static IEnumerable<FileInfo> GetManagedGatewayApis(ManagementServiceDirectory serviceDirectory) => |
| 75 | + ApisDirectory.From(serviceDirectory).ToDirectoryInfo() |
| 76 | + .ListDirectories("*") |
| 77 | + .Map(info => |
| 78 | + GatewayApiInformationFile.From(ApiName.From(info.Name), GatewayName.Managed, serviceDirectory) |
| 79 | + .ToFileInfo()); |
| 80 | + |
| 81 | + private static FrozenSet<FileInfo> GetPublisherFiles(CommitId commitId, TryParseApiName tryParseApiName, |
| 82 | + ManagementServiceDirectory serviceDirectory) |
| 83 | + { |
| 84 | + var changedFiles = Git.GetChangedFilesInCommit(serviceDirectory.ToDirectoryInfo(), commitId).ToList(); |
| 85 | + return changedFiles |
| 86 | + .Concat(GetChangedManagedGatewayApis(changedFiles, tryParseApiName, serviceDirectory)) |
| 87 | + .ToFrozenSet(x => x.FullName); |
| 88 | + } |
66 | 89 |
|
67 | | - private static FrozenSet<FileInfo> GetPublisherFiles(CommitId commitId, ManagementServiceDirectory serviceDirectory) => |
68 | | - Git.GetChangedFilesInCommit(serviceDirectory.ToDirectoryInfo(), commitId); |
| 90 | + private static IEnumerable<FileInfo> GetChangedManagedGatewayApis(List<FileInfo> changedFiles, TryParseApiName tryParseApiName, ManagementServiceDirectory serviceDirectory) => |
| 91 | + changedFiles.Map(x => tryParseApiName(x)) |
| 92 | + .Filter(x => x.IsSome) |
| 93 | + .Map(x => GatewayApiInformationFile.From(ApiName.GetRootName(x.ValueUnsafe()), GatewayName.Managed, serviceDirectory) |
| 94 | + .ToFileInfo()); |
69 | 95 | } |
70 | 96 |
|
71 | 97 | file sealed class GetArtifactFilesHandler(TryGetCommitId tryGetCommitId, ManagementServiceDirectory serviceDirectory) |
|
0 commit comments