How to use the @atomist/automation-client.Secrets.OrgToken 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 / src / handlers / events / delivery / deploy / k8s / NoticeK8sDeployCompletion.ts View on Github external
// TODO parameterize once we can have multiple handlers

/**
 * Deploy a published artifact identified in an ImageLinked event.
 */
@EventHandler("Request k8s deploy of linked artifact",
    subscription({
        name: "OnAParticularStatus",
        variables: {
            context: k8AutomationDeployContext(K8sTestingDomain),
        }},
    ),
)
export class NoticeK8sTestDeployCompletionOnStatus implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private readonly githubToken: string;

    /**
     *
     * @param {Goal} deployGoal
     * @param {Goal} endpointGoal
     */
    constructor(private readonly deployGoal: Goal,
                private readonly endpointGoal: Goal) {
    }

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

        if (status.state === "pending") { // in_process
github atomist / sdm / src / pack / dry-run / support / OnDryRunBuildComplete.ts View on Github external
import { EventFired, EventHandler, HandleEvent, HandlerContext, HandlerResult, logger, Secret, Secrets, Success } from "@atomist/automation-client";
import { subscription } from "@atomist/automation-client/graph/graphQL";
import { GitHubRepoRef } from "@atomist/automation-client/operations/common/GitHubRepoRef";
import { raiseIssue } from "@atomist/automation-client/util/gitHub";
import { RepoRefResolver } from "../../../spi/repo-ref/RepoRefResolver";
import { OnBuildCompleteForDryRun } from "../../../typings/types";
import { createStatus } from "../../../util/github/ghub";
import { DryRunContext } from "../dryRunEditorCommand";

/**
 * React to to result of a dry run build to raise a PR or issue
 */
@EventHandler("React to result of a dry run build", subscription("OnBuildCompleteForDryRun"))
export class OnDryRunBuildComplete implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private readonly githubToken: string;

    constructor(private readonly repoRefResolver: RepoRefResolver) {
    }

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

        // TODO currently Github only
        const id = params.repoRefResolver.toRemoteRepoRef(commit.repo, {sha: commit.sha}) as GitHubRepoRef;
        const branch = build.commit.pushes[0].branch;

        logger.debug("Assessing dry run for %j: Statuses=%j", id, commit.statuses);
github atomist / sdm / src / handlers / events / delivery / deploy / DeployFromLocalOnFingerprint.ts View on Github external
PlannedPhase,
    previousPhaseSucceeded,
} from "../../../../common/phases/Phases";
import { addressChannelsFor } from "../../../../common/slack/addressChannels";
import { ArtifactStore } from "../../../../spi/artifact/ArtifactStore";
import { Deployer } from "../../../../spi/deploy/Deployer";
import { TargetInfo } from "../../../../spi/deploy/Deployment";
import { OnDeployToProductionFingerprint } from "../../../../typings/types";
import { deploy } from "./deploy";

// TODO could make more common with other deployer...
@EventHandler("Deploy linked artifact",
    GraphQL.subscriptionFromFile("graphql/subscription/OnDeployToProductionFingerprint.graphql"))
export class DeployFromLocalOnFingerprint implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private githubToken: string;

    constructor(private phases: Phases,
                private ourPhase: PlannedPhase,
                private endpointPhase: PlannedPhase,
                private artifactStore: ArtifactStore,
                public deployer: Deployer,
                private targeter: (id: RemoteRepoRef) => T) {
    }

    public handle(event: EventFired, ctx: HandlerContext, params: this): Promise {
        const fingerprint = event.data.Fingerprint[0];
        const commit = fingerprint.commit;

        // TODO doesn't work as built status isn't in, yet
        // const builtStatus = commit.statuses.find(status => status.context === BuildContext);
github atomist / sdm-core / lib / handlers / events / delivery / deploy / k8s / NoticeK8sDeployCompletion.ts View on Github external
// TODO parameterize once we can have multiple handlers

/**
 * Deploy a published artifact identified in an ImageLinked event.
 */
@EventHandler("Request k8s deploy of linked artifact",
    GraphQL.subscription({
        name: "OnAParticularStatus",
        variables: {
            context: k8AutomationDeployContext(K8sTestingDomain),
        }},
    ),
)
export class NoticeK8sTestDeployCompletionOnStatus implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private readonly githubToken: string;

    /**
     *
     * @param {Goal} deployGoal
     * @param {Goal} endpointGoal
     */
    constructor(private readonly deployGoal: Goal,
                private readonly endpointGoal: Goal) {
    }

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

        if (status.state === "pending") { // in_process
github atomist / sdm / src / handlers / events / delivery / code / OnPendingAutofixStatus.ts View on Github external
import { AutofixRegistration } from "../../../../common/delivery/code/codeActionRegistrations";
import { Goal } from "../../../../common/delivery/goals/Goal";
import { OnAnyPendingStatus, StatusState } from "../../../../typings/types";
import { createStatus } from "../../../../util/github/ghub";

/**
 * Run any autofix editors on a push.
 * Set GitHub success status
 */
@EventHandler("Make autofixes", GraphQL.subscriptionFromFile(
    "../../../../graphql/subscription/OnAnyPendingStatus",
    __dirname),
)
export class OnPendingAutofixStatus implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private githubToken: string;

    private registrations: AutofixRegistration[];

    constructor(public goal: Goal,
                registrations: AutofixRegistration[] = []) {
        this.registrations = registrations;
    }

    public async handle(event: EventFired,
                        context: HandlerContext,
                        params: this): Promise {
        const status = event.data.Status[0];
        const commit = status.commit;

        const repoRefWithSha = new GitHubRepoRef(commit.repo.owner, commit.repo.name, commit.sha);
github atomist / sdm / src / handlers / events / delivery / code / ReactToSemanticDiffsOnPushImpact.ts View on Github external
FingerprintDifferenceInvocation,
    FingerprintDifferenceListener,
    FingerprintValue,
} from "../../../../common/listener/FingerprintDifferenceListener";
import { addressChannelsFor } from "../../../../common/slack/addressChannels";
import * as schema from "../../../../typings/types";
import { toRemoteRepoRef } from "../../../../util/git/repoRef";

/**
 * React to a PushImpact event to react to semantic diffs
 */
@EventHandler("Find semantic diffs from a PushImpact", subscription("OnPushImpact"))
export class ReactToSemanticDiffsOnPushImpact
    implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private readonly githubToken: string;

    constructor(private readonly differenceListeners: FingerprintDifferenceListener[]) {
    }

    public async handle(event: EventFired,
                        context: HandlerContext,
                        params: this): Promise {
        const pushImpact = event.data.PushImpact[0];

        const after = pushImpact.push.after;
        const id = toRemoteRepoRef(after.repo, { sha: after.sha });

        const oldFingerprints = pushImpact.push.before.fingerprints;
        const newFingerprints = after.fingerprints;
github atomist / sdm / src / handlers / events / delivery / superseded / SetSupersededStatus.ts View on Github external
} from "@atomist/automation-client";
import { subscription } from "@atomist/automation-client/graph/graphQL";
import { GitHubRepoRef } from "@atomist/automation-client/operations/common/GitHubRepoRef";
import { OnPushWithBefore } from "../../../../typings/types";
import { createStatus } from "../../../../util/github/ghub";
import { truncateCommitMessage } from "../../../../util/lifecycleHelpers";

export const SupersededContext = "superseded/atomist";

/**
 * Set superseded status on previous commit on a push
 */
@EventHandler("Scan code on master", subscription("OnPushWithBefore"))
export class SetSupersededStatus implements HandleEvent {

    @Secret(Secrets.OrgToken)
    private readonly githubToken: string;

    public async handle(event: EventFired,
                        ctx: HandlerContext,
                        params: this): Promise {
        const push = event.data.Push[0];
        const id = new GitHubRepoRef(push.repo.owner, push.repo.name, push.before.sha);
        createStatus(params.githubToken, id, {
            context: SupersededContext,
            state: "error",
            description: `Superseded by \`${push.after.sha.substring(0, 7)}\`: _${truncateCommitMessage(push.after.message, push.repo)}_`,
            target_url: `${id.url}/tree/${id.sha}`,
        });

        return Success;
    }
github atomist / sdm / src / handlers / events / delivery / ExecuteGoalOnSuccessStatus.ts View on Github external
import { providerIdFromStatus } from "../../../util/git/repoRef";
import { executeGoal, validSubscriptionName } from "./verify/executeGoal";

/**
 * Execute a goal on a success status
 */
export class ExecuteGoalOnSuccessStatus
    implements HandleEvent,
        ExecuteGoalInvocation,
        EventHandlerMetadata {

    public subscriptionName: string;
    public subscription: string;
    public name: string;
    public description: string;
    public secrets = [{name: "githubToken", uri: Secrets.OrgToken}];

    public githubToken: string;
    public readonly implementationName: string;

    constructor(implementationName: string,
                public goal: Goal,
                private readonly execute: GoalExecutor,
                private readonly handleGoalUpdates: boolean = false) {
        this.implementationName = validSubscriptionName(implementationName);
        this.subscriptionName = this.implementationName + "OnSuccessStatus";
        this.name = this.subscriptionName + "OnSuccessStatus";
        this.description = `Execute ${goal.name} on prior goal success`;
        this.subscription =
            subscription({name: "OnAnySuccessStatus", operationName: this.subscriptionName});
    }
github atomist / sdm-core / lib / handlers / common / GitHubCredentialsResolver.ts View on Github external
        let secret = actx.trigger.secrets.find(s => s.uri === Secrets.OrgToken);
        if (secret && hasToken(secret.value)) {
github atomist / sdm-core / lib / handlers / common / GitHubCredentialsResolver.ts View on Github external
import * as _ from "lodash";
import {
    GitHubAppInstallationByOwner,
    ProviderType,
    ScmProviderByType,
} from "../../typings/types";

/**
 * Type to implement different strategies to obtain a GitHub token
 */
type ObtainToken = (context: HandlerContext, id?: RemoteRepoRef) => Promise;

@Parameters()
export class GitHubCredentialsResolver implements CredentialsResolver {

    @Secret(Secrets.OrgToken)
    public readonly orgToken: string;

    public async eventHandlerCredentials(context: HandlerContext,
                                         id?: RemoteRepoRef): Promise {
        return this.credentials(
            [
                obtainTokenFromConfiguration(this),
                ObtainTokenFromIncomingMessage,
                ObtainTokenFromGitHubApp,
                ObtainTokenFromProvider,
            ],
            context,
            id);
    }

    public async commandHandlerCredentials(context: HandlerContext,