Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
const goalScheduler = await findGoalScheduler(goalInvocation, this.configuration);
if (!!goalScheduler) {
const start = Date.now();
const result = await goalScheduler.schedule(goalInvocation);
if (!!result && result.code !== undefined && result.code !== 0) {
await updateGoal(ctx, sdmGoal, {
state: SdmGoalState.failure,
description: `Failed to schedule goal`,
url: progressLog.url,
});
await reportEndAndClose(result, start, progressLog);
} else {
await updateGoal(ctx, sdmGoal, {
state: !!result && !!result.state ? result.state : SdmGoalState.in_process,
phase: !!result && !!result.phase ? result.phase : "scheduled",
description: !!result && !!result.description ? result.description : descriptionFromState(goal, SdmGoalState.in_process, sdmGoal),
url: progressLog.url,
externalUrls: !!result ? result.externalUrls : undefined,
});
}
return {
...result as any,
// successfully handled event even if goal failed
code: 0,
};
} else {
delete (sdmGoal as any).id;
const listeners = [];
const goalScheduler = await findGoalScheduler(goalInvocation, this.configuration);
if (!!goalScheduler) {
const start = Date.now();
const result = await goalScheduler.schedule(goalInvocation);
if (!!result && result.code !== undefined && result.code !== 0) {
await updateGoal(ctx, sdmGoal, {
state: SdmGoalState.failure,
description: `Failed to schedule goal`,
url: progressLog.url,
});
await reportEndAndClose(result, start, progressLog);
} else {
await updateGoal(ctx, sdmGoal, {
state: !!result && !!result.state ? result.state : SdmGoalState.in_process,
phase: !!result && !!result.phase ? result.phase : "scheduled",
description: !!result && !!result.description ? result.description : descriptionFromState(goal, SdmGoalState.in_process, sdmGoal),
url: progressLog.url,
externalUrls: !!result ? result.externalUrls : undefined,
});
}
return {
...result as any,
// successfully handled event even if goal failed
code: 0,
};
} else {
delete (sdmGoal as any).id;
const listeners = [];
// Prepare cache project listeners for parameters
if (!!goalInvocation.parameters) {
try {
await prepareInputAndOutput(inputDir, outputDir, gi);
} catch (e) {
const message = `Failed to prepare input and output for goal ${goalEvent.name}: ${e.message}`;
progressLog.write(message);
return { code: 1, message };
}
const secrets = await prepareSecrets(
_.merge({}, registration.containers[0], ((gi.parameters || {})["@atomist/sdm/secrets"] || {})), gi);
if (!!secrets?.files) {
for (const file of secrets.files) {
await fs.writeFile(file.mountPath, file.value);
}
}
goalEvent.state = SdmGoalState.in_process;
return goalEvent;
});
}
function buildStatusToSdmGoalState(buildStatus: BuildStatus): SdmGoalState {
switch (buildStatus) {
case "passed":
return SdmGoalState.success;
case "broken":
case "failed":
case "canceled":
return SdmGoalState.failure;
default:
return SdmGoalState.in_process;
}
}
return async gei => {
if (gei.goalEvent.state !== SdmGoalState.in_process) {
const fps = await fingerprintFinder(gei);
const pili: PushImpactListenerInvocation = {
...gei,
project: undefined,
impactedSubProject: undefined,
filesChanged: undefined,
commit: gei.goalEvent.push.after,
push: gei.goalEvent.push,
};
return publisher(pili, aspects, toArray(fps), {});
}
return false;
};
}
return async gi => {
const goalEvent = gi.completedGoal;
if (goalEvent.state === SdmGoalState.in_process) {
return;
}
if (goalEvent.state === SdmGoalState.canceled && !(await cancelableGoal(goalEvent, gi.configuration))) {
return;
}
const selector = `atomist.com/goal-set-id=${goalEvent.goalSetId},atomist.com/creator=${sanitizeName(this.sdm.configuration.name)}`;
let jobs;
try {
jobs = await listJobs(selector);
} catch (e) {
logger.warn(`Failed to read k8s jobs: ${prettyPrintError(e)}`);
return;
}