init workflows view

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-09-26 20:06:17 -04:00
parent 1b1af97923
commit 003d2c39b4
10 changed files with 179 additions and 43 deletions

View File

@@ -0,0 +1,36 @@
import * as fs from "fs/promises";
import * as path from "path";
import { workspace } from "vscode";
import * as yaml from "yaml";
import { Workflow } from "../types";
export class WorkflowManager {
async getWorkflows(): Promise<Workflow[]> {
const workflows: Workflow[] = [];
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
const workflowFiles = await workspace.findFiles(`.github/workflows/*.{yml,yaml}`);
for await (const workflowFile of workflowFiles) {
try {
const fileContent = await fs.readFile(workflowFile.fsPath, 'utf8');
workflows.push({
name: path.parse(workflowFile.fsPath).name,
path: workflowFile.fsPath,
content: yaml.parse(fileContent)
});
} catch (error) {
workflows.push({
name: path.parse(workflowFile.fsPath).name,
path: workflowFile.fsPath,
error: 'Failed to parse workflow file'
});
}
}
}
return workflows;
}
}