Skip to content

Commit

Permalink
feat: Generate Visual Code workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Jan 15, 2024
1 parent 38e603e commit 73295cc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Accelerate/Accelerate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.4"/>
<PackageReference Include="CommandLineParser" Version="2.9.1"/>
<PackageReference Include="Markdig" Version="0.33.0"/>
<PackageReference Include="Markdig" Version="0.34.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0"/>
</ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions src/Accelerate/Campaign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public sealed class Campaign

public const string ReposFileName = "repos.json";

public const string VisualStudioCodeWorkspaceFileName = "campaign.code-workspace";

private readonly IGitCommand<AzureDevOps> _gitCommand;

private readonly IShellCommand<AzureDevOps> _shellCommand;
Expand Down Expand Up @@ -89,6 +91,9 @@ public async Task CloneAsync(CancellationToken ct = default)
{
throw new AccelerateException(AccelerateErrorCode.GitCommandExecutionFailed);
}

var visualStudioCodeWorkspaceJson = JsonSerializer.Serialize(new VisualStudioCodeWorkspace(this, _repositories));
await File.WriteAllTextAsync(VisualStudioCodeWorkspaceFileName, visualStudioCodeWorkspaceJson, ct);
}

public async Task CommitAsync(string message, CancellationToken ct = default)
Expand Down Expand Up @@ -192,4 +197,30 @@ public async Task ForeachAsync(IEnumerable<string> command, CancellationToken ct
throw new AccelerateException(AccelerateErrorCode.GitCommandExecutionFailed);
}
}

private sealed class VisualStudioCodeWorkspace
{
public VisualStudioCodeWorkspace(Campaign campaign, IEnumerable<Repository> repositories)
{
Folders = repositories.Select(repository => new VisualStudioCodeFolder(repository.Url.Segments.Last(), Path.GetFullPath(Path.Combine(campaign.WorkingDirectoryPath, repository.WorkingDirectoryPath)))).ToImmutableList();
}

[JsonPropertyName("folders")]
public IReadOnlyList<VisualStudioCodeFolder> Folders { get; }
}

private sealed class VisualStudioCodeFolder
{
public VisualStudioCodeFolder(string name, string path)
{
Name = name;
Path = path;
}

[JsonPropertyName("name")]
public string Name { get; }

[JsonPropertyName("path")]
public string Path { get; }
}
}
1 change: 1 addition & 0 deletions tests/Accelerate.Tests/Workflow/WorkflowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ await cmd.DisposeAsync()
// Then
Assert.True(File.Exists(Campaign.ReadmeFileName));
Assert.True(File.Exists(Campaign.ReposFileName));
Assert.True(File.Exists(Campaign.VisualStudioCodeWorkspaceFileName));
Assert.Equivalent(typeof(IGitCommand<Repository>).GetMethods().Select(methodInfo => methodInfo.Name), _actualCmds);
Assert.Equivalent(typeof(IShellCommand<Repository>).GetMethods().Select(methodInfo => methodInfo.Name), _actualCmds);
}
Expand Down

0 comments on commit 73295cc

Please sign in to comment.