How to use @atomist/automation-client - 10 common examples

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-pack-aspect / lib / tree / treeUtils.ts View on Github external
function checkNullChildrenInvariant(pt: PlantedTree): void {
    const haveNullChildren: SunburstTree[] = [];
    visit(pt.tree, (l, d) => {
        if (isSunburstTree(l) && l.children === null) {
            haveNullChildren.push(l);
        }
        return true;
    });
    // the tree counts depth from zero
    if (haveNullChildren.length > 0) {
        logger.error("Tree: " + JSON.stringify(pt.tree, undefined, 2));
        throw new Error(`${haveNullChildren.length} tree nodes have null children: ${JSON.stringify(haveNullChildren)}`);
    }
}
github atomist / sdm-core / lib / handlers / commands / ShowBuildLog.ts View on Github external
CommandHandlerRegistration,
    CommandListener,
    LogInterpretation,
} from "@atomist/sdm";
import * as _ from "lodash";
import { BuildUrlBySha } from "../../typings/types";
import { tipOfDefaultBranch } from "../../util/github/ghub";
import { DefaultRepoRefResolver } from "../common/DefaultRepoRefResolver";
import { displayBuildLogFailure } from "../events/delivery/build/SetStatusOnBuildComplete";

@Parameters()
export class DisplayBuildLogParameters {
    @Secret(Secrets.UserToken)
    public githubToken: string;

    @MappedParameter(MappedParameters.GitHubOwner)
    public owner: string;

    @MappedParameter(MappedParameters.GitHubRepository)
    public repo: string;

    @Parameter({ required: false })
    public sha?: string;
}

function displayBuildLogForCommit(interpreter?: LogInterpretation): CommandListener {
    return async cli => {

        const sha = cli.parameters.sha ? cli.parameters.sha :
            await tipOfDefaultBranch(cli.parameters.githubToken,
                new GitHubRepoRef(cli.parameters.owner, cli.parameters.repo)); // TODO: use fetchDefaultBranchTip
github atomist / sdm-core / lib / handlers / events / delivery / goals / CancelGoalOnCanceled.ts View on Github external
public async handle(e: EventFired, ctx: HandlerContext): Promise {

        const sdmGoal = e.data.SdmGoal[0] as SdmGoalEvent;

        if (!(await cancelableGoal(sdmGoal, this.configuration))) {
            logger.info("Not exciting this process because goal can't be canceled");
            return Success;
        }

        await verifyGoal(sdmGoal, this.configuration.sdm.goalSigning, ctx);

        logger.info("Exiting this process because goal was canceled");

        // exit immediately with 0 to make sure k8s doesn't re-schedule this pod
        automationClientInstance().configuration.ws.termination.graceful = false;
        if (cluster.isWorker) {
            await (automationClientInstance().webSocketHandler as ClusterWorkerRequestProcessor).sendShutdown(0, ctx as any);
        }
        safeExit(0);

        return Success;
    }
}
github atomist / sdm / src / handlers / events / gates / StatusApprovalGate.ts View on Github external
public async handle(event: EventFired, ctx: HandlerContext, params: this): Promise {
        const status: Status = event.data.Status[0];
        const commit = status.commit;

        if (!status.targetUrl.endsWith(ApprovalGateParam)) {
            console.log(`********* approval gate got called with status context=[${status.context}]`);
            return Promise.resolve(Success);
        }

        const id = new GitHubRepoRef(commit.repo.owner, commit.repo.name, commit.sha);

        const attachment: slack.Attachment = {
            text: `Approve ${status.context}`,
            fallback: "approve",
            actions: [buttonForCommand({text: `Approve ${status.context}`},
                "StatusToApproved",
                {
                    owner: id.owner,
                    repo: id.repo,
                    sha: id.sha,
                    context: status.context,
                    // messageId,
                })],
        };
        const message: slack.SlackMessage = {
            attachments: [attachment],
github atomist / sdm-core / lib / handlers / events / delivery / build / SetStatusOnBuildComplete.ts View on Github external
descriptionFromState,
    findSdmGoalOnCommit,
    Goal,
    RepoRefResolver,
    SdmGoalEvent,
    SdmGoalFulfillmentMethod,
    SdmGoalState,
    updateGoal,
} from "@atomist/sdm";
import { OnBuildComplete } from "../../../../typings/types";

/**
 * Set build status on complete build
 */
// TODO CD move to sdm-pack-build
@EventHandler("Set build goal to successful on build complete, if it's side-effecting",
    GraphQL.subscription("OnBuildComplete"))
export class SetGoalOnBuildComplete implements HandleEvent {

    constructor(private readonly buildGoals: Goal[],
                private readonly repoRefResolver: RepoRefResolver) {
    }

    public async handle(event: EventFired,
                        ctx: HandlerContext, params: this): Promise {
        const build = event.data.Build[0];
        const commit: OnBuildComplete.Commit = build.commit;

        const id = params.repoRefResolver.toRemoteRepoRef(commit.repo, { sha: commit.sha });
        for (const buildGoal of params.buildGoals) {
            const sdmGoal = await findSdmGoalOnCommit(ctx, id, commit.repo.org.provider.providerId, buildGoal);
            if (!sdmGoal) {
github atomist / sdm / src / handlers / commands / ShowBuildLog.ts View on Github external
import { GitHubRepoRef } from "@atomist/automation-client/operations/common/GitHubRepoRef";
import { RemoteRepoRef } from "@atomist/automation-client/operations/common/RepoId";
import * as _ from "lodash";
import { AddressChannels } from "../../api/context/addressChannels";
import { LogInterpretation } from "../../spi/log/InterpretedLog";
import { BuildUrlBySha } from "../../typings/types";
import { tipOfDefaultBranch } from "../../util/github/ghub";
import { DefaultRepoRefResolver } from "../common/DefaultRepoRefResolver";
import { displayBuildLogFailure } from "../events/delivery/build/SetStatusOnBuildComplete";

@Parameters()
export class DisplayBuildLogParameters {
    @Secret(Secrets.UserToken)
    public githubToken: string;

    @MappedParameter(MappedParameters.GitHubOwner)
    public owner: string;

    @MappedParameter(MappedParameters.GitHubRepository)
    public repo: string;

    @Parameter({required: false})
    public sha?: string;
}

function displayBuildLogForCommit(interpreter?: LogInterpretation) {
    return async (ctx: HandlerContext,
                  params: { githubToken: string, owner: string, repo: string, sha?: string }) => {

        const sha = params.sha ? params.sha :
            await tipOfDefaultBranch(params.githubToken, new GitHubRepoRef(params.owner, params.repo)); // TODO: use fetchDefaultBranchTip
github atomist / sdm-core / lib / handlers / commands / ShowBuildLog.ts View on Github external
} from "@atomist/sdm";
import * as _ from "lodash";
import { BuildUrlBySha } from "../../typings/types";
import { tipOfDefaultBranch } from "../../util/github/ghub";
import { DefaultRepoRefResolver } from "../common/DefaultRepoRefResolver";
import { displayBuildLogFailure } from "../events/delivery/build/SetStatusOnBuildComplete";

@Parameters()
export class DisplayBuildLogParameters {
    @Secret(Secrets.UserToken)
    public githubToken: string;

    @MappedParameter(MappedParameters.GitHubOwner)
    public owner: string;

    @MappedParameter(MappedParameters.GitHubRepository)
    public repo: string;

    @Parameter({ required: false })
    public sha?: string;
}

function displayBuildLogForCommit(interpreter?: LogInterpretation): CommandListener {
    return async cli => {

        const sha = cli.parameters.sha ? cli.parameters.sha :
            await tipOfDefaultBranch(cli.parameters.githubToken,
                new GitHubRepoRef(cli.parameters.owner, cli.parameters.repo)); // TODO: use fetchDefaultBranchTip

        // TODO get rid of hard coding
        const id = new DefaultRepoRefResolver().toRemoteRepoRef(cli.parameters, { sha });
        const ac: AddressChannels = (msg, opts) => cli.context.messageClient.respond(msg, opts);
github atomist / sdm-pack-spring / lib / spring / generate / SpringBootProjectStructure.ts View on Github external
pathExpression: string | PathExpression): Promise {
        const fileHits = await astUtils.findFileMatches(p, parserOrRegistry, globOptions, pathExpression);
        const matches: SpringBootProjectStructure[] = [];

        for (const fh of fileHits) {
            // It's in the default package if no match found
            const packageName: { name: string } = {
                name: fh.file.extension === "java" ?
                    // TODO using package workaround for Antlr bug
                    ((await packageInfo(p, fh.file.path)) || { fqn: "" }).fqn :
                    evaluateScalarValue(fh.fileNode, KotlinPackage) ||
                    "",
            };
            const appClass = fh.matches[0].$value;
            if (packageName && appClass) {
                logger.debug("Successful Spring Boot inference on %j: packageName '%s', '%s'",
                    p.id, packageName.name, appClass);
                matches.push(new SpringBootProjectStructure(packageName.name, appClass, fh.file));
            } else {
                logger.debug("Unsuccessful Spring Boot inference on %j: packageName '%j', '%s'",
                    p.id, packageName, appClass);
            }
        }
        return matches;
    }
github atomist / sdm-pack-spring / lib / spring / generate / SpringBootProjectStructure.ts View on Github external
for (const fh of fileHits) {
            // It's in the default package if no match found
            const packageName: { name: string } = {
                name: fh.file.extension === "java" ?
                    // TODO using package workaround for Antlr bug
                    ((await packageInfo(p, fh.file.path)) || { fqn: "" }).fqn :
                    evaluateScalarValue(fh.fileNode, KotlinPackage) ||
                    "",
            };
            const appClass = fh.matches[0].$value;
            if (packageName && appClass) {
                logger.debug("Successful Spring Boot inference on %j: packageName '%s', '%s'",
                    p.id, packageName.name, appClass);
                matches.push(new SpringBootProjectStructure(packageName.name, appClass, fh.file));
            } else {
                logger.debug("Unsuccessful Spring Boot inference on %j: packageName '%j', '%s'",
                    p.id, packageName, appClass);
            }
        }
        return matches;
    }
github atomist / sdm / src / internal / delivery / goals / support / github / gitHubStatusSetters.ts View on Github external
return async (inv: GoalCompletionListenerInvocation) => {
        const {id, completedGoal, allGoals, credentials} = inv;
        logger.info("Completed goal: '%s' with '%s' in set '%s'",
            goalKeyString(completedGoal), completedGoal.state, completedGoal.goalSetId);

        if (completedGoal.state === "failure") {
            logger.info("Setting GitHub status to failed on %s" + id.sha);
            return createStatus(credentials, id as GitHubRepoRef, {
                context: "sdm/atomist",
                description: `Atomist SDM Goals: ${completedGoal.description}`,
                target_url: "https://app.atomist.com", // TODO: deep link!
                state: "failure",
            });
        }
        if (allSuccessful(allGoals)) {
            logger.info("Setting GitHub status to success on %s", id.sha);
            return createStatus(credentials, id as GitHubRepoRef, {
                context: "sdm/atomist",
                description: `Atomist SDM Goals: all succeeded`,
                target_url: "https://app.atomist.com", // TODO: deep link!
                state: "success",
            });
        }