UNPKG

cli-stash

Version:

CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.

66 lines (65 loc) 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const stash_connector_1 = require("stash-connector"); const baseCommand_1 = require("../../../libs/core/baseCommand"); const stashResponse_1 = require("../../../libs/core/stashResponse"); const tables_1 = require("../../../libs/core/tables"); const ux_1 = require("../../../libs/core/ux"); class Fork extends baseCommand_1.BaseCommand { async run() { const response = new stashResponse_1.StashCLIResponse(); const connector = new stash_connector_1.StashConnector(this.localConfig.getConnectorOptions(this.flags.alias)); try { const result = await connector.projects.repos(this.flags.project).fork(this.flags.slug, { name: this.flags['target-name'], project: this.flags['target-project'] ? { key: this.flags['target-project'] } : undefined, }); response.result = result; response.status = 0; response.message = 'The Repository forked successfully'; this.ux.log(response.message); this.ux.table([result], tables_1.RepositoryColumns, { csv: this.flags.csv, extended: this.flags.extended || this.flags.csv }); } catch (error) { this.processError(response, error); } return response; } } exports.default = Fork; Fork.description = 'Create a new repository forked from an existing repository. ' + ux_1.UX.processDocumentation('<doc:Repository>'); Fork.examples = [ `$ stash projects:repos:fork -a MyStashAlias --project "OriginProject" --slug "OriginRepoSlug" --csv`, `$ stash projects:repos:fork -a MyStashAlias --project "OriginProject" --slug "OriginRepoSlug" --target-slug "TargetSlug" --json`, `$ stash projects:repos:fork -a MyStashAlias --project "OriginProject" --slug "OriginRepoSlug" --target-slug "TargetSlug" --target-project "TargetProject" --json`, ]; Fork.flags = { ...baseCommand_1.BaseCommand.flags, csv: baseCommand_1.BuildFlags.csv, extended: baseCommand_1.BuildFlags.extended, alias: baseCommand_1.BuildFlags.alias, project: core_1.Flags.string({ description: 'The Origin Project Key (or user slug like ~userSlug) to fork the repository', required: true, name: 'Project' }), slug: core_1.Flags.string({ description: 'The Origin repository slug.', required: true, name: 'Slug' }), 'target-name': core_1.Flags.string({ description: 'The Forked repository name. Defaults to the name of the origin repository if not specified', required: false, name: 'Target Slug' }), 'target-project': core_1.Flags.string({ description: 'The Target Project Key (or user slug like ~userSlug) to fork the repository. Defaults to the current user\'s personal project if not specified', required: false, name: 'Target Project' }), };