Refactor to use workspace folders
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as fs from "fs/promises";
|
||||
import * as path from "path";
|
||||
import { Uri, workspace } from "vscode";
|
||||
import { RelativePattern, Uri, workspace, WorkspaceFolder } from "vscode";
|
||||
import * as yaml from "yaml";
|
||||
|
||||
export interface Workflow {
|
||||
@@ -17,33 +17,29 @@ export interface Job {
|
||||
}
|
||||
|
||||
export class WorkflowsManager {
|
||||
async getWorkflows(): Promise<Workflow[]> {
|
||||
async getWorkflows(workspaceFolder: WorkspaceFolder): Promise<Workflow[]> {
|
||||
const workflows: Workflow[] = [];
|
||||
|
||||
const workspaceFolders = workspace.workspaceFolders;
|
||||
if (workspaceFolders && workspaceFolders.length > 0) {
|
||||
const workflowFileUris = await workspace.findFiles(`.github/workflows/*.{yml,yaml}`);
|
||||
const workflowFileUris = await workspace.findFiles(new RelativePattern(workspaceFolder, `.github/workflows/*.{yml,yaml}`));
|
||||
for await (const workflowFileUri of workflowFileUris) {
|
||||
let yamlContent: any | undefined;
|
||||
|
||||
for await (const workflowFileUri of workflowFileUris) {
|
||||
let yamlContent: any | undefined;
|
||||
try {
|
||||
const fileContent = await fs.readFile(workflowFileUri.fsPath, 'utf8');
|
||||
yamlContent = yaml.parse(fileContent);
|
||||
|
||||
try {
|
||||
const fileContent = await fs.readFile(workflowFileUri.fsPath, 'utf8');
|
||||
yamlContent = yaml.parse(fileContent);
|
||||
|
||||
workflows.push({
|
||||
name: yamlContent.name || path.parse(workflowFileUri.fsPath).name,
|
||||
uri: workflowFileUri,
|
||||
fileContent: fileContent,
|
||||
yaml: yaml.parse(fileContent)
|
||||
});
|
||||
} catch (error) {
|
||||
workflows.push({
|
||||
name: (yamlContent ? yamlContent.name : undefined) || path.parse(workflowFileUri.fsPath).name,
|
||||
uri: workflowFileUri,
|
||||
error: 'Failed to parse workflow file.'
|
||||
});
|
||||
}
|
||||
workflows.push({
|
||||
name: yamlContent.name || path.parse(workflowFileUri.fsPath).name,
|
||||
uri: workflowFileUri,
|
||||
fileContent: fileContent,
|
||||
yaml: yaml.parse(fileContent)
|
||||
});
|
||||
} catch (error) {
|
||||
workflows.push({
|
||||
name: (yamlContent ? yamlContent.name : undefined) || path.parse(workflowFileUri.fsPath).name,
|
||||
uri: workflowFileUri,
|
||||
error: 'Failed to parse workflow file.'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user