jira-pilot 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,60 +1,63 @@
1
- import { Command } from 'commander';
2
- import chalk from 'chalk';
3
- import { execSync } from 'child_process';
4
- import { api } from '../services/api-service.js';
5
- import ora from 'ora';
6
- import enquirer from 'enquirer';
7
-
8
- export function registerGitCommand(program) {
9
- const gitCmd = new Command('git')
10
- .description('Git integration for Jira');
11
-
12
- gitCmd
13
- .command('branch')
14
- .description('Create a git branch from a Jira issue')
15
- .argument('<issueKey>', 'Jira Issue Key (e.g., PROJ-123)')
16
- .option('-t, --type <type>', 'Branch type (feature, bugfix, hotfix)', 'feature')
17
- .action(async (issueKey, options) => {
18
- const spinner = ora(`Fetching issue ${issueKey}...`).start();
19
- try {
20
- const issue = await api.get(`/issue/${issueKey}`);
21
- spinner.stop();
22
-
23
- const summary = issue.fields.summary;
24
- const sanitizedSummary = summary
25
- .toLowerCase()
26
- .replace(/[^a-z0-9]+/g, '-') // Replace non-alphanumeric with hyphen
27
- .replace(/^-+|-+$/g, ''); // Trim leading/trailing hyphens
28
-
29
- const branchName = `${options.type}/${issueKey}-${sanitizedSummary}`;
30
-
31
- console.log(chalk.blue(`Proposed Branch Name: ${chalk.bold(branchName)}`));
32
-
33
- const { confirm } = await enquirer.prompt({
34
- type: 'confirm',
35
- name: 'confirm',
36
- message: 'Create and switch to this branch?',
37
- initial: true
38
- });
39
-
40
- if (confirm) {
41
- try {
42
- execSync(`git checkout -b ${branchName}`, { stdio: 'inherit' });
43
- console.log(chalk.green('\nBranch created and checked out!'));
44
- } catch (gitError) {
45
- console.error(chalk.red('\nFailed to create branch. Are you in a git repository?'));
46
- }
47
- }
48
-
49
- } catch (e) {
50
- spinner.fail('Failed to fetch issue');
51
- if (e.response) {
52
- console.error(chalk.red(`Error ${e.response.status}: `), e.response.data);
53
- } else {
54
- console.error(chalk.red(e.message));
55
- }
56
- }
57
- });
58
-
59
- program.addCommand(gitCmd);
60
- }
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { execSync } from 'child_process';
4
+ import { api } from '../services/api-service.js';
5
+ import ora from 'ora';
6
+ import enquirer from 'enquirer';
7
+ import { validateIssueKey } from '../utils/validators.js';
8
+
9
+ export function registerGitCommand(program) {
10
+ const gitCmd = new Command('git')
11
+ .description('Git integration for Jira');
12
+
13
+ gitCmd
14
+ .command('branch')
15
+ .description('Create a git branch from a Jira issue')
16
+ .argument('<issueKey>', 'Jira Issue Key (e.g., PROJ-123)')
17
+ .option('-t, --type <type>', 'Branch type (feature, bugfix, hotfix)', 'feature')
18
+ .action(async (issueKey, options) => {
19
+ const check = validateIssueKey(issueKey);
20
+ if (!check.valid) { console.error(chalk.red(check.message)); return; }
21
+ const spinner = ora(`Fetching issue ${issueKey}...`).start();
22
+ try {
23
+ const issue = await api.get(`/issue/${issueKey}`);
24
+ spinner.stop();
25
+
26
+ const summary = issue.fields.summary;
27
+ const sanitizedSummary = summary
28
+ .toLowerCase()
29
+ .replace(/[^a-z0-9]+/g, '-') // Replace non-alphanumeric with hyphen
30
+ .replace(/^-+|-+$/g, ''); // Trim leading/trailing hyphens
31
+
32
+ const branchName = `${options.type}/${issueKey}-${sanitizedSummary}`;
33
+
34
+ console.log(chalk.blue(`Proposed Branch Name: ${chalk.bold(branchName)}`));
35
+
36
+ const { confirm } = await enquirer.prompt({
37
+ type: 'confirm',
38
+ name: 'confirm',
39
+ message: 'Create and switch to this branch?',
40
+ initial: true
41
+ });
42
+
43
+ if (confirm) {
44
+ try {
45
+ execSync(`git checkout -b ${branchName}`, { stdio: 'inherit' });
46
+ console.log(chalk.green('\nBranch created and checked out!'));
47
+ } catch (gitError) {
48
+ console.error(chalk.red('\nFailed to create branch. Are you in a git repository?'));
49
+ }
50
+ }
51
+
52
+ } catch (e) {
53
+ spinner.fail('Failed to fetch issue');
54
+ if (e.response) {
55
+ console.error(chalk.red(`Error ${e.response.status}: `), e.response.data);
56
+ } else {
57
+ console.error(chalk.red(e.message));
58
+ }
59
+ }
60
+ });
61
+
62
+ program.addCommand(gitCmd);
63
+ }