Skip to content

Commit 326cf7c

Browse files
committed
Fix pending jobs
When jobs were running it was breaking due to a Conclusion not existing yet
1 parent 5bf4901 commit 326cf7c

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

src/Converters/ConclusionColorConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
2222
"success" => new SolidColorBrush(Colors.Green),
2323
"failure" => new SolidColorBrush(Colors.Red),
2424
"startup_failure" => new SolidColorBrush(Colors.Red),
25+
"waiting" => new SolidColorBrush(Color.FromRgb(154, 103, 0)),
2526
_ => new SolidColorBrush(Colors.Black),
2627
};
2728
}

src/ToolWindows/GHActionsToolWindow.xaml.cs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void ShowInfoMessage(string messageString)
103103

104104
private void ClearTreeViews()
105105
{
106-
tvSecrets.Items.Clear();
106+
tvSecrets.ItemsSource = null;
107107
tvCurrentBranch.ItemsSource = null;
108108
CurrentBranchExpander.IsExpanded = false;
109109
}
@@ -125,29 +125,7 @@ private async Task LoadDataAsync()
125125
try
126126
{
127127
// get secrets
128-
var repoSecrets = await client.Repository?.Actions?.Secrets?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
129-
if (repoSecrets.TotalCount > 0)
130-
{
131-
foreach (var secret in repoSecrets.Secrets)
132-
{
133-
var updatedOrCreatedAt = secret.UpdatedAt.GetValueOrDefault(secret.CreatedAt);
134-
var item = new TreeViewItem
135-
{
136-
Header = $"{secret.Name} ({updatedOrCreatedAt:g})",
137-
Tag = secret,
138-
};
139-
140-
tvSecrets.Items.Add(item);
141-
}
142-
}
143-
else
144-
{
145-
var noSecretItem = new TreeViewItem
146-
{
147-
Header = "No repository secrets defined"
148-
};
149-
tvSecrets.Items.Add(noSecretItem);
150-
}
128+
await RefreshSecretsAsync(client);
151129

152130
// get current branch
153131
var runs = await client.Actions?.Workflows?.Runs?.List(_repoInfo.RepoOwner, _repoInfo.RepoName, new WorkflowRunsRequest() { Branch = _repoInfo.CurrentBranch }, new ApiOptions() { PageCount = 1, PageSize = maxRuns });
@@ -163,7 +141,7 @@ private async Task LoadDataAsync()
163141
{
164142
SimpleRun simpleRun = new()
165143
{
166-
Conclusion = run.Conclusion.Value.StringValue,
144+
Conclusion = run.Conclusion is not null ? run.Conclusion.Value.StringValue : run.Status.StringValue,
167145
Name = run.Name,
168146
LogDate = run.UpdatedAt,
169147
Id = run.Id.ToString(),
@@ -183,14 +161,14 @@ private async Task LoadDataAsync()
183161
{
184162
steps.Add(new SimpleJob()
185163
{
186-
Conclusion = step.Conclusion.Value.StringValue,
164+
Conclusion = step.Conclusion is not null ? step.Conclusion.Value.StringValue : step.Status.StringValue,
187165
Name = step.Name,
188166
Url = $"{job.HtmlUrl}#step:{step.Number.ToString()}:1"
189167
});
190168
}
191169
simpleJobs.Add(new SimpleJob()
192170
{
193-
Conclusion = job.Conclusion.Value.StringValue,
171+
Conclusion = job.Conclusion is not null ? job.Conclusion.Value.StringValue : job.Status.StringValue,
194172
Name = job.Name,
195173
Id = job.Id.ToString(),
196174
Jobs = steps // add the steps to the job
@@ -228,12 +206,23 @@ private async Task LoadDataAsync()
228206
refreshProgress.IsIndeterminate = false;
229207
}
230208

231-
private UIElement CreateEmojiContent(string emojiString)
209+
private async Task RefreshSecretsAsync(GitHubClient client)
232210
{
233-
var emojiBlock = new Emoji.Wpf.TextBlock();
234-
emojiBlock.Text = emojiString;
235-
236-
return emojiBlock;
211+
var repoSecrets = await client.Repository?.Actions?.Secrets?.GetAll(_repoInfo.RepoOwner, _repoInfo.RepoName);
212+
List<string> secretList = new();
213+
if (repoSecrets.TotalCount > 0)
214+
{
215+
foreach (var secret in repoSecrets.Secrets)
216+
{
217+
var updatedOrCreatedAt = secret.UpdatedAt.GetValueOrDefault(secret.CreatedAt);
218+
secretList.Add($"{secret.Name} ({updatedOrCreatedAt:g})");
219+
}
220+
}
221+
else
222+
{
223+
secretList.Add("No repository secrets defined");
224+
}
225+
tvSecrets.ItemsSource = secretList;
237226
}
238227

239228
private static GitHubClient GetGitHubClient()

0 commit comments

Comments
 (0)