How to use the @atomist/automation-client.guid function in @atomist/automation-client

To help you get started, we’ve selected a few @atomist/automation-client 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 / internal / machine / configureSdm.ts View on Github external
function configureSdmToRunExactlyOneGoal(mergedConfig: SoftwareDeliveryMachineConfiguration,
                                         sdm: SoftwareDeliveryMachine): void {
    if (process.env.ATOMIST_JOB_NAME) {
        mergedConfig.name = process.env.ATOMIST_REGISTRATION_NAME;
    } else {
        mergedConfig.name = `${mergedConfig.name}-${process.env.ATOMIST_GOAL_ID || guid()}`;
    }

    // Force ephemeral policy and no handlers or ingesters
    mergedConfig.policy = "ephemeral";
    mergedConfig.commands = [];
    mergedConfig.events = [
        () => new FulfillGoalOnRequested(
            sdm.goalFulfillmentMapper,
            [...sdm.goalExecutionListeners])];
    mergedConfig.ingesters = [];
    mergedConfig.ws.enabled = false;
    mergedConfig.cluster.enabled = false;

    mergedConfig.listeners.push(
        new GoalExecutionAutomationEventListener(sdm),
        new CacheCleanupAutomationEventListener(sdm));
github atomist / sdm-core / lib / handlers / events / delivery / goals / goalExecution.ts View on Github external
public async startupSuccessful(client: AutomationClient): Promise {
        if (cluster.isMaster) {
            const teamId = process.env.ATOMIST_GOAL_TEAM;
            const teamName = process.env.ATOMIST_GOAL_TEAM_NAME || teamId;
            const goalSetId = [process.env.ATOMIST_GOAL_SET_ID];
            const uniqueName = [process.env.ATOMIST_GOAL_UNIQUE_NAME];
            const correlationId = process.env.ATOMIST_CORRELATION_ID || guid();

            // Obtain goal via graphql query
            const graphClient = new ApolloGraphClient(
                `${this.sdm.configuration.endpoints.graphql}/${teamId}`,
                { Authorization: `Bearer ${client.configuration.apiKey}` });

            const goal = await graphClient.query({
                name: "SdmGoalsByGoalSetIdAndUniqueName",
                variables: {
                    goalSetId,
                    uniqueName,
                },
                options: QueryNoCacheOptions,
            });

            // Create event and run event handler
github atomist / sdm / lib / api-helper / command / transform / chattyDryRunAwareEditor.ts View on Github external
async function sendDryRunSummaryMessage(codeTransformName: string,
                                        id: RemoteRepoRef,
                                        diff: string,
                                        params: any,
                                        ctx: HandlerContext): Promise {
    const msgId = guid();
    const applyAction = {
        actions: [
            buttonForCommand(
                { text: "Apply Transform" },
                codeTransformName,
                {
                    // reuse the other parameters, but set the dryRun flag to false and pin to one repo
                    ...params,
                    "dry-run": false,
                    "dry-run.msgId": msgId,
                    "targets.sha": params.targets.sha,
                    "targets.owner": id.owner,
                    "targets.repo": id.repo,
                }),
        ],
    };
github atomist / sdm-core / lib / goal / container / k8s.ts View on Github external
delete spec.containers[0].workingDir;
        } else if (!spec.containers[0].workingDir) {
            spec.containers[0].workingDir = ContainerProjectHome;
        }

        const goalSchedulers: GoalScheduler[] = toArray(repoContext.configuration.sdm.goalScheduler) || [];
        const k8sScheduler = goalSchedulers.find(gs => gs instanceof KubernetesGoalScheduler) as KubernetesGoalScheduler;
        if (!k8sScheduler) {
            throw new Error("Failed to find KubernetesGoalScheduler in goal schedulers");
        }
        if (!k8sScheduler.podSpec) {
            throw new Error("KubernetesGoalScheduler has no podSpec defined");
        }

        const containerEnvs = await containerEnvVars(goalEvent, repoContext);
        const projectVolume = `project-${guid().split("-")[0]}`;
        const inputVolume = `input-${guid().split("-")[0]}`;
        const outputVolume = `output-${guid().split("-")[0]}`;
        const ioVolumes = [
            {
                name: projectVolume,
                emptyDir: {},
            },
            {
                name: inputVolume,
                emptyDir: {},
            },
            {
                name: outputVolume,
                emptyDir: {},
            },
        ];
github atomist / sdm / lib / api-helper / misc / slack / messages.ts View on Github external
export function slackSuccessMessage(title: string, text: string, options: Partial = {}): SlackMessage {
    const msg: SlackMessage = {
        attachments: [{
            author_icon: `https://images.atomist.com/rug/check-circle.gif?gif=${guid()}`,
            author_name: title,
            text,
            fallback: text,
            color: "#37A745",
            mrkdwn_in: ["text"],
            footer: slackFooter(),
            ts: slackTs(),
            ...options,
        }],
    };
    return msg;
}
github atomist / sdm-core / lib / pack / goal-state / updateGoal.ts View on Github external
goal.preApproval = prov;
                goal.preApprovalRequired = false;
            }

            goal.state = ci.parameters.state;
            goal.ts = Date.now();
            goal.version = (goal.version || 0) + 1;
            delete (goal as any).id;

            await storeGoal(ci.context, goal as any);
            return ci.context.messageClient.respond(
                slackSuccessMessage(
                    "Set Goal State",
                    `Successfully set state of ${italic(goal.name)} on ${codeLine(goal.sha.slice(0, 7))} of ${
                        bold(`${goal.repo.owner}/${goal.repo.name}/${goal.branch}`)} to ${italic(ci.parameters.state)}`),
                { id: ci.parameters.msgId || guid()});
        },
    };
github atomist / sdm-core / lib / pack / goal-state / cancelGoals.ts View on Github external
listener: async ci => {
            const id = ci.parameters.msgId || guid();
            if (!!ci.parameters.goalSetId) {
                await cancelGoalSet(ci.parameters.goalSetId, ci.context, id);
            } else {
                let pgs = await pendingGoalSets(ci.context, sdm.configuration.name);
                let count = 0;
                while (pgs.length > 0) {
                    for (const pg of pgs) {
                        await cancelGoalSet(pg.goalSetId, ci.context);
                        count++;
                    }
                    pgs = await pendingGoalSets(ci.context, sdm.configuration.name);
                }
                await ci.context.messageClient.respond(
                    slackSuccessMessage(
                        "Cancel Goal Sets",
                        `Successfully canceled ${count} pending goal ${count > 1 ? "sets" : "set"}`));
github atomist / sdm-core / lib / pack / goal-state / manageGoalSets.ts View on Github external
ses.run(async () => {
                    const id = guid();
                    namespace.set({
                        invocationId: id,
                        correlationId: id,
                        workspaceName: workspaceId,
                        workspaceId,
                        operation: "ManagePendingGoalSets",
                        ts: Date.now(),
                        name: li.sdm.configuration.name,
                        version: li.sdm.configuration.version,
                    });
                    try {
                        const graphClient = li.sdm.configuration.graphql.client.factory.create(workspaceId, li.sdm.configuration);
                        const messageClient = new TriggeredMessageClient(
                            (li.sdm.configuration.ws as any).lifecycle,
                            workspaceId,
                            li.sdm.configuration) as any;
github atomist / sdm-core / lib / internal / github / InvokeFromitHubActionAutomationEventListener.ts View on Github external
sha: event.before,
        },
        commits: event.commits.map((c: any) => ({
            sha: c.sha,
            message: c.message,
            timestamp: c.timestamp,
        })),
    };

    const ei: EventIncoming = {
        data: {
            Push: [push],
        },
        extensions: {
            operationName: "SetGoalsOnPush",
            correlation_id: guid(),
            team_id: client.configuration.workspaceIds && client.configuration.workspaceIds.length > 0
                ? client.configuration.workspaceIds[0] : event.repository.owner.name,
            team_name: os.hostname(),
        },
        secrets: [{
            uri: Secrets.OrgToken,
            value: null,
        }],
    };

    await client.processEvent(ei, async results => {
        const r = await results;
        logger.info(`Returned '${JSON.stringify(r)}'`);
    });
}