Skip to content

Commit

Permalink
Fixing some error condition on secrets node
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Aug 8, 2023
1 parent 0f193c2 commit 2d5ee3c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 9 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.

4 changes: 4 additions & 0 deletions src/Resources/UIStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@
<value>Workflows</value>
<comment>Header for workflow top-level node</comment>
</data>
<data name="INSUFFICIENT_SECRET_PERMS" xml:space="preserve">
<value>Insufficient permissions to retrieve Secrets</value>
<comment>Error for when you don't have perms</comment>
</data>
<data name="LABEL_NAME" xml:space="preserve">
<value>Name:</value>
<comment>Label for secret form for name</comment>
Expand Down
25 changes: 20 additions & 5 deletions src/ToolWindows/GHActionsToolWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private async Task RefreshSecretsAsync(GitHubClient client)
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
await _pane.WriteLineAsync($"Error retrieving Secrets: {ex.Message}:{ex.StatusCode}");
secretList.Add("Insufficient permissions to retrieve Secrets");
secretList.Add(resx.INSUFFICIENT_SECRET_PERMS);
await ex.LogAsync(ex.Message);
}
}
Expand Down Expand Up @@ -410,14 +410,29 @@ private void HandlePreviewMouseWheel(object sender, MouseWheelEventArgs e)

private async void AddSecret_Click(object sender, RoutedEventArgs e)
{
await UpsertRepositorySecret(string.Empty);
try
{
await UpsertRepositorySecret(string.Empty);
}
catch (ApiException ex)
{
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized || ex.StatusCode == System.Net.HttpStatusCode.Forbidden)
{
await _pane.WriteLineAsync($"Error saving Secret: {ex.Message}:{ex.StatusCode}");
await ex.LogAsync(ex.Message);
}
}
catch (Exception ex)
{
await ex.LogAsync();
}
}

private async void EditSecret_Click(object sender, RoutedEventArgs e)
{
MenuItem menuItem = (MenuItem)sender;
TextBlock tvi = GetParentTreeViewItem(menuItem);
if (tvi is not null && tvi.Text.ToLowerInvariant() != resx.NO_REPO_SECRETS.ToLowerInvariant()) // yes a hack
if (tvi is not null && !tvi.Text.ToLowerInvariant().Contains(" (")) // yes a hack
{
string header = tvi.Text.ToString();
string secretName = header.Substring(0, header.IndexOf(" ("));
Expand All @@ -444,7 +459,7 @@ private async void DeleteSecret_Click(object sender, RoutedEventArgs e)
MenuItem menuItem = (MenuItem)sender;
TextBlock tvi = GetParentTreeViewItem(menuItem);

if (tvi is not null && tvi.Text.ToLowerInvariant() != resx.NO_REPO_SECRETS.ToLowerInvariant()) // yes a hack
if (tvi is not null && !tvi.Text.ToLowerInvariant().Contains(" (")) // yes a hack
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
// confirm the delete first
Expand Down Expand Up @@ -528,7 +543,7 @@ private void RunWorkflow_Click(object sender, RoutedEventArgs e)
private async void Secret_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
// get the items Tag
if (sender is TreeViewItem item && item.Header is not null)
if (sender is TreeViewItem item && item.Header is not null && item.Header.ToString().ToLowerInvariant().Contains(" ("))
{
string header = item.Header.ToString();
string secretName = header.Substring(0, header.IndexOf(" ("));
Expand Down

0 comments on commit 2d5ee3c

Please sign in to comment.