| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import * as vscode from 'vscode'; |
| import {println} from '../logger'; |
| import {determineWorkspaceLanguage} from '../utils'; |
| import {cifuzzGenerator} from '../cifuzz'; |
|
|
| export async function setupCIFuzzHandler() { |
| const workspaceFolder = vscode.workspace.workspaceFolders; |
| if (!workspaceFolder) { |
| return false; |
| } |
|
|
| const wsPath = workspaceFolder[0].uri.fsPath; |
|
|
| |
| |
| |
| const githubWorkflowsPath = vscode.Uri.file(wsPath + '/.github/workflows'); |
| try { |
| await vscode.workspace.fs.readDirectory(githubWorkflowsPath); |
| } catch { |
| println('Did not find a workflows path.'); |
| return false; |
| } |
|
|
| for (const [name, type] of await vscode.workspace.fs.readDirectory( |
| githubWorkflowsPath |
| )) { |
| |
| if (type === 2) { |
| continue; |
| } |
|
|
| |
| println('Is a file'); |
| const workflowFile = vscode.Uri.file(wsPath + '/.github/workflows/' + name); |
| const doc = await vscode.workspace.openTextDocument(workflowFile); |
| if (doc.getText().includes('cifuzz')) { |
| println('Found existing CIFuzz, will not continue.'); |
| return false; |
| } |
| } |
|
|
| println('Did not find CIFuzz, creating one.'); |
| const projectName = await vscode.window.showInputBox({ |
| value: '', |
| placeHolder: 'OSS-Fuzz project name', |
| }); |
| if (!projectName) { |
| println('Failed to get project name'); |
| return false; |
| } |
|
|
| |
| |
| |
| |
| const targetLanguage = await determineWorkspaceLanguage(); |
| println('Target language: ' + targetLanguage); |
|
|
| |
| const cifuzzWorkflowText = cifuzzGenerator(targetLanguage, projectName, 30); |
|
|
| |
| |
| const cifuzzYml = vscode.Uri.file(wsPath + '/.github/workflows/cifuzz.yml'); |
| const wsedit = new vscode.WorkspaceEdit(); |
| wsedit.createFile(cifuzzYml, {ignoreIfExists: true}); |
| wsedit.insert(cifuzzYml, new vscode.Position(0, 0), cifuzzWorkflowText); |
| vscode.workspace.applyEdit(wsedit); |
| return true; |
| } |
|
|