How to use the @atomist/sdm.execPromise 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 / cli / lib / job / init.ts View on Github external
export async function init(opts: InitOptions): Promise {

    // 1. clone the repo
    try {
        print.info("Cloning repository...");
        await execPromise("git", ["clone", opts.cloneUrl, "."]);
        await execPromise("git", ["checkout", opts.sha]);
        print.info("Finished");
    } catch (e) {
        print.error(`Failed to checkout repository: ${e.message}`);
        return 5;
    }

    // 2. load input
    const inputs: string[] = JSON.parse(process.env.ATOMIST_INPUT || "[]");
    for (const input of inputs) {
        print.info(`Restoring '${input}'`);
        try {
            const files = glob.sync(input, { cwd: "/atm/share" });
            for (const file of files) {
                await fs.copy(path.join("/", "atm", "share", file), path.join(process.cwd(), file), {
                    overwrite: true,
github atomist / sdm-pack-aspect / lib / analysis / offline / spider / github / GitCommandGitProjectCloner.ts View on Github external
public async clone(sourceData: GitHubSearchResult): Promise {
        const project = await GitCommandGitProject.cloned(
            process.env.GITHUB_TOKEN ? { token: process.env.GITHUB_TOKEN } : undefined,
            GitHubRepoRef.from({
                owner: sourceData.owner.login,
                repo: sourceData.name,
                rawApiBase: "https://api.github.com", // for GitHub Enterprise, make this something like github.yourcompany.com/api/v3
            }), {
                alwaysDeep: false,
                noSingleBranch: true,
                depth: 1,
            },
            this.directoryManager);

        if (!project.id.sha) {
            const sha = await execPromise("git", ["rev-parse", "HEAD"], {
                cwd: (project as LocalProject).baseDir,
            });
            project.id.sha = sha.stdout.trim();
            logger.debug(`Set sha to ${project.id.sha}`);
        }
        return project;
    }
github atomist / sdm-pack-aspect / lib / job / fingerprintTask.ts View on Github external
await ci.configuration.sdm.projectLoader.doWithProject({ ...ci, id, credentials }, async p => {

                    if (isLazyProjectLoader(ci.configuration.sdm.projectLoader)) {
                        await p.materialize();
                    }

                    // git rev-parse HEAD = sha
                    const sha = (await execPromise("git", ["rev-parse", "HEAD"], { cwd: p.baseDir })).stdout.trim();
                    // const author = (await execPromise("git", ["show", "-s", "--format=%an"], { cwd: p.baseDir })).stdout.trim();
                    const email = (await execPromise("git", ["show", "-s", "--format=%ae"], { cwd: p.baseDir })).stdout.trim();
                    const ts = (await execPromise("git", ["show", "-s", "--format=%at"], { cwd: p.baseDir })).stdout.trim();
                    const message = (await execPromise("git", ["show", "-s", "--format=%B"], { cwd: p.baseDir })).stdout.trim();

                    // Ingest initial commit
                    const commit: ScmCommitInput = {
                        repoId: ci.parameters.repoId,
                        branchName: ci.parameters.branch,
                        timestamp: new Date(+ts * 1000).toISOString(),
                        email: {
                            address: email,
                        },
                        sha,
                        message,
                    };

                    await ci.context.graphClient.mutate({
github atomist / sdm-pack-aspect / lib / analysis / offline / spider / SpiderAnalyzer.ts View on Github external
async function fetchChangedFiles(project: GitProject): Promise {
    try {
        const output = await execPromise("git", ["show", `--pretty=format:""`, "--name-only"],
            { cwd: project.baseDir });
        return output.stdout.trim().split("\n");
    } catch (err) {
        logger.error("Failure getting changed files: %s", err.message);
        return [];
    }
}
github atomist / sdm-pack-aspect / lib / feature / node / TypeScriptVersionFeature.ts View on Github external
apply: async (p, fp) => {
        if (fp.data.length !== 1) {
            return false;
        }
        if (!(await p.hasFile(PackageJsonName))) {
            return false;
        }
        if (!(p as LocalProject).baseDir) {
            return false;
        }

        await execPromise(
            "npm",
            ["install", `typescript@${fp.data[0]}`, "--save-dev", "--safe-exact"],
            { cwd: (p as LocalProject).baseDir });

        return true;
    },
    toDisplayableFingerprintName: () => "TypeScript version",
github atomist / sdm-pack-aspect / lib / aspect / node / idealFromNpm.ts View on Github external
export async function idealFromNpm(name: string): Promise {
    const libraryName = deconstructNpmDepsFingerprintName(name);
    try {
        const result = await execPromise("npm", ["view", libraryName, "dist-tags.latest"]);
        logger.info(`World Ideal Version is ${result.stdout} for ${libraryName}`);
        return {
            ideal: createNpmDepFingerprint(libraryName, result.stdout.trim()),
            reason: "latest from NPM",
        };
    } catch (err) {
        logger.error("Could not find version of " + libraryName + ": " + err.message);
    }
    return undefined;
}
github atomist / sdm-pack-spring / lib / maven / inspection / findDependencies.ts View on Github external
async function extractDependencies(p: LocalProject): Promise {
    try {
        await execPromise(`mvn`, [`dependency:list`, `-DoutputFile=${dependenciesFile}`], {cwd: p.baseDir});
        return p.findFile(dependenciesFile);
    } catch (err) {
        throw err;
    }
}
github atomist / cli / lib / install.ts View on Github external
name: "package",
                message: "Extension Packs",
                choices: packs
                    .map(p => ({
                        name: `${p.name} ${chalk.yellow(p.description)} ${chalk.reset("by")} ${
                            chalk.gray(p.maintainers.map(m => m.username).join(", "))}`,
                        value: p,
                        short: p.name,
                    })),

            },
        ];
        const answers: any = await inquirer.prompt(questions);
        spinner = createSpinner(`Installing extension pack ${chalk.cyan(answers.package.name)} in ${opts.cwd}`);
        try {
            await execPromise("npm", ["install", answers.package.name], { cwd: opts.cwd });
            spinner.stop(true);
            print.log(`Successfully installed extension pack ${chalk.cyan(answers.package.name)} by ${
                chalk.gray(answers.package.maintainers.map((m: any) => m.username).join(", "))}`);
            const p = path.join(opts.cwd, "node_modules", answers.package.name, "package.json");
            const pj = JSON.parse((await fs.readFile(p)).toString());
            print.log(`Visit ${chalk.yellow(pj.homepage)} for install and usage instructions`);
        } catch (e) {
            spinner.stop(true);
            print.error(`Failed to install extension pack '${answers.package.name}': ${e.message}`);
            return 1;
        }

    } else {
        print.log(`No SDM extension packs found for: ${opts.keywords.join(", ")}`);
        return 1;
    }