diff --git a/src/extension.ts b/src/extension.ts index d135c85c..f28ef264 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -45,6 +45,8 @@ const reporter = new TelemetryReporter( TELEMETRY_KEY ); +const doNotConfirmRunJob = 'local-ci.job.do-not-confirm'; + export function activate(context: vscode.ExtensionContext): void { if (!context.globalState.get(TRIAL_STARTED_TIMESTAMP)) { context.globalState.update(TRIAL_STARTED_TIMESTAMP, new Date().getTime()); @@ -203,12 +205,31 @@ export function activate(context: vscode.ExtensionContext): void { reporter.sendTelemetryEvent('runJob'); - if (job instanceof Job) { - job.setIsRunning(); - await jobProvider.hardRefresh(job); + if (context.globalState.get(doNotConfirmRunJob)) { + runJob(context, jobName, jobProvider, job); } - runJob(context, jobName, jobProvider, job); + const confirmText = 'Yes'; + const doNotAskAgainText = `Don't ask again`; + vscode.window + .showInformationMessage( + `Do you want to run the job ${jobName}?`, + { modal: true }, + { title: confirmText }, + { title: doNotAskAgainText } + ) + .then((selection) => { + if ( + selection?.title === confirmText || + selection?.title === doNotAskAgainText + ) { + runJob(context, jobName, jobProvider, job); + } + + if (selection?.title === doNotAskAgainText) { + context.globalState.update(doNotConfirmRunJob, true); + } + }); } ), vscode.commands.registerCommand(EXIT_JOB_COMMAND, (job: Job) => { @@ -218,13 +239,42 @@ export function activate(context: vscode.ExtensionContext): void { disposeTerminalsForJob(jobName); }), vscode.commands.registerCommand('local-ci.job.rerun', async (job: Job) => { - job.setIsRunning(); - await jobProvider.hardRefresh(job); const jobName = job.getJobName(); - disposeTerminalsForJob(jobName); + const confirmText = 'Yes'; + const doNotAskAgainText = `Don't ask again`; + + async function rerunJob() { + job.setIsRunning(); + await jobProvider.hardRefresh(job); + disposeTerminalsForJob(jobName); + + reporter.sendTelemetryEvent('rerunJob'); + runJob(context, jobName, jobProvider, job); + } + + if (context.globalState.get(doNotConfirmRunJob)) { + rerunJob(); + } + + vscode.window + .showInformationMessage( + `Do you want to rerun the job ${jobName}?`, + { modal: true }, + { title: confirmText }, + { title: doNotAskAgainText } + ) + .then(async (selection) => { + if ( + selection?.title === confirmText || + selection?.title === doNotAskAgainText + ) { + rerunJob(); + } - reporter.sendTelemetryEvent('rerunJob'); - runJob(context, jobName, jobProvider, job); + if (selection?.title === doNotAskAgainText) { + context.globalState.update(doNotConfirmRunJob, true); + } + }); }), vscode.commands.registerCommand( 'local-ci.debug.repo', diff --git a/src/utils/runJob.ts b/src/utils/runJob.ts index 76221bd0..c577f84a 100644 --- a/src/utils/runJob.ts +++ b/src/utils/runJob.ts @@ -47,6 +47,11 @@ export default async function runJob( jobProvider: JobProvider, job: JobClass | undefined ): Promise { + if (job && job instanceof JobClass) { + job.setIsRunning(); + await jobProvider.hardRefresh(job); + } + const configFilePath = await getConfigFilePath(context); const repoPath = path.dirname(path.dirname(configFilePath)); const terminal = vscode.window.createTerminal({