How to use the @atomist/automation-client/operations/common/GitHubRepoRef.GitHubRepoRef 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 / 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 / src / handlers / commands / ShowBuildLog.ts View on Github external
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

        // TODO get rid of hard coding
        const id = new DefaultRepoRefResolver().toRemoteRepoRef(params, {sha});
        const ac: AddressChannels = (msg, opts) => ctx.messageClient.respond(msg, opts);
        const build = await fetchBuildUrl(ctx, id);

        await displayBuildLogFailure(id, build, ac, interpreter);
        await ctx.messageClient.respond(":heavy_check_mark: Build log displayed for " + sha);
        return Success;
    };
}
github atomist / sdm / src / software-delivery-machine / blueprint / deploy / deployToProd.ts View on Github external
public async handle(ctx: HandlerContext, params: this): Promise {

        const address = (message: slack.SlackMessage | string) => {
            const destination = params.destinationsJson ? JSON.parse(params.destinationsJson) :
                addressSlackUsers(ctx.teamId, params.slackUserName);
            const messageOptions = {id: params.messageId}; // undefined is ok
            return ctx.messageClient.send(message, destination, messageOptions);
        };

        await address(workingMessage(params));

        const id = new GitHubRepoRef(params.owner, params.repo, params.sha);
        const creds = {token: params.githubToken};
        await ProductionDeployPhases.setAllToPending(id, creds);

        const fingerprint: Fingerprint = {
            name: "DeployToProduction",
            version: "1.0",
            data: "do-it",
            sha: "12345",
            abbreviation: "dp",
        };

        await sendFingerprint(id, fingerprint, ctx.teamId);
        // if (result.code === 0) {
        //     await address(successMessage(params));
        // } else {
        //     await address(tryAgainMessage(params, result.message));
github atomist / sdm / src / handlers / events / delivery / deploy / DeployFromLocalOnFingerprint.ts View on Github external
context: BuildContext,
            state: "success", // builtStatus.state,
            description: "This is sadly hardcoded",
            targetUrl: "xxx",
            siblings: fingerprint.commit.statuses,
        };

        if (nothingFailed(statusAndFriends) && !previousPhaseSucceeded(params.phases, params.ourPhase.context, statusAndFriends)) {
            return Promise.resolve(Success);
        }

        if (!currentPhaseIsStillPending(params.ourPhase.context, statusAndFriends)) {
            return Promise.resolve(Success);
        }

        const id = new GitHubRepoRef(commit.repo.owner, commit.repo.name, commit.sha);
        logger.info("Fingerprint deployer deploying image [%s]", fingerprint.commit.image.imageName);
        return deploy({
            deployPhase: params.ourPhase,
            endpointPhase: params.endpointPhase,
            id,
            githubToken: params.githubToken,
            targetUrl: fingerprint.commit.image.imageName,
            artifactStore: params.artifactStore,
            deployer: params.deployer,
            targeter: params.targeter,
            ac: addressChannelsFor(commit.repo, ctx),
            team: ctx.teamId,
            logFactory: createEphemeralProgressLog,
        })
            .then(success);
    }
github atomist / sdm / src / software-delivery-machine / blueprint / deploy / presentPromotionInformation.ts View on Github external
commandHandlerFrom(async (context: HandlerContext, params: PromotionParameters) => {
            const inv: VerifiedDeploymentInvocation = {
                id: new GitHubRepoRef(params.owner, params.repo, params.sha || await
                    tipOfDefaultBranch(params.githubToken, new GitHubRepoRef(params.owner, params.repo))),
                status: {targetUrl: undefined},
                credentials: {token: params.githubToken},
                messageDestination: addressSlackChannels(params.channel),
                context,
            };
            return presentPromotionInformation(inv);
        }, PromotionParameters, "PromotionInfo", "test: suggest promoting a ref to prod",
        "promotion info");
github atomist / sdm / src / software-delivery-machine / blueprint / deploy / presentPromotionInformation.ts View on Github external
commandHandlerFrom(async (context: HandlerContext, params: PromotionParameters) => {
            const inv: VerifiedDeploymentInvocation = {
                id: new GitHubRepoRef(params.owner, params.repo, params.sha || await
                    tipOfDefaultBranch(params.githubToken, new GitHubRepoRef(params.owner, params.repo))),
                status: {targetUrl: undefined},
                credentials: {token: params.githubToken},
                messageDestination: addressSlackChannels(params.channel),
                context,
            };
            return presentPromotionInformation(inv);
        }, PromotionParameters, "PromotionInfo", "test: suggest promoting a ref to prod",
        "promotion info");
github atomist / sdm / src / util / github / ghub.ts View on Github external
export async function listTopics(creds: string | ProjectOperationCredentials, rr: RemoteRepoRef): Promise {
    const headers = {
        headers: {
            ...authHeaders(toToken(creds)).headers,
            Accept: "application/vnd.github.mercy-preview+json",
        },
    };
    const grr = isGitHubRepoRef(rr) ? rr : new GitHubRepoRef(rr.owner, rr.repo, rr.sha);
    const url = `${grr.scheme}${grr.apiBase}/repos/${grr.owner}/${grr.repo}/topics`;
    const topics = await axios.get(url, headers);
    return topics.data.names;
}
github atomist / sdm / src / handlers / events / delivery / verify / OnEndpointStatus.ts View on Github external
public async handle(event: EventFired,
                        context: HandlerContext,
                        params: this): Promise {
        const status = event.data.Status[0];
        const commit = status.commit;
        const id = new GitHubRepoRef(commit.repo.owner, commit.repo.name, commit.sha);

        const statusAndFriends: GitHubStatusAndFriends = {
            context: status.context,
            description: status.description,
            state: status.state,
            targetUrl: status.targetUrl,
            siblings: status.commit.statuses,
        };

        const preconsStatus = await params.goal.preconditionsStatus({token: params.githubToken}, id, statusAndFriends);
        if (preconsStatus === "failure") {
            logger.info("Preconditions failed for goal %s on %j", params.goal.name, id);
            return failure(new Error("Precondition error"));
        }
        if (preconsStatus === "waiting") {
            logger.info("Preconditions not yet met for goal %s on %j", params.goal.name, id);
github atomist / sdm / src / handlers / events / delivery / deploy / k8s / RequestK8sDeployOnSuccessStatus1.ts View on Github external
public async handle(event: EventFired,
                        context: HandlerContext,
                        params: this): Promise {
        const status = event.data.Status[0];
        const commit = status.commit;
        const image = status.commit.image;
        const id = new GitHubRepoRef(commit.repo.owner, commit.repo.name, commit.sha);
        const statusAndFriends: GitHubStatusAndFriends = {
            context: status.context,
            state: status.state,
            targetUrl: status.targetUrl,
            description: status.description,
            siblings: status.commit.statuses,
        };
        const creds = { token: params.githubToken};

        if (! await params.deployGoal.preconditionsMet(creds, id, statusAndFriends)) {
            logger.info("Preconditions not met for goal %s on %j", params.deployGoal.name, id);
            return Promise.resolve(Success);
        }

        if (!currentGoalIsStillPending(params.deployGoal.context, statusAndFriends)) {
            return Promise.resolve(Success);
github atomist / sdm / src / common / delivery / deploy / executeArtifactDeploy.ts View on Github external
await dedup(commit.sha, async () => {
            const credentials = {token: params.githubToken};
            const id = new GitHubRepoRef(commit.repo.owner, commit.repo.name, commit.sha);
            const atomistTeam = context.teamId;
            const addressChannels = addressChannelsFor(commit.repo, context);

            await projectLoader.doWithProject({credentials, id, context, readOnly: true}, async project => {
                const push = commit.pushes[0];
                const pti: ProjectListenerInvocation = {
                    id,
                    project,
                    credentials,
                    context,
                    addressChannels,
                    push,
                };

                const target = await targetMapping.valueForPush(pti);
                if (!target) {