bbk-cli 1.0.0
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.
- package/.claude/bitbucket-config.local.md.example +58 -0
- package/.eslintcache +1 -0
- package/.github/dependabot.yml +15 -0
- package/.github/workflows/convetional-commit.yml +24 -0
- package/.github/workflows/publish-on-tag.yml +47 -0
- package/.github/workflows/release-please.yml +21 -0
- package/.github/workflows/run-tests.yml +75 -0
- package/.nvmrc +1 -0
- package/.prettierignore +2 -0
- package/.prettierrc.cjs +17 -0
- package/.release-please-manifest.json +3 -0
- package/CHANGELOG.md +21 -0
- package/LICENSE +202 -0
- package/README.md +381 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/wrapper.d.ts +38 -0
- package/dist/cli/wrapper.d.ts.map +1 -0
- package/dist/cli/wrapper.js +326 -0
- package/dist/cli/wrapper.js.map +1 -0
- package/dist/commands/helpers.d.ts +11 -0
- package/dist/commands/helpers.d.ts.map +1 -0
- package/dist/commands/helpers.js +40 -0
- package/dist/commands/helpers.js.map +1 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +3 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/runner.d.ts +7 -0
- package/dist/commands/runner.d.ts.map +1 -0
- package/dist/commands/runner.js +126 -0
- package/dist/commands/runner.js.map +1 -0
- package/dist/config/constants.d.ts +16 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +171 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/arg-parser.d.ts +7 -0
- package/dist/utils/arg-parser.d.ts.map +1 -0
- package/dist/utils/arg-parser.js +67 -0
- package/dist/utils/arg-parser.js.map +1 -0
- package/dist/utils/bitbucket-client.d.ts +122 -0
- package/dist/utils/bitbucket-client.d.ts.map +1 -0
- package/dist/utils/bitbucket-client.js +182 -0
- package/dist/utils/bitbucket-client.js.map +1 -0
- package/dist/utils/bitbucket-utils.d.ts +110 -0
- package/dist/utils/bitbucket-utils.d.ts.map +1 -0
- package/dist/utils/bitbucket-utils.js +491 -0
- package/dist/utils/bitbucket-utils.js.map +1 -0
- package/dist/utils/config-loader.d.ts +41 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/utils/config-loader.js +76 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/eslint.config.ts +15 -0
- package/package.json +62 -0
- package/release-please-config.json +33 -0
- package/tests/integration/cli-integration.test.ts +528 -0
- package/tests/unit/cli/wrapper.test.ts +727 -0
- package/tests/unit/commands/helpers.test.ts +268 -0
- package/tests/unit/commands/runner.test.ts +758 -0
- package/tests/unit/utils/arg-parser.test.ts +350 -0
- package/tests/unit/utils/config-loader.test.ts +158 -0
- package/vitest.config.ts +22 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { getCurrentVersion, printAvailableCommands, printCommandDetail } from '../../../src/commands/helpers.js';
|
|
4
|
+
|
|
5
|
+
// Mock the config module
|
|
6
|
+
vi.mock('../../../src/config/index.js', () => ({
|
|
7
|
+
COMMANDS: [
|
|
8
|
+
'list-repos',
|
|
9
|
+
'get-repo',
|
|
10
|
+
'list-prs',
|
|
11
|
+
'get-pr',
|
|
12
|
+
'create-pr',
|
|
13
|
+
'update-pr',
|
|
14
|
+
'add-comment',
|
|
15
|
+
'delete-pr',
|
|
16
|
+
'get-user',
|
|
17
|
+
'test-connection',
|
|
18
|
+
],
|
|
19
|
+
COMMANDS_INFO: [
|
|
20
|
+
'List all accessible repositories',
|
|
21
|
+
'Get details of a specific repository',
|
|
22
|
+
'List pull requests in a repository',
|
|
23
|
+
'Get details of a specific pull request',
|
|
24
|
+
'Create a new pull request',
|
|
25
|
+
'Update an existing pull request',
|
|
26
|
+
'Add a comment to a pull request',
|
|
27
|
+
'Delete a pull request',
|
|
28
|
+
'Get user information',
|
|
29
|
+
'Test Bitbucket API connection',
|
|
30
|
+
],
|
|
31
|
+
COMMANDS_DETAIL: [
|
|
32
|
+
'\nParameters:\n- workspace (optional): string\n- format (optional): string\n\nExample:\nlist-repos',
|
|
33
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n\nExample:\nget-repo',
|
|
34
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n- state (optional): string\n- limit (optional): number\n\nExample:\nlist-prs',
|
|
35
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n- prId (required): string\n\nExample:\nget-pr',
|
|
36
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n- title (required): string\n- sourceBranch (required): string\n- destinationBranch (required): string\n\nExample:\ncreate-pr',
|
|
37
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n- prId (required): string\n- title (optional): string\n- description (optional): string\n\nExample:\nupdate-pr',
|
|
38
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n- prId (required): string\n- content (required): string\n\nExample:\nadd-comment',
|
|
39
|
+
'\nParameters:\n- workspace (required): string\n- repo (required): string\n- prId (required): string\n\nExample:\ndelete-pr',
|
|
40
|
+
'\nParameters:\n- accountId (optional): string\n- username (optional): string\n\nExample:\nget-user',
|
|
41
|
+
'\nParameters:\n- profile (optional): string\n\nExample:\ntest-connection',
|
|
42
|
+
],
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
describe('commands/helpers', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
vi.clearAllMocks();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('printAvailableCommands', () => {
|
|
51
|
+
it('should print all available commands with their descriptions', () => {
|
|
52
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
53
|
+
|
|
54
|
+
printAvailableCommands();
|
|
55
|
+
|
|
56
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
57
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('1. list-repos: List all accessible repositories');
|
|
58
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('2. get-repo: Get details of a specific repository');
|
|
59
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('3. list-prs: List pull requests in a repository');
|
|
60
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('4. get-pr: Get details of a specific pull request');
|
|
61
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('5. create-pr: Create a new pull request');
|
|
62
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('6. update-pr: Update an existing pull request');
|
|
63
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('7. add-comment: Add a comment to a pull request');
|
|
64
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('8. delete-pr: Delete a pull request');
|
|
65
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('9. get-user: Get user information');
|
|
66
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('10. test-connection: Test Bitbucket API connection');
|
|
67
|
+
|
|
68
|
+
consoleLogSpy.mockRestore();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should print commands with correct numbering starting from 1', () => {
|
|
72
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
73
|
+
|
|
74
|
+
printAvailableCommands();
|
|
75
|
+
|
|
76
|
+
const calls = consoleLogSpy.mock.calls;
|
|
77
|
+
// Find the calls that contain command numbers
|
|
78
|
+
const numberCalls = calls.filter(call => call[0] && call[0].match(/^\d+\./));
|
|
79
|
+
expect(numberCalls).toHaveLength(10);
|
|
80
|
+
expect(numberCalls[0][0]).toBe('1. list-repos: List all accessible repositories');
|
|
81
|
+
expect(numberCalls[9][0]).toBe('10. test-connection: Test Bitbucket API connection');
|
|
82
|
+
|
|
83
|
+
consoleLogSpy.mockRestore();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('printCommandDetail', () => {
|
|
88
|
+
it('should print detailed information for a valid command', () => {
|
|
89
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
90
|
+
|
|
91
|
+
printCommandDetail('list-repos');
|
|
92
|
+
|
|
93
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('list-repos'));
|
|
94
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('List all accessible repositories'));
|
|
95
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Parameters:'));
|
|
96
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('workspace (optional)'));
|
|
97
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Example:'));
|
|
98
|
+
|
|
99
|
+
consoleLogSpy.mockRestore();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should print details for get-repo command', () => {
|
|
103
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
104
|
+
|
|
105
|
+
printCommandDetail('get-repo');
|
|
106
|
+
|
|
107
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('get-repo'));
|
|
108
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Get details of a specific repository'));
|
|
109
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('workspace (required)'));
|
|
110
|
+
|
|
111
|
+
consoleLogSpy.mockRestore();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should print details for create-pr command', () => {
|
|
115
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
116
|
+
|
|
117
|
+
printCommandDetail('create-pr');
|
|
118
|
+
|
|
119
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('create-pr'));
|
|
120
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Create a new pull request'));
|
|
121
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('workspace (required)'));
|
|
122
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('title (required)'));
|
|
123
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('sourceBranch (required)'));
|
|
124
|
+
|
|
125
|
+
consoleLogSpy.mockRestore();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should print details for update-pr command', () => {
|
|
129
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
130
|
+
|
|
131
|
+
printCommandDetail('update-pr');
|
|
132
|
+
|
|
133
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('update-pr'));
|
|
134
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Update an existing pull request'));
|
|
135
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('workspace (required)'));
|
|
136
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('prId (required)'));
|
|
137
|
+
|
|
138
|
+
consoleLogSpy.mockRestore();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should print details for all 10 commands', () => {
|
|
142
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
143
|
+
|
|
144
|
+
const commands = [
|
|
145
|
+
'list-repos',
|
|
146
|
+
'get-repo',
|
|
147
|
+
'list-prs',
|
|
148
|
+
'get-pr',
|
|
149
|
+
'create-pr',
|
|
150
|
+
'update-pr',
|
|
151
|
+
'add-comment',
|
|
152
|
+
'delete-pr',
|
|
153
|
+
'get-user',
|
|
154
|
+
'test-connection',
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
commands.forEach(command => {
|
|
158
|
+
consoleLogSpy.mockClear();
|
|
159
|
+
printCommandDetail(command);
|
|
160
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining(command));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
consoleLogSpy.mockRestore();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should handle empty command string', () => {
|
|
167
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
168
|
+
|
|
169
|
+
printCommandDetail('');
|
|
170
|
+
|
|
171
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Please provide a command name.');
|
|
172
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
173
|
+
|
|
174
|
+
consoleLogSpy.mockRestore();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should handle null command', () => {
|
|
178
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
179
|
+
|
|
180
|
+
// @ts-expect-error - Testing null input
|
|
181
|
+
printCommandDetail(null);
|
|
182
|
+
|
|
183
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Please provide a command name.');
|
|
184
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
185
|
+
|
|
186
|
+
consoleLogSpy.mockRestore();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('should handle undefined command', () => {
|
|
190
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
191
|
+
|
|
192
|
+
// @ts-expect-error - Testing undefined input
|
|
193
|
+
printCommandDetail(undefined);
|
|
194
|
+
|
|
195
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Please provide a command name.');
|
|
196
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
197
|
+
|
|
198
|
+
consoleLogSpy.mockRestore();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('should handle whitespace-only command', () => {
|
|
202
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
203
|
+
|
|
204
|
+
printCommandDetail(' ');
|
|
205
|
+
|
|
206
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Please provide a command name.');
|
|
207
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
208
|
+
|
|
209
|
+
consoleLogSpy.mockRestore();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should show error for unknown command', () => {
|
|
213
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
214
|
+
|
|
215
|
+
printCommandDetail('invalid-command');
|
|
216
|
+
|
|
217
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Unknown command: invalid-command');
|
|
218
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
219
|
+
|
|
220
|
+
consoleLogSpy.mockRestore();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should show error for unknown command and then list available commands', () => {
|
|
224
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
225
|
+
|
|
226
|
+
printCommandDetail('nonexistent');
|
|
227
|
+
|
|
228
|
+
expect(consoleLogSpy.mock.calls[0][0]).toContain('Unknown command:');
|
|
229
|
+
expect(consoleLogSpy.mock.calls[1][0]).toContain('Available commands:');
|
|
230
|
+
|
|
231
|
+
consoleLogSpy.mockRestore();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should trim whitespace from command name', () => {
|
|
235
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
236
|
+
|
|
237
|
+
printCommandDetail(' list-repos ');
|
|
238
|
+
|
|
239
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('list-repos'));
|
|
240
|
+
expect(consoleLogSpy).not.toHaveBeenCalledWith(expect.stringContaining('Unknown command'));
|
|
241
|
+
|
|
242
|
+
consoleLogSpy.mockRestore();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should handle commands with mixed case', () => {
|
|
246
|
+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
247
|
+
|
|
248
|
+
printCommandDetail('LIST-REPOS');
|
|
249
|
+
|
|
250
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('Unknown command: LIST-REPOS');
|
|
251
|
+
expect(consoleLogSpy).toHaveBeenCalledWith('\nAvailable commands:');
|
|
252
|
+
|
|
253
|
+
consoleLogSpy.mockRestore();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe('getCurrentVersion', () => {
|
|
258
|
+
it('should return version as string', () => {
|
|
259
|
+
const version = getCurrentVersion();
|
|
260
|
+
expect(typeof version).toBe('string');
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should return version in semver format', () => {
|
|
264
|
+
const version = getCurrentVersion();
|
|
265
|
+
expect(version).toMatch(/^\d+\.\d+\.\d+$/);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|