Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/GitHubActionsVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@
<Compile Include="Helpers\ConclusionFilter.cs" />
<Compile Include="Helpers\CredentialManager.cs" />
<Compile Include="Helpers\RepoInfo.cs" />
<Compile Include="Helpers\StringHelpers.cs" />
<Compile Include="Helpers\YamlHelpers.cs" />
<Compile Include="Models\BaseWorkflowType.cs" />
<Compile Include="Models\InputMetadata.cs" />
<Compile Include="Models\SimpleEnvironment.cs" />
<Compile Include="Models\SimpleJob.cs" />
<Compile Include="Models\SimpleRun.cs" />
<Compile Include="Models\Workflow.cs" />
<Compile Include="Options\ExtensionOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Commands\ActionsToolWindowCommand.cs" />
Expand All @@ -82,6 +86,9 @@
<Compile Include="UserControls\AddEditSecret.xaml.cs">
<DependentUpon>AddEditSecret.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\WorkflowInputsDialog.xaml.cs">
<DependentUpon>WorkflowInputsDialog.xaml</DependentUpon>
</Compile>
<Compile Include="VSCommandTable.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -136,6 +143,9 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\WorkflowInputsDialog.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down Expand Up @@ -186,6 +196,9 @@
<PackageReference Include="Sodium.Core">
<Version>1.3.3</Version>
</PackageReference>
<PackageReference Include="YamlDotNet">
<Version>16.3.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\UIStrings.resx">
Expand Down
27 changes: 27 additions & 0 deletions src/Helpers/StringHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace GitHubActionsVS.Helpers
{
internal class StringHelpers
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The StringHelpers class should be declared as 'static' since all its methods are static. This prevents instantiation and makes the intent clearer.

Suggested change
internal class StringHelpers
internal static class StringHelpers

Copilot uses AI. Check for mistakes.
{
public static bool IsBase64(string input)
{
if (string.IsNullOrWhiteSpace(input) || input.Length % 4 != 0)
return false;

foreach (char c in input)
{
if (!(char.IsLetterOrDigit(c) || c == '+' || c == '/' || c == '='))
return false;
}

try
{
_ = Convert.FromBase64String(input);
return true;
}
catch
{
return false;
}
}
}
}
58 changes: 58 additions & 0 deletions src/Helpers/YamlHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Reflection;
using YamlDotNet.RepresentationModel;

namespace GitHubActionsVS.Helpers
{
internal static class YamlHelpers
{
/// <summary>
/// Follows YamlDotNet alias nodes (&anchor / *alias) to the real node.
/// Returns the resolved node if an alias chain exists.
/// </summary>
public static YamlNode Unalias(YamlNode node)
{
// Use reflection to check for YamlAliasNode and access RealNode
var aliasType = node.GetType().FullName == "YamlDotNet.RepresentationModel.YamlAliasNode"
? node.GetType()
: null;

while (aliasType != null)
{
var realNodeProp = aliasType.GetProperty("RealNode", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (realNodeProp?.GetValue(node) is not YamlNode realNode)
break;
node = realNode;
aliasType = node.GetType().FullName == "YamlDotNet.RepresentationModel.YamlAliasNode"
? node.GetType()
: null;
}

return node;
}

/// <summary>
/// Attempts to retrieve a child value from a mapping node by key name.
/// Uses string comparison on scalar node values rather than allocating new nodes.
/// </summary>
/// <param name="map">The mapping node to search.</param>
/// <param name="key">The scalar key string to match.</param>
/// <param name="value">The value node if found.</param>
/// <returns>True if a matching key was found, otherwise false.</returns>
public static bool TryGetScalarKey(YamlMappingNode map, string key, out YamlNode value)
{
foreach (var kv in map.Children)
{
if (kv.Key is YamlScalarNode sk &&
string.Equals(sk.Value, key, StringComparison.Ordinal))
{
value = kv.Value;
return true;
}
}

value = null!;
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using 'null!' (null-forgiving operator) here is misleading since the method is designed to return false when no value is found. Consider using 'value = default!' or restructuring to avoid the null-forgiving operator.

Suggested change
value = null!;
value = default;

Copilot uses AI. Check for mistakes.
return false;
}

}
}
82 changes: 82 additions & 0 deletions src/Models/InputMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace GitHubActionsVS.Models
{
public sealed class InputMetadata
{
public string Name { get; }
public string Type { get; }
public string Description { get; }
public bool Required { get; }
public string Default { get; }
public string[] Options { get; }

public InputMetadata(string name, string type, string description, bool required, string @default, string[] options)
{
Name = name;
Type = type;
Description = description;
Required = required;
Default = @default;
Options = options;
}

public static List<InputMetadata> ToInputMeta(IReadOnlyDictionary<string, IReadOnlyDictionary<string, object>> inputs)
{
var list = new List<InputMetadata>();

try
{
foreach (var kv in inputs)
{
var name = kv.Key;
var dict = kv.Value;

dict.TryGetValue("type", out var typeObj);
dict.TryGetValue("description", out var descObj);
dict.TryGetValue("required", out var reqObj);
dict.TryGetValue("default", out var defObj);
dict.TryGetValue("options", out var optsObj);

var type = (typeObj?.ToString()?.Trim().ToLowerInvariant()) switch
{
"boolean" => "boolean",
"choice" => "choice",
"environment" => "environment",
_ => "string"
};

string[] options = null;

if (optsObj is IEnumerable<object> seq)
{
options = [.. seq.Select(o => o?.ToString() ?? string.Empty)];
}
else if (optsObj is string s)
{
options = [s];
}

var required = reqObj is bool b ? b : bool.TryParse(reqObj?.ToString(), out var br) && br;

list.Add(new InputMetadata(
name,
type,
descObj?.ToString(),
required,
defObj?.ToString(),
options
));
}
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to create InputMetadata. Ex: {ex.Message}");
}

return list;
}
}
}
22 changes: 22 additions & 0 deletions src/Models/Workflow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using YamlDotNet.Serialization;

namespace GitHubActionsVS.Models
{
sealed class WorkflowRoot
{
[YamlMember(Alias = "on")]
public OnSection On { get; init; }
}

sealed class OnSection
{
[YamlMember(Alias = "workflow_dispatch")]
public WorkflowDispatch WorkflowDispatch { get; init; }
}

sealed class WorkflowDispatch
{
public Dictionary<string, Dictionary<string, object>> Inputs { get; init; }
}
}
4 changes: 2 additions & 2 deletions src/ToolWindows/GHActionsToolWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<Expander Header="{x:Static resx:UIStrings.HEADER_CURRENT_BRANCH}" x:Name="CurrentBranchExpander" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}">
<TreeView BorderThickness="0" FontWeight="Normal" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvCurrentBranch" ItemTemplate="{StaticResource TreeViewRunNodeDataTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Static shell:VsResourceKeys.ThemedDialogTreeViewItemStyleKey}}">
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="JobItem_MouseDoubleClick"/>
</Style>
</TreeView.Resources>
Expand All @@ -147,7 +147,7 @@
<TreeViewItem ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" Header="{x:Static resx:UIStrings.HEADER_SECRETS}" HeaderTemplate="{StaticResource SecretsHeaderTemplate}">
<TreeViewItem ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" x:Name="tvSecrets" HeaderTemplate="{StaticResource RepoSecretsHeaderTemplate}">
<TreeViewItem.Resources>
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Static shell:VsResourceKeys.ThemedDialogTreeViewItemStyleKey}}">
<Style TargetType="{x:Type TreeViewItem}">
<EventSetter Event="MouseDoubleClick" Handler="Secret_MouseDoubleClick"/>
</Style>
</TreeViewItem.Resources>
Expand Down
Loading