Skip to content

Commit

Permalink
Starting on Environments
Browse files Browse the repository at this point in the history
- Starting on #17 but blocked by API in package used, still will display them
- Added counts to other things
  • Loading branch information
timheuer committed Jul 21, 2023
1 parent 1589abb commit 8ab99f1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/GitHubActionsVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Helpers\CredentialManager.cs" />
<Compile Include="Helpers\RepoInfo.cs" />
<Compile Include="Models\BaseWorkflowType.cs" />
<Compile Include="Models\SimpleEnvironment.cs" />
<Compile Include="Models\SimpleJob.cs" />
<Compile Include="Models\SimpleRun.cs" />
<Compile Include="Options\ExtensionOptions.cs" />
Expand Down
10 changes: 10 additions & 0 deletions src/Models/SimpleEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace GitHubActionsVS.Models;
public class SimpleEnvironment
{
public string Name { get; set; }
public string Url { get; set; }
}


30 changes: 17 additions & 13 deletions src/ToolWindows/GHActionsToolWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<TextBlock Text="{Binding}" Margin="5,0" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="RepoSecretsHeaderTemplate">
<TextBlock Text="{Binding}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Add Secret" Click="AddSecret_Click" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
<HierarchicalDataTemplate x:Key="TreeViewRunNodeDataTemplate" ItemsSource="{Binding Jobs}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock VerticalAlignment="Center" FontFamily="{StaticResource CodiconFont}"
Expand All @@ -39,6 +48,9 @@
<emoji:TextBlock Text="{Binding DisplayName}" VerticalAlignment="Bottom" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate x:Key="EnvironmentItemTemplate">
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</UserControl.Resources>
<Grid VerticalAlignment="Stretch">
<Grid.RowDefinitions>
Expand All @@ -51,21 +63,13 @@
<ScrollViewer VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="5,5,0,0" x:Name="ActionsInfoPanel">
<StackPanel Orientation="Vertical">
<Expander Header="Current Branch" x:Name="CurrentBranchExpander">
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvCurrentBranch" ItemTemplate="{DynamicResource TreeViewRunNodeDataTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvCurrentBranch" ItemTemplate="{StaticResource TreeViewRunNodeDataTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"/>
</Expander>
<Expander Header="Settings">
<TreeView BorderThickness="0">
<TreeViewItem Header="Secrets" HeaderTemplate="{DynamicResource SecretsHeaderTemplate}">
<TreeViewItem x:Name="tvSecrets">
<TreeViewItem.Header>
<TextBlock Text="Repository Secrets">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Add Secret" Click="AddSecret_Click" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</TreeViewItem.Header>
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel">
<TreeViewItem Header="Environments" x:Name="tvEnvironments" ItemTemplate="{StaticResource EnvironmentItemTemplate}" />
<TreeViewItem Header="Secrets" HeaderTemplate="{StaticResource SecretsHeaderTemplate}">
<TreeViewItem x:Name="tvSecrets" HeaderTemplate="{StaticResource RepoSecretsHeaderTemplate}">
<TreeViewItem.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}">
Expand Down
34 changes: 34 additions & 0 deletions src/ToolWindows/GHActionsToolWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Octokit;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -114,6 +115,9 @@ private void ShowInfoMessage(string messageString)
private void ClearTreeViews()
{
tvSecrets.ItemsSource = null;
tvSecrets.Header = "Repository Secrets";
tvEnvironments.ItemsSource = null;
tvEnvironments.Header = "Environments";
tvCurrentBranch.ItemsSource = null;
CurrentBranchExpander.IsExpanded = false;
}
Expand All @@ -136,6 +140,8 @@ private async Task LoadDataAsync()
{
// get secrets
await RefreshSecretsAsync(client);
// get environments
await RefreshEnvironmentsAsync(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 @@ -216,12 +222,39 @@ private async Task LoadDataAsync()
refreshProgress.IsIndeterminate = false;
}

private async Task RefreshEnvironmentsAsync(GitHubClient client)
{
var repoEnvs = await client.Repository?.Environment?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
List<SimpleEnvironment> envList = new List<SimpleEnvironment>();
if (repoEnvs.TotalCount > 0)
{
tvEnvironments.Header = $"Environments ({repoEnvs.TotalCount})";
foreach (var env in repoEnvs.Environments)
{
var envItem = new SimpleEnvironment
{
Name = env.Name,
Url = env.HtmlUrl
};

envList.Add(envItem);
}
}
else
{
envList.Add(new() { Name = "No environments defined"});
}

tvEnvironments.ItemsSource = envList;
}

private async Task RefreshSecretsAsync(GitHubClient client)
{
var repoSecrets = await client.Repository?.Actions?.Secrets?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
List<string> secretList = new();
if (repoSecrets.TotalCount > 0)
{
tvSecrets.Header = $"Repository Secrets ({repoSecrets.TotalCount})";
foreach (var secret in repoSecrets.Secrets)
{
var updatedOrCreatedAt = secret.UpdatedAt.GetValueOrDefault(secret.CreatedAt);
Expand All @@ -230,6 +263,7 @@ private async Task RefreshSecretsAsync(GitHubClient client)
}
else
{
tvSecrets.Header = $"Repository Secrets";
secretList.Add("No repository secrets defined");
}
tvSecrets.ItemsSource = secretList;
Expand Down

0 comments on commit 8ab99f1

Please sign in to comment.