Skip to content

Commit

Permalink
Merge pull request #4328 from microsoft/feature/config-workspace
Browse files Browse the repository at this point in the history
feature/config workspace
  • Loading branch information
baywet authored Mar 18, 2024
2 parents c7b49e4 + 54bac9d commit 7e0a4c0
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/kiota/bin/Debug/net8.0/kiota.dll",
"args": ["config", "migrate"],
"args": ["workspace", "migrate"],
"cwd": "${workspaceFolder}/samples/msgraph-mail/dotnet",
"console": "internalConsole",
"stopAtEntry": false,
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- PREVIEW: Renamed the config commands to workspace. [#4310](https://github.com/microsoft/kiota/issues/4310)
- PREVIEW: Moved preview configuration files to the .kiota directory. [#4310](https://github.com/microsoft/kiota/issues/4310)
- PREVIEW: Moved the copy descriptions to dedicated folders. [#4310](https://github.com/microsoft/kiota/issues/4310)
- PREVIEW: Renamed the config to workspace file. [#4310](https://github.com/microsoft/kiota/issues/4310)

## [1.12.0] - 2024-03-06

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ public DescriptionStorageService(string targetDirectory)
o.PoolSize = 20;
o.PoolInitialFill = 1;
});
private string GetDescriptionFilePath(string clientName, string extension) => Path.Combine(TargetDirectory, DescriptionsSubDirectoryRelativePath, clientName, $"description.{extension}");
public async Task UpdateDescriptionAsync(string clientName, Stream description, string extension = "yml", CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(clientName);
ArgumentNullException.ThrowIfNull(description);
ArgumentNullException.ThrowIfNull(extension);
var descriptionFilePath = Path.Combine(TargetDirectory, DescriptionsSubDirectoryRelativePath, $"{clientName}.{extension}");
var descriptionFilePath = GetDescriptionFilePath(clientName, extension);
using (await localFilesLock.LockAsync(descriptionFilePath, cancellationToken).ConfigureAwait(false))
{
Directory.CreateDirectory(Path.GetDirectoryName(descriptionFilePath) ?? throw new InvalidOperationException("The target path is invalid"));
Expand All @@ -39,7 +40,7 @@ public async Task UpdateDescriptionAsync(string clientName, Stream description,
{
ArgumentNullException.ThrowIfNull(clientName);
ArgumentNullException.ThrowIfNull(extension);
var descriptionFilePath = Path.Combine(TargetDirectory, DescriptionsSubDirectoryRelativePath, $"{clientName}.{extension}");
var descriptionFilePath = GetDescriptionFilePath(clientName, extension);
if (!File.Exists(descriptionFilePath))
return null;
using (await localFilesLock.LockAsync(descriptionFilePath, cancellationToken).ConfigureAwait(false))
Expand All @@ -55,7 +56,7 @@ public void RemoveDescription(string clientName, string extension = "yml")
{
ArgumentNullException.ThrowIfNull(clientName);
ArgumentNullException.ThrowIfNull(extension);
var descriptionFilePath = Path.Combine(TargetDirectory, DescriptionsSubDirectoryRelativePath, $"{clientName}.{extension}");
var descriptionFilePath = GetDescriptionFilePath(clientName, extension);
if (File.Exists(descriptionFilePath))
File.Delete(descriptionFilePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace Kiota.Builder.WorkspaceManagement;

public class WorkspaceConfigurationStorageService
{
public const string ConfigurationFileName = "kiota-config.json";
public const string ConfigurationFileName = "workspace.json";
public const string ManifestFileName = "apimanifest.json";
public static string KiotaDirectorySegment => DescriptionStorageService.KiotaDirectorySegment;
public string TargetDirectory
{
get; private set;
Expand All @@ -25,7 +26,7 @@ public string TargetDirectory
public WorkspaceConfigurationStorageService(string targetDirectory)
{
ArgumentException.ThrowIfNullOrEmpty(targetDirectory);
TargetDirectory = targetDirectory;
TargetDirectory = Path.Combine(targetDirectory, KiotaDirectorySegment);
targetConfigurationFilePath = Path.Combine(TargetDirectory, ConfigurationFileName);
targetManifestFilePath = Path.Combine(TargetDirectory, ManifestFileName);
}
Expand Down
3 changes: 2 additions & 1 deletion src/kiota/Handlers/Client/AddHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -131,7 +132,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
DisplaySuccess("Generation skipped as --skip-generation was passed");
DisplayGenerateCommandHint();
} // else we get an error because we're adding a client that already exists
var manifestPath = $"{GetAbsolutePath(WorkspaceConfigurationStorageService.ManifestFileName)}#{Configuration.Generation.ClientClassName}";
var manifestPath = $"{GetAbsolutePath(Path.Combine(WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ManifestFileName))}#{Configuration.Generation.ClientClassName}";
DisplayInfoHint(language, string.Empty, manifestPath);
DisplayGenerateAdvancedHint(includePatterns, excludePatterns, string.Empty, manifestPath, "client add");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/Handlers/Client/EditHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
DisplayWarning("Generation skipped as no changes were detected");
DisplayCleanHint("client generate", "--refresh");
}
var manifestPath = $"{GetAbsolutePath(WorkspaceConfigurationStorageService.ManifestFileName)}#{Configuration.Generation.ClientClassName}";
var manifestPath = $"{GetAbsolutePath(Path.Combine(WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ManifestFileName))}#{Configuration.Generation.ClientClassName}";
DisplayInfoHint(Configuration.Generation.Language, string.Empty, manifestPath);
DisplayGenerateAdvancedHint(includePatterns ?? [], excludePatterns ?? [], string.Empty, manifestPath, "client edit");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/Handlers/Client/GenerateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
if (result)
{
DisplaySuccess($"Update of {clientEntry.Key} client completed");
var manifestPath = $"{GetAbsolutePath(WorkspaceConfigurationStorageService.ManifestFileName)}#{clientEntry.Key}";
var manifestPath = $"{GetAbsolutePath(Path.Combine(WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ManifestFileName))}#{clientEntry.Key}";
DisplayInfoHint(generationConfiguration.Language, string.Empty, manifestPath);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Kiota.Builder.WorkspaceManagement;
using Microsoft.Extensions.Logging;

namespace kiota.Handlers.Config;
namespace kiota.Handlers.Workspace;

internal class InitHandler : BaseKiotaCommandHandler
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Kiota.Builder.WorkspaceManagement;
using Microsoft.Extensions.Logging;

namespace kiota.Handlers.Config;
namespace kiota.Handlers.Workspace;

internal class MigrateHandler : BaseKiotaCommandHandler
{
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/KiotaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static RootCommand GetRootCommand()
rootCommand.AddCommand(GetRpcCommand());
if (IsConfigPreviewEnabled.Value)
{
rootCommand.AddCommand(KiotaConfigCommands.GetConfigNodeCommand());
rootCommand.AddCommand(KiotaWorkspaceCommands.GetWorkspaceNodeCommand());
rootCommand.AddCommand(KiotaClientCommands.GetClientNodeCommand());
}
return rootCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using System.CommandLine;
using kiota.Handlers.Config;
using kiota.Handlers.Workspace;

namespace kiota;

public static class KiotaConfigCommands
public static class KiotaWorkspaceCommands
{
public static Command GetConfigNodeCommand()
public static Command GetWorkspaceNodeCommand()
{
var command = new Command("config", "Manages the Kiota configuration");
var command = new Command("workspace", "Manages the Kiota workspace configuration");
command.AddCommand(GetInitCommand());
command.AddCommand(GetMigrateCommand());
return command;
}
private static Command GetInitCommand()
{
var logLevelOption = KiotaHost.GetLogLevelOption();
var command = new Command("init", "Initializes the Kiota configuration"){
var command = new Command("init", "Initializes the Kiota workspace configuration"){
logLevelOption,
};
command.Handler = new InitHandler
Expand All @@ -29,7 +29,7 @@ private static Command GetMigrateCommand()
var logLevelOption = KiotaHost.GetLogLevelOption();
var lockDirectoryOption = GetLockDirectoryOption();
var classOption = KiotaClientCommands.GetClientNameOption(false);
var command = new Command("migrate", "Migrates a kiota lock file to a Kiota configuration")
var command = new Command("migrate", "Migrates a kiota lock file to a Kiota workspace configuration")
{
logLevelOption,
lockDirectoryOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task InitializesAsync()
{
var service = new WorkspaceConfigurationStorageService(tempPath);
await service.InitializeAsync();
Assert.True(File.Exists(Path.Combine(tempPath, "kiota-config.json")));
Assert.True(File.Exists(Path.Combine(tempPath, WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ConfigurationFileName)));
}
[Fact]
public async Task FailsOnDoubleInit()
Expand Down Expand Up @@ -67,7 +67,7 @@ public async Task BackupsAndRestores()
var service = new WorkspaceConfigurationStorageService(tempPath);
await service.InitializeAsync();
await service.BackupConfigAsync();
var targetConfigFile = Path.Combine(tempPath, "kiota-config.json");
var targetConfigFile = Path.Combine(tempPath, WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ConfigurationFileName);
File.Delete(targetConfigFile);
Assert.False(File.Exists(targetConfigFile));
await service.RestoreConfigAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ await File.WriteAllTextAsync(descriptionPath, @$"openapi: 3.0.1
Assert.Single(clientNames);
Assert.Equal("clientName", clientNames.First());
Assert.False(File.Exists(Path.Combine(tempPath, LockManagementService.LockFileName)));
Assert.True(File.Exists(Path.Combine(tempPath, WorkspaceConfigurationStorageService.ConfigurationFileName)));
Assert.True(File.Exists(Path.Combine(tempPath, WorkspaceConfigurationStorageService.ManifestFileName)));
Assert.True(File.Exists(Path.Combine(tempPath, DescriptionStorageService.DescriptionsSubDirectoryRelativePath, "clientName.yml")));
Assert.True(File.Exists(Path.Combine(tempPath, WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ConfigurationFileName)));
Assert.True(File.Exists(Path.Combine(tempPath, WorkspaceConfigurationStorageService.KiotaDirectorySegment, WorkspaceConfigurationStorageService.ManifestFileName)));
Assert.True(File.Exists(Path.Combine(tempPath, DescriptionStorageService.DescriptionsSubDirectoryRelativePath, "clientName", "description.yml")));
}
[InlineData(true, true)]
[InlineData(true, false)]
Expand All @@ -186,7 +186,7 @@ public async Task GetsADescription(bool usesConfig, bool cleanOutput)
var mockLogger = Mock.Of<ILogger>();
Directory.CreateDirectory(tempPath);
var service = new WorkspaceManagementService(mockLogger, httpClient, usesConfig, tempPath);
var descriptionPath = Path.Combine(tempPath, $"{DescriptionStorageService.DescriptionsSubDirectoryRelativePath}/clientName.yml");
var descriptionPath = Path.Combine(tempPath, $"{DescriptionStorageService.DescriptionsSubDirectoryRelativePath}/clientName/description.yml");
var outputPath = Path.Combine(tempPath, "client");
Directory.CreateDirectory(outputPath);
Directory.CreateDirectory(Path.GetDirectoryName(descriptionPath));
Expand Down

0 comments on commit 7e0a4c0

Please sign in to comment.