Skip to content

Commit b6bd818

Browse files
committed
Workflow list part 1
- Listing out the workflows - Enabling right-click run action to trigger them starting
1 parent 4d26870 commit b6bd818

6 files changed

+72
-0
lines changed

src/GitHubActionsVS.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
8787
<IncludeInVSIX>true</IncludeInVSIX>
8888
</Content>
89+
<Resource Include="Resources\Run.png" />
8990
<Resource Include="Resources\OpenWebSite.png" />
9091
<Resource Include="Resources\codicon.ttf" />
9192
<Content Include="LICENSE">

src/Resources/Run.png

405 Bytes
Loading

src/Resources/UIStrings.Designer.cs

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/UIStrings.resx

+8
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@
173173
<value>Settings</value>
174174
<comment>Settings expander header</comment>
175175
</data>
176+
<data name="HEADER_WORKFLOWS" xml:space="preserve">
177+
<value>Workflows</value>
178+
<comment>Header for workflow top-level node</comment>
179+
</data>
176180
<data name="LABEL_NAME" xml:space="preserve">
177181
<value>Name:</value>
178182
<comment>Label for secret form for name</comment>
@@ -201,6 +205,10 @@
201205
<value>No workflow runs found for query</value>
202206
<comment>For when no workload runs are found</comment>
203207
</data>
208+
<data name="RUN_WORKFLOW" xml:space="preserve">
209+
<value>Run Workflow</value>
210+
<comment>Menu for running a workflow</comment>
211+
</data>
204212
<data name="VIEW_LOG" xml:space="preserve">
205213
<value>View Log</value>
206214
<comment>Menu for viewing a log</comment>

src/ToolWindows/GHActionsToolWindow.xaml

+16
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@
7171
</emoji:TextBlock>
7272
</StackPanel>
7373
</HierarchicalDataTemplate>
74+
<DataTemplate x:Key="WorkflowItemTemplate">
75+
<TextBlock Text="{Binding Name}" Tag="{Binding Id}">
76+
<TextBlock.ContextMenu>
77+
<ContextMenu>
78+
<MenuItem Header="{x:Static resx:UIStrings.RUN_WORKFLOW}" Click="RunWorkflow_Click" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}">
79+
<MenuItem.Icon>
80+
<Image Source="pack://application:,,,/GitHubActionsVS;component/Resources/Run.png" />
81+
</MenuItem.Icon>
82+
</MenuItem>
83+
</ContextMenu>
84+
</TextBlock.ContextMenu>
85+
</TextBlock>
86+
</DataTemplate>
7487
<DataTemplate x:Key="EnvironmentItemTemplate">
7588
<TextBlock Text="{Binding Name}"/>
7689
</DataTemplate>
@@ -94,6 +107,9 @@
94107
</TreeView.Resources>
95108
</TreeView>
96109
</Expander>
110+
<Expander Header="{x:Static resx:UIStrings.HEADER_WORKFLOWS}" FontWeight="Bold">
111+
<TreeView BorderThickness="0" FontWeight="Normal" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvWorkflows" ItemTemplate="{StaticResource WorkflowItemTemplate}"/>
112+
</Expander>
97113
<Expander Header="{x:Static resx:UIStrings.HEADER_SECRETS}" FontWeight="Bold">
98114
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" FontWeight="Normal">
99115
<TreeViewItem Header="{x:Static resx:UIStrings.HEADER_ENVIRONMENTS}" HeaderTemplate="{StaticResource EnvironmentHeaderTemplate}" x:Name="tvEnvironments" ItemTemplate="{StaticResource EnvironmentItemTemplate}" />

src/ToolWindows/GHActionsToolWindow.xaml.cs

+29
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ private async Task LoadDataAsync()
149149
await RefreshSecretsAsync(client);
150150
// get environments
151151
await RefreshEnvironmentsAsync(client);
152+
// get workflows
153+
await RefreshWorkflowsAsync(client);
152154

153155
// get current branch
154156
var runs = await client.Actions?.Workflows?.Runs?.List(_repoInfo.RepoOwner, _repoInfo.RepoName, new WorkflowRunsRequest() { Branch = _repoInfo.CurrentBranch }, new ApiOptions() { PageCount = 1, PageSize = maxRuns });
@@ -271,6 +273,11 @@ private async Task RefreshEnvironmentsAsync(GitHubClient client)
271273
tvEnvironments.ItemsSource = envList;
272274
}
273275

276+
private async Task RefreshWorkflowsAsync(GitHubClient client)
277+
{
278+
var workflows = await client.Actions?.Workflows?.List(_repoInfo.RepoOwner, _repoInfo.RepoName);
279+
tvWorkflows.ItemsSource = workflows.Workflows;
280+
}
274281
private async Task RefreshSecretsAsync(GitHubClient client)
275282
{
276283
var repoSecrets = await client.Repository?.Actions?.Secrets?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
@@ -419,5 +426,27 @@ private void ViewLog_Click(object sender, RoutedEventArgs e)
419426
Process.Start(logUrl);
420427
}
421428
}
429+
430+
private void RunWorkflow_Click(object sender, RoutedEventArgs e)
431+
{
432+
MenuItem menuItem = (MenuItem)sender;
433+
TextBlock tvi = GetParentTreeViewItem(menuItem);
434+
435+
// check the tag value to ensure it isn't null
436+
if (tvi is not null && tvi.Tag is not null)
437+
{
438+
GitHubClient client = GetGitHubClient();
439+
CreateWorkflowDispatch cwd = new CreateWorkflowDispatch(_repoInfo.CurrentBranch);
440+
441+
try
442+
{
443+
_ = client.Actions.Workflows.CreateDispatch(_repoInfo.RepoOwner, _repoInfo.RepoName, (long)tvi.Tag, cwd);
444+
}
445+
catch (Exception ex)
446+
{
447+
Debug.WriteLine($"Failed to start workflow: {ex.Message}");
448+
}
449+
}
450+
}
422451
}
423452

0 commit comments

Comments
 (0)