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