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.
Files changed (76) hide show
  1. package/.claude/bitbucket-config.local.md.example +58 -0
  2. package/.eslintcache +1 -0
  3. package/.github/dependabot.yml +15 -0
  4. package/.github/workflows/convetional-commit.yml +24 -0
  5. package/.github/workflows/publish-on-tag.yml +47 -0
  6. package/.github/workflows/release-please.yml +21 -0
  7. package/.github/workflows/run-tests.yml +75 -0
  8. package/.nvmrc +1 -0
  9. package/.prettierignore +2 -0
  10. package/.prettierrc.cjs +17 -0
  11. package/.release-please-manifest.json +3 -0
  12. package/CHANGELOG.md +21 -0
  13. package/LICENSE +202 -0
  14. package/README.md +381 -0
  15. package/dist/cli/index.d.ts +2 -0
  16. package/dist/cli/index.d.ts.map +1 -0
  17. package/dist/cli/index.js +2 -0
  18. package/dist/cli/index.js.map +1 -0
  19. package/dist/cli/wrapper.d.ts +38 -0
  20. package/dist/cli/wrapper.d.ts.map +1 -0
  21. package/dist/cli/wrapper.js +326 -0
  22. package/dist/cli/wrapper.js.map +1 -0
  23. package/dist/commands/helpers.d.ts +11 -0
  24. package/dist/commands/helpers.d.ts.map +1 -0
  25. package/dist/commands/helpers.js +40 -0
  26. package/dist/commands/helpers.js.map +1 -0
  27. package/dist/commands/index.d.ts +3 -0
  28. package/dist/commands/index.d.ts.map +1 -0
  29. package/dist/commands/index.js +3 -0
  30. package/dist/commands/index.js.map +1 -0
  31. package/dist/commands/runner.d.ts +7 -0
  32. package/dist/commands/runner.d.ts.map +1 -0
  33. package/dist/commands/runner.js +126 -0
  34. package/dist/commands/runner.js.map +1 -0
  35. package/dist/config/constants.d.ts +16 -0
  36. package/dist/config/constants.d.ts.map +1 -0
  37. package/dist/config/constants.js +171 -0
  38. package/dist/config/constants.js.map +1 -0
  39. package/dist/config/index.d.ts +2 -0
  40. package/dist/config/index.d.ts.map +1 -0
  41. package/dist/config/index.js +2 -0
  42. package/dist/config/index.js.map +1 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +24 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/utils/arg-parser.d.ts +7 -0
  48. package/dist/utils/arg-parser.d.ts.map +1 -0
  49. package/dist/utils/arg-parser.js +67 -0
  50. package/dist/utils/arg-parser.js.map +1 -0
  51. package/dist/utils/bitbucket-client.d.ts +122 -0
  52. package/dist/utils/bitbucket-client.d.ts.map +1 -0
  53. package/dist/utils/bitbucket-client.js +182 -0
  54. package/dist/utils/bitbucket-client.js.map +1 -0
  55. package/dist/utils/bitbucket-utils.d.ts +110 -0
  56. package/dist/utils/bitbucket-utils.d.ts.map +1 -0
  57. package/dist/utils/bitbucket-utils.js +491 -0
  58. package/dist/utils/bitbucket-utils.js.map +1 -0
  59. package/dist/utils/config-loader.d.ts +41 -0
  60. package/dist/utils/config-loader.d.ts.map +1 -0
  61. package/dist/utils/config-loader.js +76 -0
  62. package/dist/utils/config-loader.js.map +1 -0
  63. package/dist/utils/index.d.ts +5 -0
  64. package/dist/utils/index.d.ts.map +1 -0
  65. package/dist/utils/index.js +4 -0
  66. package/dist/utils/index.js.map +1 -0
  67. package/eslint.config.ts +15 -0
  68. package/package.json +62 -0
  69. package/release-please-config.json +33 -0
  70. package/tests/integration/cli-integration.test.ts +528 -0
  71. package/tests/unit/cli/wrapper.test.ts +727 -0
  72. package/tests/unit/commands/helpers.test.ts +268 -0
  73. package/tests/unit/commands/runner.test.ts +758 -0
  74. package/tests/unit/utils/arg-parser.test.ts +350 -0
  75. package/tests/unit/utils/config-loader.test.ts +158 -0
  76. package/vitest.config.ts +22 -0
package/README.md ADDED
@@ -0,0 +1,381 @@
1
+ # Bitbucket CLI
2
+
3
+ [![npm bbk-cli package](https://img.shields.io/npm/v/bbk-cli.svg)](https://npmjs.org/package/bbk-cli)
4
+
5
+ A powerful command-line interface for Bitbucket interaction with support for repositories, pull requests, issues, branches, commits, and pipelines.
6
+
7
+ ## Features
8
+
9
+ - 💻 **Interactive REPL** for Bitbucket exploration and management
10
+ - 🚀 **Headless mode** for one-off command execution and automation
11
+ - 🔐 **Multi-profile support** for managing different Bitbucket accounts
12
+ - 📊 **Multiple output formats**: JSON or TOON
13
+ - 📦 **Repository management**: list and view repository details
14
+ - 🔀 **Pull request operations**: list, view, and create pull requests
15
+ - 🐛 **Issue tracking**: list, view, and create issues
16
+ - 🌿 **Branch operations**: list branches in repositories
17
+ - 📝 **Commit history**: view commits in repositories
18
+ - 🔧 **Pipeline support**: list pipeline runs
19
+ - 👤 **User management**: retrieve user information
20
+ - ✅ **Connection testing** for quick diagnostics
21
+
22
+ ## Requirements
23
+
24
+ - [Node.js](https://nodejs.org/) v22.0 or newer
25
+ - [npm](https://www.npmjs.com/)
26
+ - Bitbucket Cloud account with API access
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install -g bbk-cli
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ ### Step 1: Create API Token
37
+
38
+ 1. Go to [Atlassian API Tokens](https://id.atlassian.com/manage-profile/security/api-tokens)
39
+ 2. Click "Create API token"
40
+ 3. Give it a label (e.g., "BBK CLI")
41
+ 4. Copy the generated token
42
+
43
+ ### Step 2: Create Configuration File
44
+
45
+ Create a configuration file at `.claude/bitbucket-config.local.md` in your project root:
46
+
47
+ ```markdown
48
+ ---
49
+ profiles:
50
+ cloud:
51
+ email: your-email@example.com
52
+ apiToken: YOUR_API_TOKEN_HERE
53
+
54
+ defaultProfile: cloud
55
+ defaultFormat: json
56
+ ---
57
+
58
+ # Bitbucket API Configuration
59
+
60
+ This file stores your Bitbucket API connection profiles.
61
+ ```
62
+
63
+ ### Configuration Options
64
+
65
+ - **profiles**: Named Bitbucket connection profiles
66
+ - `email`: Your Bitbucket email
67
+ - `apiToken`: Your Bitbucket API token
68
+
69
+ - **defaultProfile**: Profile name to use when none specified
70
+ - **defaultFormat**: Default output format (`json` or `toon`)
71
+
72
+ ### Multiple Profiles Example
73
+
74
+ ```yaml
75
+ ---
76
+ profiles:
77
+ personal:
78
+ email: john@email.com
79
+ apiToken: <api_token>
80
+
81
+ work:
82
+ email: john@company.com
83
+ apiToken: <api_token>
84
+
85
+ defaultProfile: personal
86
+ defaultFormat: json
87
+ ---
88
+ ```
89
+
90
+ ## Quick Start
91
+
92
+ ### Interactive Mode
93
+
94
+ Start the CLI and interact with Bitbucket through a REPL:
95
+
96
+ ```bash
97
+ npx bbk-cli
98
+ ```
99
+
100
+ Once started, you'll see the `bbk>` prompt:
101
+
102
+ ```
103
+ bbk> list-repositories {"workspace":"myworkspace"}
104
+ bbk> get-repository {"workspace":"myworkspace","repoSlug":"my-repo"}
105
+ bbk> list-pullrequests {"workspace":"myworkspace","repoSlug":"my-repo","state":"OPEN"}
106
+ ```
107
+
108
+ ### Headless Mode
109
+
110
+ Execute single commands directly:
111
+
112
+ ```bash
113
+ # Test connection
114
+ npx bbk-cli test-connection
115
+
116
+ # List all repositories
117
+ npx bbk-cli list-repositories '{"workspace":"myworkspace"}'
118
+
119
+ # Get repository details
120
+ npx bbk-cli get-repository '{"workspace":"myworkspace","repoSlug":"my-repo"}'
121
+
122
+ # List pull requests
123
+ npx bbk-cli list-pullrequests '{"workspace":"myworkspace","repoSlug":"my-repo","state":"OPEN"}'
124
+
125
+ # Get pull request details
126
+ npx bbk-cli get-pullrequest '{"workspace":"myworkspace","repoSlug":"my-repo","pullRequestId":123}'
127
+
128
+ # Create a new pull request
129
+ npx bbk-cli create-pullrequest '{"workspace":"myworkspace","repoSlug":"my-repo","title":"Feature PR","sourceBranch":"feature/new","destinationBranch":"main"}'
130
+
131
+ # List issues
132
+ npx bbk-cli list-issues '{"workspace":"myworkspace","repoSlug":"my-repo"}'
133
+
134
+ # Create an issue
135
+ npx bbk-cli create-issue '{"workspace":"myworkspace","repoSlug":"my-repo","title":"Bug found","kind":"bug"}'
136
+ ```
137
+
138
+ ## Available Commands
139
+
140
+ ### Repository Commands
141
+
142
+ - **list-repositories** - List all repositories in a workspace
143
+
144
+ ```bash
145
+ bbk> list-repositories {"workspace":"myworkspace"}
146
+ bbk> list-repositories {"workspace":"myworkspace","format":"json"}
147
+ ```
148
+
149
+ - **get-repository** - Get details of a specific repository
150
+ ```bash
151
+ bbk> get-repository {"workspace":"myworkspace","repoSlug":"my-repo"}
152
+ ```
153
+
154
+ ### Pull Request Commands
155
+
156
+ - **list-pullrequests** - List pull requests in a repository
157
+
158
+ ```bash
159
+ bbk> list-pullrequests {"workspace":"myworkspace","repoSlug":"my-repo"}
160
+ bbk> list-pullrequests {"workspace":"myworkspace","repoSlug":"my-repo","state":"OPEN"}
161
+ ```
162
+
163
+ - **get-pullrequest** - Get details of a specific pull request
164
+
165
+ ```bash
166
+ bbk> get-pullrequest {"workspace":"myworkspace","repoSlug":"my-repo","pullRequestId":123}
167
+ ```
168
+
169
+ - **create-pullrequest** - Create a new pull request
170
+
171
+ ```bash
172
+ bbk> create-pullrequest {"workspace":"myworkspace","repoSlug":"my-repo","title":"Feature PR","sourceBranch":"feature/new","destinationBranch":"main"}
173
+ bbk> create-pullrequest {"workspace":"myworkspace","repoSlug":"my-repo","title":"Feature PR","sourceBranch":"feature/new","destinationBranch":"main","description":"PR description"}
174
+ ```
175
+
176
+ ### Branch Commands
177
+
178
+ - **list-branches** - List branches in a repository
179
+
180
+ ```bash
181
+ bbk> list-branches {"workspace":"myworkspace","repoSlug":"my-repo"}
182
+ ```
183
+
184
+ ### Commit Commands
185
+
186
+ - **list-commits** - List commits in a repository
187
+
188
+ ```bash
189
+ bbk> list-commits {"workspace":"myworkspace","repoSlug":"my-repo"}
190
+ bbk> list-commits {"workspace":"myworkspace","repoSlug":"my-repo","branch":"main"}
191
+ ```
192
+
193
+ ### Issue Commands
194
+
195
+ - **list-issues** - List issues in a repository
196
+
197
+ ```bash
198
+ bbk> list-issues {"workspace":"myworkspace","repoSlug":"my-repo"}
199
+ ```
200
+
201
+ - **get-issue** - Get details of a specific issue
202
+
203
+ ```bash
204
+ bbk> get-issue {"workspace":"myworkspace","repoSlug":"my-repo","issueId":123}
205
+ ```
206
+
207
+ - **create-issue** - Create a new issue
208
+
209
+ ```bash
210
+ bbk> create-issue {"workspace":"myworkspace","repoSlug":"my-repo","title":"Bug found"}
211
+ bbk> create-issue {"workspace":"myworkspace","repoSlug":"my-repo","title":"Bug found","content":"Description here","kind":"bug","priority":"major"}
212
+ ```
213
+
214
+ ### Pipeline Commands
215
+
216
+ - **list-pipelines** - List pipelines in a repository
217
+
218
+ ```bash
219
+ bbk> list-pipelines {"workspace":"myworkspace","repoSlug":"my-repo"}
220
+ ```
221
+
222
+ ### User Commands
223
+
224
+ - **get-user** - Get user information
225
+ ```bash
226
+ bbk> get-user
227
+ bbk> get-user {"username":"myusername"}
228
+ ```
229
+
230
+ ### Utility Commands
231
+
232
+ - **test-connection** - Test Bitbucket API connection
233
+ ```bash
234
+ bbk> test-connection
235
+ ```
236
+
237
+ ## Interactive Mode Commands
238
+
239
+ Special commands available in the REPL:
240
+
241
+ - **commands** - List all available commands
242
+ - **help** or **?** - Show help message
243
+ - **profile \<name\>** - Switch to a different profile
244
+ - **profiles** - List all available profiles
245
+ - **format \<type\>** - Set output format (json, toon)
246
+ - **clear** - Clear the screen
247
+ - **exit**, **quit**, or **q** - Exit the CLI
248
+
249
+ ## Output Formats
250
+
251
+ ### JSON Format
252
+
253
+ Machine-readable JSON format (default):
254
+
255
+ ```bash
256
+ bbk> format json
257
+ bbk> list-repositories {"workspace":"myworkspace"}
258
+ ```
259
+
260
+ ### TOON Format
261
+
262
+ [Token-Oriented Object Notation](https://github.com/toon-format/toon) for AI-optimized output:
263
+
264
+ ```bash
265
+ bbk> format toon
266
+ bbk> list-pullrequests {"workspace":"myworkspace","repoSlug":"my-repo"}
267
+ ```
268
+
269
+ ## Security
270
+
271
+ ⚠️ **Important Security Notes:**
272
+
273
+ 1. **Never commit** `.claude/bitbucket-config.local.md` to version control
274
+ 2. Add `*.local.md` to your `.gitignore`
275
+ 3. Keep your API tokens secure and rotate them periodically
276
+ 4. Use different credentials for different environments
277
+ 5. API tokens have the same permissions as your user account
278
+
279
+ ## Development
280
+
281
+ ### Build from Source
282
+
283
+ ```bash
284
+ # Clone repository
285
+ git clone https://github.com/hesedcasa/bbk-cli.git
286
+ cd bbk-cli
287
+
288
+ # Install dependencies
289
+ npm install
290
+
291
+ # Build
292
+ npm run build
293
+
294
+ # Run in development mode
295
+ npm start
296
+ ```
297
+
298
+ ### Run Tests
299
+
300
+ ```bash
301
+ npm test # Run all tests once
302
+ npm run test:watch # Run tests in watch mode
303
+ npm run test:coverage # Run tests with coverage
304
+ ```
305
+
306
+ ### Code Quality
307
+
308
+ ```bash
309
+ npm run format # Format code with ESLint and Prettier
310
+ npm run find-deadcode # Find unused exports
311
+ npm run pre-commit # Run format + find-deadcode
312
+ ```
313
+
314
+ ## Examples
315
+
316
+ ### Basic Workflow
317
+
318
+ ```bash
319
+ # Start interactive mode
320
+ npx bbk-cli
321
+
322
+ # List all repositories in workspace
323
+ bbk> list-repositories {"workspace":"myworkspace"}
324
+
325
+ # Get specific repository
326
+ bbk> get-repository {"workspace":"myworkspace","repoSlug":"my-repo"}
327
+
328
+ # List pull requests
329
+ bbk> list-pullrequests {"workspace":"myworkspace","repoSlug":"my-repo","state":"OPEN"}
330
+
331
+ # Get specific pull request
332
+ bbk> get-pullrequest {"workspace":"myworkspace","repoSlug":"my-repo","pullRequestId":123}
333
+
334
+ # Create new pull request
335
+ bbk> create-pullrequest {"workspace":"myworkspace","repoSlug":"my-repo","title":"Feature PR","sourceBranch":"feature/new","destinationBranch":"main"}
336
+
337
+ # List branches
338
+ bbk> list-branches {"workspace":"myworkspace","repoSlug":"my-repo"}
339
+
340
+ # List commits
341
+ bbk> list-commits {"workspace":"myworkspace","repoSlug":"my-repo","branch":"main"}
342
+
343
+ # List issues
344
+ bbk> list-issues {"workspace":"myworkspace","repoSlug":"my-repo"}
345
+
346
+ # Create issue
347
+ bbk> create-issue {"workspace":"myworkspace","repoSlug":"my-repo","title":"Bug found","kind":"bug"}
348
+ ```
349
+
350
+ ## Troubleshooting
351
+
352
+ ### Connection Issues
353
+
354
+ ```bash
355
+ # Test your connection
356
+ npx bbk-cli test-connection
357
+
358
+ # Common issues:
359
+ # 1. Invalid API token - regenerate credentials
360
+ # 2. Wrong email - use your Bitbucket account email
361
+ ```
362
+
363
+ ### Authentication Errors
364
+
365
+ - Verify your API token is correct
366
+ - Check that the email matches your Bitbucket account
367
+
368
+ ### Permission Errors
369
+
370
+ - API token inherit your user permissions
371
+ - Check that your Bitbucket account has access to the workspace/repository
372
+ - Some operations require specific repository permissions
373
+ - Pull request creation requires write access to the repository
374
+
375
+ ## License
376
+
377
+ Apache-2.0
378
+
379
+ ## Acknowledgments
380
+
381
+ Built with [bitbucket](https://www.npmjs.com/package/bitbucket) by [MunifTanjim](https://github.com/MunifTanjim/node-bitbucket) - A Bitbucket API client for Node.js and Browser
@@ -0,0 +1,2 @@
1
+ export { wrapper } from './wrapper.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { wrapper } from './wrapper.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Main CLI class for Bitbucket interaction
3
+ */
4
+ export declare class wrapper {
5
+ private rl;
6
+ private config;
7
+ private currentProfile;
8
+ private currentFormat;
9
+ constructor();
10
+ /**
11
+ * Initialize the CLI and load configuration
12
+ */
13
+ connect(): Promise<void>;
14
+ /**
15
+ * Handles user input commands
16
+ * @param input - The raw user input string
17
+ */
18
+ private handleCommand;
19
+ /**
20
+ * Runs a Bitbucket command
21
+ * @param command - The command name to execute
22
+ * @param arg - JSON string or null for the command arguments
23
+ */
24
+ private runCommand;
25
+ /**
26
+ * Prints help message
27
+ */
28
+ private printHelp;
29
+ /**
30
+ * Starts the interactive REPL loop
31
+ */
32
+ start(): Promise<void>;
33
+ /**
34
+ * Disconnects from Bitbucket and closes the CLI
35
+ */
36
+ private disconnect;
37
+ }
38
+ //# sourceMappingURL=wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../src/cli/wrapper.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,EAAE,CAAqB;IAC/B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,aAAa,CAA2B;;IAUhD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;;OAGG;YACW,aAAa;IAmF3B;;;;OAIG;YACW,UAAU;IAmKxB;;OAEG;IACH,OAAO,CAAC,SAAS;IAuCjB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B5B;;OAEG;YACW,UAAU;CAKzB"}