Add support for job and step level execution

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-11-30 00:16:49 -05:00
parent d032fe2d3d
commit b96f1c613a
7 changed files with 273 additions and 41 deletions

View File

@@ -1,15 +1,16 @@
import * as path from "path";
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { History, HistoryStatus } from "../../historyManager";
import { TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { History, HistoryManager, HistoryStatus } from "../../historyManager";
import { Utils } from "../../utils";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import JobTreeItem from "./job";
export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.history';
history: History;
constructor(public workspaceFolder: WorkspaceFolder, history: History) {
super(`${history.name} #${history.count}`, TreeItemCollapsibleState.None);
super(`${history.name} #${history.count}`, TreeItemCollapsibleState.Collapsed);
this.history = history;
let endTime: string | undefined;
@@ -24,20 +25,7 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
this.description = totalDuration;
this.contextValue = `${HistoryTreeItem.contextValue}_${history.status}`;
switch (history.status) {
case HistoryStatus.Running:
this.iconPath = new ThemeIcon('loading~spin');
break;
case HistoryStatus.Success:
this.iconPath = new ThemeIcon('pass', new ThemeColor('GitHubLocalActions.green'));
break;
case HistoryStatus.Failed:
this.iconPath = new ThemeIcon('error', new ThemeColor('GitHubLocalActions.red'));
break;
case HistoryStatus.Cancelled:
this.iconPath = new ThemeIcon('circle-slash', new ThemeColor('GitHubLocalActions.yellow'));
break;
}
this.iconPath = HistoryManager.statusToIcon(history.status);
this.tooltip = `Name: ${history.name} #${history.count}\n` +
`${history.commandArgs.extraHeader.map(header => `${header.key}: ${header.value}`).join('\n')}\n` +
`Path: ${history.commandArgs.path}\n` +
@@ -46,14 +34,14 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
`Started: ${Utils.getDateString(history.date.start)}\n` +
`Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` +
`Total Duration: ${totalDuration ? totalDuration : 'N/A'}`;
this.command = {
title: 'Focus Task',
command: 'githubLocalActions.focusTask',
arguments: [this]
};
// this.command = {
// title: 'Focus Task',
// command: 'githubLocalActions.focusTask',
// arguments: [this]
// };
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
return this.history.jobs?.map(job => new JobTreeItem(this.workspaceFolder, job)) || [];
}
}

38
src/views/history/job.ts Normal file
View File

@@ -0,0 +1,38 @@
import { TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { HistoryManager, HistoryStatus, Job } from "../../historyManager";
import { Utils } from "../../utils";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
import StepTreeItem from "./step";
export default class JobTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.job';
job: Job;
constructor(public workspaceFolder: WorkspaceFolder, job: Job) {
super(job.name, TreeItemCollapsibleState.Expanded);
this.job = job;
let endTime: string | undefined;
let totalDuration: string | undefined;
if (job.date.end) {
endTime = job.date.end;
totalDuration = Utils.getTimeDuration(job.date.start, endTime);
} else if (job.status === HistoryStatus.Running) {
endTime = new Date().toString();
totalDuration = Utils.getTimeDuration(job.date.start, endTime);
}
this.description = totalDuration;
this.contextValue = `${JobTreeItem.contextValue}_${job.status}`;
this.iconPath = HistoryManager.statusToIcon(job.status);
this.tooltip = `Name: ${job.name}\n` +
`Status: ${job.status}\n` +
`Started: ${Utils.getDateString(job.date.start)}\n` +
`Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` +
`Total Duration: ${totalDuration ? totalDuration : 'N/A'}`;
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return this.job.steps?.map(step => new StepTreeItem(this.workspaceFolder, step)) || [];
}
}

37
src/views/history/step.ts Normal file
View File

@@ -0,0 +1,37 @@
import { TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { HistoryManager, HistoryStatus, Step } from "../../historyManager";
import { Utils } from "../../utils";
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
export default class StepTreeItem extends TreeItem implements GithubLocalActionsTreeItem {
static contextValue = 'githubLocalActions.step';
step: Step;
constructor(public workspaceFolder: WorkspaceFolder, step: Step) {
super(step.name, TreeItemCollapsibleState.None);
this.step = step;
let endTime: string | undefined;
let totalDuration: string | undefined;
if (step.date.end) {
endTime = step.date.end;
totalDuration = Utils.getTimeDuration(step.date.start, endTime);
} else if (step.status === HistoryStatus.Running) {
endTime = new Date().toString();
totalDuration = Utils.getTimeDuration(step.date.start, endTime);
}
this.description = totalDuration;
this.contextValue = `${StepTreeItem.contextValue}_${step.status}`;
this.iconPath = HistoryManager.statusToIcon(step.status);
this.tooltip = `Name: ${step.name}\n` +
`Status: ${step.status}\n` +
`Started: ${Utils.getDateString(step.date.start)}\n` +
`Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` +
`Total Duration: ${totalDuration ? totalDuration : 'N/A'}`;
}
async getChildren(): Promise<GithubLocalActionsTreeItem[]> {
return [];
}
}

View File

@@ -307,9 +307,9 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
];
options.forEach((option, index) => {
options[index].label = options[index].label.slice(2)
options[index].label = options[index].label.slice(2);
options[index].iconPath = new ThemeIcon('symbol-property');
})
});
const settings = await act.settingsManager.getSettings(optionsTreeItem.workspaceFolder, false);
const optionNames = settings.options.map(option => option.name);