cli-stash
Version:
CLI application to manage and work with Atlassian Stash. Work with your Stash project and repositories from Command lines.
113 lines (112 loc) • 5.83 kB
JavaScript
"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 Create 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 {
let inputData;
if (this.hasInputData()) {
inputData = this.getJSONInputData();
}
else {
inputData = {
text: this.flags.text,
};
if (this.flags.parent) {
inputData.parent = this.flags.parent;
}
if (this.flags.path) {
inputData.anchor = {
path: this.flags.path,
srcPath: this.flags.path,
};
if (this.flags.line >= 0) {
inputData.anchor.lineType = "CONTEXT";
inputData.anchor.fileType = "FROM";
inputData.anchor.line = this.flags.line;
}
}
}
const comment = await connector.projects.repos(this.flags.project).pullRequests(this.flags.slug).comments(this.flags.pull).create(inputData);
response.result = comment;
response.status = 0;
response.message = this.getRecordCreatedText('Comment');
this.ux.log(response.message);
this.ux.table([comment], tables_1.CommentColumns, {
csv: this.flags.csv,
extended: this.flags.extended || this.flags.csv
});
}
catch (error) {
this.processError(response, error);
}
return response;
}
}
exports.default = Create;
Create.description = 'Add a new comment. ' + ux_1.UX.processDocumentation('<doc:Comment>');
Create.examples = [
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --data "{'text':'The comment text.'}" --csv`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --data "{'text':'A Comment Reply.','parent':{'id':1}}" --json`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --data "{'text':'A General file comment','anchor':{'path':'path/to/file','srcPath':'path/to/file'}}" --json`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --data "{'text':'A comment on file line.','anchor':{'line': 1, 'lineType': 'CONTEXT', 'fileType': 'FROM', 'path':'path/to/file','srcPath':'path/to/file'}}" --json`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --file "path/to/json/data/file" --csv`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --text "The comment text" --json`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --text "A comment Reply" --parent 1`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --text "A General file comment" --path "path/to/file"`,
`$ stash projects:repos:pulls:comments:create -a MyStashAlias --project "ProjectKey" --slug "MyRepoSlug" --pull 1234 --text "A comment on file line" --path "path/to/file" --line 1`,
];
Create.flags = {
...baseCommand_1.BaseCommand.flags,
csv: baseCommand_1.BuildFlags.csv,
extended: baseCommand_1.BuildFlags.extended,
alias: baseCommand_1.BuildFlags.alias,
data: baseCommand_1.BuildFlags.input.jsonData('<doc:CommentInput>', false, ['text']),
file: baseCommand_1.BuildFlags.input.jsonFile('<doc:CommentInput>', false, ['text']),
project: core_1.Flags.string({
description: 'The Project Key (or user slug like ~userSlug) to create the pull request comment',
required: true,
name: 'Project'
}),
slug: core_1.Flags.string({
description: 'The Repository slug to create the pull request comment',
required: true,
name: 'Slug',
}),
pull: core_1.Flags.integer({
description: 'The Pull Request Id to create the pull request comment',
required: true,
name: 'Pull Request Id',
}),
text: core_1.Flags.string({
description: 'The Comment text to add',
required: false,
name: 'Text',
exclusive: ['data', 'file']
}),
parent: core_1.Flags.string({
description: 'The parent comment if the comment is a response',
required: false,
name: 'Parent Comment',
dependsOn: ['text'],
}),
path: core_1.Flags.string({
description: 'The file path if the comment is a general file comment',
required: false,
name: 'File Path',
dependsOn: ['text'],
}),
line: core_1.Flags.integer({
description: 'The file line if the comment is a file line comment',
required: false,
name: 'Line',
dependsOn: ['text', 'path'],
}),
};