-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to OctoKit and support access tokens and include wait for rateli…
…mits (#331)
- Loading branch information
Showing
4 changed files
with
159 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,85 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Elastic.CommonSchema.Generator.Projection; | ||
using Elastic.CommonSchema.Generator.Schema; | ||
|
||
namespace Elastic.CommonSchema.Generator | ||
namespace Elastic.CommonSchema.Generator; | ||
|
||
public static class Program | ||
{ | ||
public static class Program | ||
private const string DefaultDownloadBranch = "v8.9.0"; | ||
|
||
// ReSharper disable once UnusedParameter.Local | ||
private static async Task Main(string[] args) | ||
{ | ||
private const string DefaultDownloadBranch = "v8.6.0"; | ||
var token = args.Length > 0 ? args[0] : string.Empty; | ||
|
||
// ReSharper disable once UnusedParameter.Local | ||
private static void Main(string[] args) | ||
{ | ||
var redownloadCoreSpecification = true; | ||
var downloadBranch = DefaultDownloadBranch; | ||
Console.WriteLine($"Running from: {Directory.GetCurrentDirectory()}"); | ||
Console.WriteLine($"Resolved codebase root to: {CodeConfiguration.Root}"); | ||
Console.WriteLine(); | ||
|
||
var answer = "invalid"; | ||
while (answer != "y" && answer != "n" && answer != "") | ||
{ | ||
Console.Write("Download online specifications? [Y/N] (default N): "); | ||
answer = Console.ReadLine()?.Trim().ToLowerInvariant(); | ||
redownloadCoreSpecification = answer == "y"; | ||
} | ||
var redownloadCoreSpecification = true; | ||
var downloadBranch = DefaultDownloadBranch; | ||
|
||
Console.Write($"Tag to use (default {downloadBranch}): "); | ||
var readBranch = Console.ReadLine()?.Trim(); | ||
if (!string.IsNullOrEmpty(readBranch)) downloadBranch = readBranch; | ||
var answer = "invalid"; | ||
while (answer != "y" && answer != "n" && answer != "") | ||
{ | ||
Console.Write("Download online specifications? [Y/N] (default N): "); | ||
answer = Console.ReadLine()?.Trim().ToLowerInvariant(); | ||
redownloadCoreSpecification = answer == "y"; | ||
} | ||
|
||
if (string.IsNullOrEmpty(downloadBranch)) | ||
downloadBranch = DefaultDownloadBranch; | ||
Console.Write($"Tag to use (default {downloadBranch}): "); | ||
var readBranch = Console.ReadLine()?.Trim(); | ||
if (!string.IsNullOrEmpty(readBranch)) downloadBranch = readBranch; | ||
|
||
if (redownloadCoreSpecification) | ||
SpecificationDownloader.Download(downloadBranch); | ||
if (string.IsNullOrEmpty(downloadBranch)) | ||
downloadBranch = DefaultDownloadBranch; | ||
|
||
if (redownloadCoreSpecification) | ||
await SpecificationDownloader.DownloadAsync(downloadBranch, token); | ||
|
||
var ecsSchema = new EcsSchemaParser(downloadBranch).Parse(); | ||
WarnAboutSchemaValidations(ecsSchema); | ||
|
||
var projection = new TypeProjector(ecsSchema).CreateProjection(); | ||
WarnAboutProjectionValidations(projection); | ||
var ecsSchema = new EcsSchemaParser(downloadBranch).Parse(); | ||
WarnAboutSchemaValidations(ecsSchema); | ||
|
||
FileGenerator.Generate(projection); | ||
} | ||
var projection = new TypeProjector(ecsSchema).CreateProjection(); | ||
WarnAboutProjectionValidations(projection); | ||
|
||
private static void WarnAboutSchemaValidations(EcsSchema ecsSchema) | ||
FileGenerator.Generate(projection); | ||
} | ||
|
||
private static void WarnAboutSchemaValidations(EcsSchema ecsSchema) | ||
{ | ||
if (ecsSchema.Warnings.Count > 0) | ||
{ | ||
if (ecsSchema.Warnings.Count > 0) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine("Validation errors in YAML"); | ||
foreach (var warning in ecsSchema.Warnings.Distinct().OrderBy(w => w)) | ||
Console.WriteLine(warning); | ||
Console.ResetColor(); | ||
return; | ||
} | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("No validation errors in YAML"); | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine("Validation errors in YAML"); | ||
foreach (var warning in ecsSchema.Warnings.Distinct().OrderBy(w => w)) | ||
Console.WriteLine(warning); | ||
Console.ResetColor(); | ||
return; | ||
} | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("No validation errors in YAML"); | ||
Console.ResetColor(); | ||
} | ||
|
||
private static void WarnAboutProjectionValidations(CommonSchemaTypesProjection projection) | ||
private static void WarnAboutProjectionValidations(CommonSchemaTypesProjection projection) | ||
{ | ||
if (projection.Warnings.Count > 0) | ||
{ | ||
if (projection.Warnings.Count > 0) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine("Validation errors in Canonical Model"); | ||
foreach (var warning in projection.Warnings.Distinct().OrderBy(w => w)) | ||
Console.WriteLine(warning); | ||
Console.ResetColor(); | ||
return; | ||
} | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("No validation errors in the Canonical Model"); | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine("Validation errors in Canonical Model"); | ||
foreach (var warning in projection.Warnings.Distinct().OrderBy(w => w)) | ||
Console.WriteLine(warning); | ||
Console.ResetColor(); | ||
return; | ||
} | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("No validation errors in the Canonical Model"); | ||
Console.ResetColor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters