How to use the @atomist/sdm.GoalProjectListenerEvent.before 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 / goal / cache / goalCaching.ts View on Github external
async function invokeCacheMissListeners(optsToUse: GoalCacheOptions | GoalCacheRestoreOptions,
                                        p: GitProject,
                                        gi: GoalInvocation,
                                        event: GoalProjectListenerEvent): Promise {
    for (const cacheMissFallback of toArray(optsToUse.onCacheMiss)) {
        const allEvents = [GoalProjectListenerEvent.before, GoalProjectListenerEvent.after];
        if ((cacheMissFallback.events || allEvents).filter(e => e === event).length > 0
            && await pushTestSucceeds(cacheMissFallback.pushTest, gi, p)) {
            await cacheMissFallback.listener(p, gi, event);
        }
    }
}
github atomist / sdm-core / lib / goal / container / repositoryDrivenContainer.ts View on Github external
const c = new Container({ displayName: this.definition.displayName });
                (c as any).register = () => {
                };
                (c as any).addFulfillment = () => c;
                (c as any).addFulfillmentCallback = () => c;
                (c as any).withProjectListener = () => c;
                c.with(registration);

                return executeDockerJob(c, registration)(gi);
            },
            name: DefaultGoalNameGenerator.generateName(`container-docker-${this.definition.displayName}`),
        });

        this.withProjectListener({
            name: "cache-restore",
            events: [GoalProjectListenerEvent.before],
            listener: async (p, gi, e) => {
                const registration = gi.parameters.registration as ContainerRegistration;
                if (registration.input && registration.input.length > 0) {
                    await cacheRestore({ entries: registration.input }).listener(p, gi, e);
                }
            },
        }).withProjectListener({
            name: "cache-put",
            events: [GoalProjectListenerEvent.after],
            listener: async (p, gi, e) => {
                const registration = gi.parameters.registration as ContainerRegistration;
                if (registration.output && registration.output.length > 0) {
                    await cachePut({ entries: registration.output }).listener(p, gi, e);
                }
            },
        });
github atomist / sdm-core / lib / goal / container / k8s.ts View on Github external
return data;
}

/**
 * If running as isolated goal, use [[executeK8sJob]] to execute the
 * goal.  Otherwise, schedule the goal execution as a Kubernetes job
 * using [[scheduleK8sjob]].
 */
const containerExecutor: ExecuteGoal = gi => (process.env.ATOMIST_ISOLATED_GOAL) ? executeK8sJob()(gi) : scheduleK8sJob(gi);

/**
 * Restore cache input entries before fulfilling goal.
 */
const containerFulfillerCacheRestore: GoalProjectListenerRegistration = {
    name: "ContainerFulfillerCacheRestore",
    events: [GoalProjectListenerEvent.before],
    listener: async (project, gi, event) => {
        const data = parseGoalEventData(gi.goalEvent);
        if (!data[ContainerRegistrationGoalDataKey]) {
            throw new Error(`Goal ${gi.goal.uniqueName} has no Kubernetes container registration: ${gi.goalEvent.data}`);
        }
        const registration: K8sContainerRegistration = data[ContainerRegistrationGoalDataKey];
        if (registration.input && registration.input.length > 0) {
            try {
                const cp = cacheRestore({ entries: registration.input });
                return cp.listener(project, gi, GoalProjectListenerEvent.before);
            } catch (e) {
                const message = `Failed to restore cache input to container for goal ${gi.goal.uniqueName}: ${e.message}`;
                gi.progressLog.write(message);
                return { code: 1, message };
            }
        } else {
github atomist / sdm-core / lib / goal / container / k8s.ts View on Github external
listener: async (project, gi, event) => {
        const data = parseGoalEventData(gi.goalEvent);
        if (!data[ContainerRegistrationGoalDataKey]) {
            throw new Error(`Goal ${gi.goal.uniqueName} has no Kubernetes container registration: ${gi.goalEvent.data}`);
        }
        const registration: K8sContainerRegistration = data[ContainerRegistrationGoalDataKey];
        if (registration.input && registration.input.length > 0) {
            try {
                const cp = cacheRestore({ entries: registration.input });
                return cp.listener(project, gi, GoalProjectListenerEvent.before);
            } catch (e) {
                const message = `Failed to restore cache input to container for goal ${gi.goal.uniqueName}: ${e.message}`;
                gi.progressLog.write(message);
                return { code: 1, message };
            }
        } else {
            return { code: 0, message: "No container input cache entries to restore" };
        }
    },
};
github atomist / sdm-pack-spring / lib / maven / build / helpers.ts View on Github external
export async function mvnVersionProjectListener(p: GitProject,
                                                gi: GoalInvocation,
                                                event: GoalProjectListenerEvent): Promise {
    const command = await determineMavenCommand(p);
    if (event === GoalProjectListenerEvent.before) {
        const v = await readSdmVersion(
            gi.goalEvent.repo.owner,
            gi.goalEvent.repo.name,
            gi.goalEvent.repo.providerId,
            gi.goalEvent.sha,
            gi.goalEvent.branch,
            gi.context);
        return spawnLog(
            command, ["versions:set", `-DnewVersion=${v}`, "versions:commit", ...MavenOptions],
            { cwd: p.baseDir, log: gi.progressLog });
    }
}
github atomist / sdm-core / lib / goal / container / buildingContainer.ts View on Github external
this.addFulfillmentCallback({
            goal: this,
            callback: async (goal, context) => {
                const reg = JSON.parse((goal as any).parameters).registration as ContainerRegistration;
                if (scheduler === "k8s") {
                     const c = new Container({ displayName: this.definition.displayName });
                     return k8sFulfillmentCallback(c, reg)(goal, context);
                 }
                return goal;
            },
        });

        this.withProjectListener({
            name: "cache-restore",
            events: [GoalProjectListenerEvent.before],
            listener: async (p, gi, e) => {
                const reg = gi.parameters.registration as ContainerRegistration;
                if (reg.input && reg.input.length > 0) {
                    await cacheRestore({ entries: reg.input }).listener(p, gi, e);
                }
            },
        }).withProjectListener({
            name: "cache-put",
            events: [GoalProjectListenerEvent.after],
            listener: async (p, gi, e) => {
                const reg = gi.parameters.registration as ContainerRegistration;
                if (reg.output && reg.output.length > 0) {
                    await cachePut({ entries: reg.output }).listener(p, gi, e);
                }
            },
        });
github atomist / sdm-pack-spring / lib / gradle / build / helpers.ts View on Github external
event: GoalProjectListenerEvent): Promise {
    const v = await readSdmVersion(
        gi.goalEvent.repo.owner,
        gi.goalEvent.repo.name,
        gi.goalEvent.repo.providerId,
        gi.goalEvent.sha,
        gi.goalEvent.branch,
        gi.context);
    return changeGradleVersion(v, p);
}

export const GradleVersion: GoalProjectListenerRegistration = {
    name: "gradle version",
    listener: gradleVersionProjectListener,
    pushTest: IsGradle,
    events: [GoalProjectListenerEvent.before],
};

function gradleBuildProjectListener(p: GitProject,
                                    gi: GoalInvocation): Promise {
    return gradleCommand(p, {
        progressLog: gi.progressLog,
        tasks: ["build"],
        args: [{name: "artifact.name", value: p.id.repo}],
        errorFinder: SuccessIsReturn0ErrorFinder,
    });
}

export const GradleBuild: GoalProjectListenerRegistration = {
    name: "gradle build",
    listener: gradleBuildProjectListener,
    pushTest: IsGradle,