UNPKG

@salesforce/plugin-release-management

Version:
100 lines 4.02 kB
"use strict"; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ Object.defineProperty(exports, "__esModule", { value: true }); const os_1 = require("os"); const command_1 = require("@salesforce/command"); const core_1 = require("@salesforce/core"); const got_1 = require("got"); const chalk_1 = require("chalk"); const circleCiEnvvars_1 = require("../../../circleCiEnvvars"); const packAndSign_1 = require("../../../codeSigning/packAndSign"); core_1.Messages.importMessagesDirectory(__dirname); const messages = core_1.Messages.loadMessages('@salesforce/plugin-release-management', 'circleci'); const URL_BASE = 'https://circleci.com/api/v2/project'; class CircleCIEnvvarCreate extends circleCiEnvvars_1.CircleCiEnvvars { async run() { if (this.flags.dryrun) { this.ux.log((0, chalk_1.yellow)('Dryrun mode set. All validation will occur but the environment variables will NOT be updated.') + os_1.EOL); } const slugs = await this.resolveSlugs(); await this.resolveEnvvarValues(); const status = {}; for (const slug of slugs) { const batch = await this.createEnvvars(slug); status[slug] = batch; this.printStatus(slug, batch); } return status; } async isPipedIn() { return await super.isPipedIn(); } async readPipedInput() { return await super.readPipedInput(); } async createEnvvars(slug) { const envvarNames = this.getFlagAsArray('envvar'); try { const existingEnvvars = await this.getCircleCiEnvvars(slug); const foundEnvvars = envvarNames.filter((envvarName) => existingEnvvars.find((existingEnvvar) => existingEnvvar.name === envvarName)); if (foundEnvvars.length > 0) { const envvarList = envvarNames.join(', '); const foundList = foundEnvvars.join(', '); return `Envvars [${envvarList}] are already set. ALL specified envvars [${foundList}] cannot be set on the slug. Skipping...`; } const status = []; for (const name of envvarNames) { status.push(await this.createEnvvar(slug, name, this.envvarValues[name])); } return status; } catch (err) { const error = err; return `${error.message}. Skipping...`; } } async createEnvvar(slug, name, value) { const envvarUrl = `${URL_BASE}/${slug}/envvar`; // Only try to delete and create if we are doing an actual run if (!this.flags.dryrun) { try { const agent = packAndSign_1.api.getAgentForUri(envvarUrl); await got_1.default.post(`${envvarUrl}`, { headers: this.headers, json: { name, value }, agent, }); } catch (err) { const error = err; return { name, success: false, message: error.message }; } } return { name, success: true }; } } exports.default = CircleCIEnvvarCreate; CircleCIEnvvarCreate.description = messages.getMessage('envvar.update.description'); CircleCIEnvvarCreate.examples = messages.getMessage('envvar.update.examples').split(os_1.EOL); CircleCIEnvvarCreate.flagsConfig = { slug: command_1.flags.string({ description: messages.getMessage('envvar.flags.slug'), char: 's', multiple: true, }), envvar: command_1.flags.string({ description: messages.getMessage('envvar.flags.envvar'), char: 'e', required: true, multiple: true, }), dryrun: command_1.flags.boolean({ description: messages.getMessage('envvar.flags.dryrun'), }), }; //# sourceMappingURL=create.js.map