UNPKG

@codefresh-io/cf-git-providers

Version:

An NPM module/CLI for interacting with various git providers

88 lines 3.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handler = exports.builder = exports.desc = exports.command = void 0; const helpers_1 = require("../../../helpers"); // tslint:disable-next-line: no-var-requires const logger = (0, helpers_1.createNewLogger)('codefresh:create:status'); const AllowedStatuses = ['pending', 'running', 'success', 'failure', 'error']; exports.command = 'status'; exports.desc = 'Create a git commit status for a given SHA'; const builder = (yargs) => yargs .usage('Usage: $0 create webhook [options]') .option('owner', { alias: 'o', demandOption: (0, helpers_1.errormsg) `must provide "owner" option`, describe: 'The name of the owner of the git repository', type: 'string', }) .option('repo', { alias: 'r', demandOption: (0, helpers_1.errormsg) `must provide "repo" option`, describe: 'The name of the git repository', type: 'string', }) .option('sha', { alias: 's', demandOption: (0, helpers_1.errormsg) `must provide "sha" option`, describe: 'The SHA of the commit', type: 'string', }) .option('target-url', { alias: 'u', demandOption: (0, helpers_1.errormsg) `must provide "target-url" option`, describe: 'The target URL to associate with this status', type: 'string', }) .option('state', { demandOption: (0, helpers_1.errormsg) `must provide "state" option`, describe: 'The state of the status', choices: AllowedStatuses, }) .option('description', { alias: 'd', demandOption: (0, helpers_1.errormsg) `must provide "description" option`, describe: 'A short description of the status', type: 'string', }) .option('context', { alias: 'c', demandOption: (0, helpers_1.errormsg) `must provide "context" option`, describe: 'The label to differentiate this status from the status of other systems', type: 'string', }) .example(`$0 create ${exports.command} -o some-owner -r some-repo -s 8a8f822 -u https://example.com --state running -d "build is running"` + ` -c "Codefresh Build"`, 'Creates a new statue for repository "some-owner/some-repo" commit with sha: 8a8f822 ' + 'associated with the url https://example.com, in a running state, with the description: "build is running"'); exports.builder = builder; const handler = async (argv) => { const owner = argv.owner; const repo = argv.repo; const sha = argv.sha; const targetUrl = argv['target-url']; const state = argv.state; const description = argv.description; const context = argv.context; const provider = argv.provider; logger.debug(`owner=${owner}`); logger.debug(`repo=${repo}`); logger.debug(`sha=${sha}`); logger.debug(`targetUrl=${targetUrl}`); logger.debug(`state=${state}`); logger.debug(`description=${description}`); logger.debug(`context=${context}`); const [err] = await (0, helpers_1.to)(provider.createCommitStatus({ owner, repo, sha, targetUrl, state, description, context, })); if (err) { (0, helpers_1.exitWithError)(`failed to create commit status: ${err}`); } console.log(`created commit status for repo: ${owner}/${repo} sha: ${sha}`); }; exports.handler = handler; //# sourceMappingURL=status.cmd.js.map