Skip to content

Commit 8ab99f1

Browse files
committed
Starting on Environments
- Starting on #17 but blocked by API in package used, still will display them - Added counts to other things
1 parent 1589abb commit 8ab99f1

File tree

4 files changed

+62
-13
lines changed

4 files changed

+62
-13
lines changed

src/GitHubActionsVS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="Helpers\CredentialManager.cs" />
5353
<Compile Include="Helpers\RepoInfo.cs" />
5454
<Compile Include="Models\BaseWorkflowType.cs" />
55+
<Compile Include="Models\SimpleEnvironment.cs" />
5556
<Compile Include="Models\SimpleJob.cs" />
5657
<Compile Include="Models\SimpleRun.cs" />
5758
<Compile Include="Options\ExtensionOptions.cs" />

src/Models/SimpleEnvironment.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace GitHubActionsVS.Models;
4+
public class SimpleEnvironment
5+
{
6+
public string Name { get; set; }
7+
public string Url { get; set; }
8+
}
9+
10+

src/ToolWindows/GHActionsToolWindow.xaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
<TextBlock Text="{Binding}" Margin="5,0" />
3232
</StackPanel>
3333
</DataTemplate>
34+
<DataTemplate x:Key="RepoSecretsHeaderTemplate">
35+
<TextBlock Text="{Binding}">
36+
<TextBlock.ContextMenu>
37+
<ContextMenu>
38+
<MenuItem Header="Add Secret" Click="AddSecret_Click" />
39+
</ContextMenu>
40+
</TextBlock.ContextMenu>
41+
</TextBlock>
42+
</DataTemplate>
3443
<HierarchicalDataTemplate x:Key="TreeViewRunNodeDataTemplate" ItemsSource="{Binding Jobs}">
3544
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
3645
<TextBlock VerticalAlignment="Center" FontFamily="{StaticResource CodiconFont}"
@@ -39,6 +48,9 @@
3948
<emoji:TextBlock Text="{Binding DisplayName}" VerticalAlignment="Bottom" />
4049
</StackPanel>
4150
</HierarchicalDataTemplate>
51+
<DataTemplate x:Key="EnvironmentItemTemplate">
52+
<TextBlock Text="{Binding Name}"/>
53+
</DataTemplate>
4254
</UserControl.Resources>
4355
<Grid VerticalAlignment="Stretch">
4456
<Grid.RowDefinitions>
@@ -51,21 +63,13 @@
5163
<ScrollViewer VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="5,5,0,0" x:Name="ActionsInfoPanel">
5264
<StackPanel Orientation="Vertical">
5365
<Expander Header="Current Branch" x:Name="CurrentBranchExpander">
54-
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvCurrentBranch" ItemTemplate="{DynamicResource TreeViewRunNodeDataTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
66+
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvCurrentBranch" ItemTemplate="{StaticResource TreeViewRunNodeDataTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
5567
</Expander>
5668
<Expander Header="Settings">
57-
<TreeView BorderThickness="0">
58-
<TreeViewItem Header="Secrets" HeaderTemplate="{DynamicResource SecretsHeaderTemplate}">
59-
<TreeViewItem x:Name="tvSecrets">
60-
<TreeViewItem.Header>
61-
<TextBlock Text="Repository Secrets">
62-
<TextBlock.ContextMenu>
63-
<ContextMenu>
64-
<MenuItem Header="Add Secret" Click="AddSecret_Click" />
65-
</ContextMenu>
66-
</TextBlock.ContextMenu>
67-
</TextBlock>
68-
</TreeViewItem.Header>
69+
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel">
70+
<TreeViewItem Header="Environments" x:Name="tvEnvironments" ItemTemplate="{StaticResource EnvironmentItemTemplate}" />
71+
<TreeViewItem Header="Secrets" HeaderTemplate="{StaticResource SecretsHeaderTemplate}">
72+
<TreeViewItem x:Name="tvSecrets" HeaderTemplate="{StaticResource RepoSecretsHeaderTemplate}">
6973
<TreeViewItem.ItemTemplate>
7074
<DataTemplate>
7175
<TextBlock Text="{Binding}">

src/ToolWindows/GHActionsToolWindow.xaml.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Octokit;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7+
using System.Threading.Tasks;
78
using System.Windows;
89
using System.Windows.Controls;
910
using System.Windows.Input;
@@ -114,6 +115,9 @@ private void ShowInfoMessage(string messageString)
114115
private void ClearTreeViews()
115116
{
116117
tvSecrets.ItemsSource = null;
118+
tvSecrets.Header = "Repository Secrets";
119+
tvEnvironments.ItemsSource = null;
120+
tvEnvironments.Header = "Environments";
117121
tvCurrentBranch.ItemsSource = null;
118122
CurrentBranchExpander.IsExpanded = false;
119123
}
@@ -136,6 +140,8 @@ private async Task LoadDataAsync()
136140
{
137141
// get secrets
138142
await RefreshSecretsAsync(client);
143+
// get environments
144+
await RefreshEnvironmentsAsync(client);
139145

140146
// get current branch
141147
var runs = await client.Actions?.Workflows?.Runs?.List(_repoInfo.RepoOwner, _repoInfo.RepoName, new WorkflowRunsRequest() { Branch = _repoInfo.CurrentBranch }, new ApiOptions() { PageCount = 1, PageSize = maxRuns });
@@ -216,12 +222,39 @@ private async Task LoadDataAsync()
216222
refreshProgress.IsIndeterminate = false;
217223
}
218224

225+
private async Task RefreshEnvironmentsAsync(GitHubClient client)
226+
{
227+
var repoEnvs = await client.Repository?.Environment?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
228+
List<SimpleEnvironment> envList = new List<SimpleEnvironment>();
229+
if (repoEnvs.TotalCount > 0)
230+
{
231+
tvEnvironments.Header = $"Environments ({repoEnvs.TotalCount})";
232+
foreach (var env in repoEnvs.Environments)
233+
{
234+
var envItem = new SimpleEnvironment
235+
{
236+
Name = env.Name,
237+
Url = env.HtmlUrl
238+
};
239+
240+
envList.Add(envItem);
241+
}
242+
}
243+
else
244+
{
245+
envList.Add(new() { Name = "No environments defined"});
246+
}
247+
248+
tvEnvironments.ItemsSource = envList;
249+
}
250+
219251
private async Task RefreshSecretsAsync(GitHubClient client)
220252
{
221253
var repoSecrets = await client.Repository?.Actions?.Secrets?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
222254
List<string> secretList = new();
223255
if (repoSecrets.TotalCount > 0)
224256
{
257+
tvSecrets.Header = $"Repository Secrets ({repoSecrets.TotalCount})";
225258
foreach (var secret in repoSecrets.Secrets)
226259
{
227260
var updatedOrCreatedAt = secret.UpdatedAt.GetValueOrDefault(secret.CreatedAt);
@@ -230,6 +263,7 @@ private async Task RefreshSecretsAsync(GitHubClient client)
230263
}
231264
else
232265
{
266+
tvSecrets.Header = $"Repository Secrets";
233267
secretList.Add("No repository secrets defined");
234268
}
235269
tvSecrets.ItemsSource = secretList;

0 commit comments

Comments
 (0)