Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 2 additions & 49 deletions bin/commands/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,7 @@ const path = require('path');
function createIssueCommand(factory) {
const command = new Command('issue')
.description('Manage JIRA issues')
.alias('i')
.option('-l, --list', 'list issues')
.option('-c, --create', 'create a new issue')
.option('-g, --get <key>', 'get issue by key')
.option('-u, --update <key>', 'update issue by key')
.option('-d, --delete <key>', 'delete issue by key')
.option('--project <project>', 'filter by project')
.option('--assignee <assignee>', 'filter by assignee')
.option('--status <status>', 'filter by status')
.option('--type <type>', 'filter by issue type')
.option('--summary <summary>', 'issue summary (for create/update)')
.option('--description <description>', 'issue description (for create/update)')
.option('--priority <priority>', 'priority (for create/update)')
.option('--limit <limit>', 'limit number of results', '20')
.action(async (options) => {
const io = factory.getIOStreams();
const client = await factory.getJiraClient();
const analytics = factory.getAnalytics();

try {
await analytics.track('issue', { action: getIssueAction(options) });

if (options.create) {
await createIssue(client, io, factory, options);
} else if (options.get) {
await getIssue(client, io, options.get);
} else if (options.update) {
await updateIssue(client, io, options.update, options);
} else if (options.delete) {
await deleteIssue(client, io, options.delete, options);
} else {
// Default to list issues
await listIssues(client, io, options);
}

} catch (err) {
io.error(`Issue command failed: ${err.message}`);
process.exit(1);
}
});
.alias('i');

// Add subcommands
command
Expand All @@ -75,7 +36,7 @@ function createIssueCommand(factory) {
.action(async (options) => {
const io = factory.getIOStreams();
const client = await factory.getJiraClient();

try {
await listIssues(client, io, options);
} catch (err) {
Expand Down Expand Up @@ -399,12 +360,4 @@ async function deleteIssue(client, io, issueKey, options = {}) {
io.success(`Issue ${issueKey} deleted successfully`);
}

function getIssueAction(options) {
if (options.create) return 'create';
if (options.get) return 'get';
if (options.update) return 'update';
if (options.delete) return 'delete';
return 'list';
}

module.exports = createIssueCommand;
51 changes: 27 additions & 24 deletions tests/commands/issue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,43 @@ describe('IssueCommand', () => {
expect(issueCommand.aliases()).toContain('i');
});

it('should have options', () => {
const options = issueCommand.options;
expect(options.length).toBeGreaterThan(0);
});
});
it('should have subcommands', () => {
const commands = issueCommand.commands;
expect(commands.length).toBeGreaterThan(0);

describe('command options', () => {
it('should have list option', () => {
const listOption = issueCommand.options.find(opt => opt.long === '--list');
expect(listOption).toBeDefined();
expect(listOption.short).toBe('-l');
});
const listCommand = commands.find(cmd => cmd.name() === 'list');
expect(listCommand).toBeDefined();

it('should have create option', () => {
const createOption = issueCommand.options.find(opt => opt.long === '--create');
expect(createOption).toBeDefined();
expect(createOption.short).toBe('-c');
const createCommand = commands.find(cmd => cmd.name() === 'create');
expect(createCommand).toBeDefined();

const viewCommand = commands.find(cmd => cmd.name() === 'view');
expect(viewCommand).toBeDefined();
});
});

it('should have get option', () => {
const getOption = issueCommand.options.find(opt => opt.long === '--get');
expect(getOption).toBeDefined();
expect(getOption.short).toBe('-g');
describe('list subcommand options', () => {
let listCommand;

beforeEach(() => {
listCommand = issueCommand.commands.find(cmd => cmd.name() === 'list');
});

it('should have filter options', () => {
const projectOption = issueCommand.options.find(opt => opt.long === '--project');
const projectOption = listCommand.options.find(opt => opt.long === '--project');
expect(projectOption).toBeDefined();
const assigneeOption = issueCommand.options.find(opt => opt.long === '--assignee');

const assigneeOption = listCommand.options.find(opt => opt.long === '--assignee');
expect(assigneeOption).toBeDefined();
const statusOption = issueCommand.options.find(opt => opt.long === '--status');

const statusOption = listCommand.options.find(opt => opt.long === '--status');
expect(statusOption).toBeDefined();
});

it('should have limit option with default value', () => {
const limitOption = listCommand.options.find(opt => opt.long === '--limit');
expect(limitOption).toBeDefined();
expect(limitOption.defaultValue).toBe('20');
});
});
});