Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logger.debug(`Goal ${sdmGoal.uniqueName} has been canceled. Not fulfilling`);
return Success;
}
if (sdmGoal.fulfillment.method === SdmGoalFulfillmentMethod.SideEffect &&
sdmGoal.fulfillment.registration !== this.configuration.name) {
logger.debug("Not fulfilling side-effected goal '%s' with method '%s/%s'",
sdmGoal.uniqueName, sdmGoal.fulfillment.method, sdmGoal.fulfillment.name);
return Success;
} else if (sdmGoal.fulfillment.method === SdmGoalFulfillmentMethod.Other) {
// fail goal with neither Sdm nor SideEffect fulfillment
await updateGoal(
ctx,
sdmGoal,
{
state: SdmGoalState.failure,
description: `No fulfillment for ${sdmGoal.uniqueName}`,
});
return Success;
}
const id = this.configuration.sdm.repoRefResolver.repoRefFromSdmGoal(sdmGoal);
const credentials = await resolveCredentialsPromise(this.configuration.sdm.credentialsResolver.eventHandlerCredentials(ctx, id));
const addressChannels = addressChannelsFor(sdmGoal.push.repo, ctx);
const preferences = this.configuration.sdm.preferenceStoreFactory(ctx);
const implementation = this.implementationMapper.findImplementationBySdmGoal(sdmGoal);
const { goal } = implementation;
const progressLog = new WriteToAllProgressLog(
sdmGoal.name,
new LoggingProgressLog(sdmGoal.name, "debug"),
const start = Date.now();
try {
const result = await executeGoal(
{
projectLoader: this.configuration.sdm.projectLoader,
goalExecutionListeners: this.goalExecutionListeners,
},
{
...implementation,
projectListeners: [...toArray(implementation.projectListeners || []), ...listeners],
},
goalInvocation);
const terminatingStates = [
SdmGoalState.canceled,
SdmGoalState.failure,
SdmGoalState.skipped,
SdmGoalState.stopped,
SdmGoalState.success,
SdmGoalState.waiting_for_approval,
];
if (!result || !result.state || terminatingStates.includes(result.state)) {
await reportEndAndClose(result, start, progressLog);
}
return {
...result,
// successfully handled event even if goal failed
code: 0,
};
} catch (e) {
e.message = `Goal executor threw exception: ${e.message}`;
const egr: ExecuteGoalResult = {
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;
}
}
export async function defaultDestinationFactory(goal: SdmGoalEvent): Promise {
if (goal.state === SdmGoalState.failure) {
return _.uniqBy(goal.push.commits.map(c => _.get(c, "author.person.chatId"))
.filter(c => !!c), r => `${r.chatTeam.id}.${r.screenName}`)
.map(r => addressSlackUsers(r.chatTeam.id, r.screenName));
}
return undefined;
}
function isGoalRejected(sdmGoal: SdmGoalEvent): boolean {
return sdmGoal.state === SdmGoalState.failure && sdmGoal.description === `Rejected: ${sdmGoal.name}`;
}
async function rejectGoal(reason: string,
sdmGoal: SdmGoalEvent,
ctx: HandlerContext): Promise {
await updateGoal(
ctx,
sdmGoal,
{
state: SdmGoalState.failure,
description: `Rejected: ${sdmGoal.name}`,
phase: reason,
});
}
...QueryNoCacheOptions,
log: configurationValue("sdm.query.logging", false),
},
})).SdmGoal;
const state = !!options && !!options.state ? options.state : SdmGoalState.canceled;
for (const goal of gs) {
if (goal.ts < end) {
logger.debug(
`Canceling goal '${goal.uniqueName}' of goal set '${goal.goalSetId}' because it timed out after '${formatDuration(timeout)}'`);
let description = `${state === SdmGoalState.canceled ? "Canceled" : "Failed"}: ${goal.name}`;
if (!!goal.descriptions) {
if (state === SdmGoalState.canceled && !!goal.descriptions.canceled) {
description = goal.descriptions.canceled;
} else if (state === SdmGoalState.failure && !!goal.descriptions.failed) {
description = goal.descriptions.failed;
}
}
await updateGoal(
ctx,
goal as any,
{
state,
description,
phase: `${formatDuration(timeout)} timeout`,
});
}
}
}
if (!shouldHandle(failedGoal)) {
logger.debug(`Goal ${failedGoal.uniqueName} skipped because not managed by this SDM`);
return Success;
}
await verifyGoal(failedGoal, this.configuration.sdm.goalSigning, context);
const goals = fetchGoalsFromPush(failedGoal);
const goalsToSkip = goals.filter(g => isDependentOn(failedGoal, g, mapKeyToGoal(goals)))
.filter(g => g.state === "planned");
let failedGoalState;
let failedGoalDescription;
switch (failedGoal.state) {
case SdmGoalState.failure:
failedGoalDescription = "failed";
failedGoalState = SdmGoalState.skipped;
break;
case SdmGoalState.stopped:
failedGoalDescription = "stopped goals";
failedGoalState = SdmGoalState.skipped;
break;
case SdmGoalState.canceled:
failedGoalDescription = "was canceled";
failedGoalState = SdmGoalState.canceled;
break;
}
await Promise.all(goalsToSkip.map(g => updateGoal(context, g, {
state: failedGoalState,
description: `${failedGoalState === SdmGoalState.skipped ? "Skipped" : "Canceled"
} ${g.name} because ${failedGoal.name} ${failedGoalDescription}`,