Skip to content

Commit

Permalink
Workflow list part 1
Browse files Browse the repository at this point in the history
- Listing out the workflows
- Enabling right-click run action to trigger them starting
  • Loading branch information
timheuer committed Jul 31, 2023
1 parent 4d26870 commit b6bd818
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GitHubActionsVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Resource Include="Resources\Run.png" />
<Resource Include="Resources\OpenWebSite.png" />
<Resource Include="Resources\codicon.ttf" />
<Content Include="LICENSE">
Expand Down
Binary file added src/Resources/Run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/Resources/UIStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Resources/UIStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
<value>Settings</value>
<comment>Settings expander header</comment>
</data>
<data name="HEADER_WORKFLOWS" xml:space="preserve">
<value>Workflows</value>
<comment>Header for workflow top-level node</comment>
</data>
<data name="LABEL_NAME" xml:space="preserve">
<value>Name:</value>
<comment>Label for secret form for name</comment>
Expand Down Expand Up @@ -201,6 +205,10 @@
<value>No workflow runs found for query</value>
<comment>For when no workload runs are found</comment>
</data>
<data name="RUN_WORKFLOW" xml:space="preserve">
<value>Run Workflow</value>
<comment>Menu for running a workflow</comment>
</data>
<data name="VIEW_LOG" xml:space="preserve">
<value>View Log</value>
<comment>Menu for viewing a log</comment>
Expand Down
16 changes: 16 additions & 0 deletions src/ToolWindows/GHActionsToolWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
</emoji:TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate x:Key="WorkflowItemTemplate">
<TextBlock Text="{Binding Name}" Tag="{Binding Id}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="{x:Static resx:UIStrings.RUN_WORKFLOW}" Click="RunWorkflow_Click" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}}">
<MenuItem.Icon>
<Image Source="pack://application:,,,/GitHubActionsVS;component/Resources/Run.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
<DataTemplate x:Key="EnvironmentItemTemplate">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
Expand All @@ -94,6 +107,9 @@
</TreeView.Resources>
</TreeView>
</Expander>
<Expander Header="{x:Static resx:UIStrings.HEADER_WORKFLOWS}" FontWeight="Bold">
<TreeView BorderThickness="0" FontWeight="Normal" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvWorkflows" ItemTemplate="{StaticResource WorkflowItemTemplate}"/>
</Expander>
<Expander Header="{x:Static resx:UIStrings.HEADER_SECRETS}" FontWeight="Bold">
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" FontWeight="Normal">
<TreeViewItem Header="{x:Static resx:UIStrings.HEADER_ENVIRONMENTS}" HeaderTemplate="{StaticResource EnvironmentHeaderTemplate}" x:Name="tvEnvironments" ItemTemplate="{StaticResource EnvironmentItemTemplate}" />
Expand Down
29 changes: 29 additions & 0 deletions src/ToolWindows/GHActionsToolWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private async Task LoadDataAsync()
await RefreshSecretsAsync(client);
// get environments
await RefreshEnvironmentsAsync(client);
// get workflows
await RefreshWorkflowsAsync(client);

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

private async Task RefreshWorkflowsAsync(GitHubClient client)
{
var workflows = await client.Actions?.Workflows?.List(_repoInfo.RepoOwner, _repoInfo.RepoName);
tvWorkflows.ItemsSource = workflows.Workflows;
}
private async Task RefreshSecretsAsync(GitHubClient client)
{
var repoSecrets = await client.Repository?.Actions?.Secrets?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
Expand Down Expand Up @@ -419,5 +426,27 @@ private void ViewLog_Click(object sender, RoutedEventArgs e)
Process.Start(logUrl);
}
}

private void RunWorkflow_Click(object sender, RoutedEventArgs e)
{
MenuItem menuItem = (MenuItem)sender;
TextBlock tvi = GetParentTreeViewItem(menuItem);

// check the tag value to ensure it isn't null
if (tvi is not null && tvi.Tag is not null)
{
GitHubClient client = GetGitHubClient();
CreateWorkflowDispatch cwd = new CreateWorkflowDispatch(_repoInfo.CurrentBranch);

try
{
_ = client.Actions.Workflows.CreateDispatch(_repoInfo.RepoOwner, _repoInfo.RepoName, (long)tvi.Tag, cwd);
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to start workflow: {ex.Message}");
}
}
}
}

0 comments on commit b6bd818

Please sign in to comment.