How to use the @atomist/sdm.SdmGoalState.failure function in @atomist/sdm

To help you get started, we’ve selected a few @atomist/sdm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomist / sdm-core / lib / handlers / events / delivery / goals / FulfillGoalOnRequested.ts View on Github external
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"),
github atomist / sdm-core / lib / handlers / events / delivery / goals / FulfillGoalOnRequested.ts View on Github external
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 = {
github atomist / sdm-core / lib / handlers / events / delivery / build / SetStatusOnBuildComplete.ts View on Github external
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;
    }
}
github atomist / sdm-core / lib / pack / notification / notification.ts View on Github external
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;
}
github atomist / sdm-core / lib / internal / signing / goalSigning.ts View on Github external
function isGoalRejected(sdmGoal: SdmGoalEvent): boolean {
    return sdmGoal.state === SdmGoalState.failure && sdmGoal.description === `Rejected: ${sdmGoal.name}`;
}
github atomist / sdm-core / lib / internal / signing / goalSigning.ts View on Github external
async function rejectGoal(reason: string,
                          sdmGoal: SdmGoalEvent,
                          ctx: HandlerContext): Promise {
    await updateGoal(
        ctx,
        sdmGoal,
        {
            state: SdmGoalState.failure,
            description: `Rejected: ${sdmGoal.name}`,
            phase: reason,
        });
}
github atomist / sdm-core / lib / pack / goal-state / manageGoalSets.ts View on Github external
...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`,
                });
        }
    }
}
github atomist / sdm-core / lib / handlers / events / delivery / goals / SkipDownstreamGoalsOnGoalFailure.ts View on Github external
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}`,