bitbucket-data-center-client 1.4.0 → 1.4.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.
- package/README.md +38 -518
- package/dist/api/base.d.ts +11 -0
- package/dist/api/base.d.ts.map +1 -0
- package/dist/api/base.js +22 -0
- package/dist/api/base.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/projects.d.ts +14 -0
- package/dist/api/projects.d.ts.map +1 -0
- package/dist/api/projects.js +17 -0
- package/dist/api/projects.js.map +1 -0
- package/dist/api/pull-requests.d.ts +81 -0
- package/dist/api/pull-requests.d.ts.map +1 -0
- package/dist/api/pull-requests.js +206 -0
- package/dist/api/pull-requests.js.map +1 -0
- package/dist/api/repositories.d.ts +35 -0
- package/dist/api/repositories.d.ts.map +1 -0
- package/dist/api/repositories.js +85 -0
- package/dist/api/repositories.js.map +1 -0
- package/dist/api/users.d.ts +18 -0
- package/dist/api/users.d.ts.map +1 -0
- package/dist/api/users.js +24 -0
- package/dist/api/users.js.map +1 -0
- package/dist/client.d.ts +41 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +44 -195
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types/common.d.ts +72 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +5 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/project.d.ts +41 -0
- package/dist/types/project.d.ts.map +1 -0
- package/dist/types/project.js +2 -0
- package/dist/types/project.js.map +1 -0
- package/dist/types/pull-request.d.ts +730 -0
- package/dist/types/pull-request.d.ts.map +1 -0
- package/dist/types/pull-request.js +2 -0
- package/dist/types/pull-request.js.map +1 -0
- package/dist/types/repository.d.ts +172 -0
- package/dist/types/repository.d.ts.map +1 -0
- package/dist/types/repository.js +2 -0
- package/dist/types/repository.js.map +1 -0
- package/dist/types/user.d.ts +46 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +2 -0
- package/dist/types/user.js.map +1 -0
- package/package.json +21 -12
- package/.claude/settings.local.json +0 -10
- package/AGENTS.md +0 -123
- package/BitbucketServerSwagger.json +0 -67522
- package/LICENSE +0 -21
- package/dist/types.d.ts +0 -490
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
# Bitbucket Data Center Client
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🔒 **Type-safe**: Full TypeScript support with comprehensive type definitions
|
|
8
|
-
- 🚀 **Simple**: Clean, intuitive API design
|
|
9
|
-
- 📦 **Lightweight**: Minimal dependencies (only axios)
|
|
10
|
-
- 🎯 **Complete**: Covers users, projects, repositories, and pull requests operations
|
|
3
|
+
TypeScript client for Bitbucket Server/Data Center REST API.
|
|
11
4
|
|
|
12
5
|
## Installation
|
|
13
6
|
|
|
@@ -15,552 +8,89 @@ A TypeScript client library for Bitbucket Server/Data Center REST API. This libr
|
|
|
15
8
|
npm install bitbucket-data-center-client
|
|
16
9
|
```
|
|
17
10
|
|
|
18
|
-
##
|
|
11
|
+
## Usage
|
|
19
12
|
|
|
20
13
|
```typescript
|
|
21
14
|
import { BitbucketClient } from 'bitbucket-data-center-client';
|
|
22
15
|
|
|
23
|
-
// Initialize the client
|
|
24
16
|
const client = new BitbucketClient({
|
|
17
|
+
baseUrl: 'https://bitbucket.example.com',
|
|
25
18
|
token: 'your-personal-access-token',
|
|
26
|
-
baseUrl: 'https://bitbucket.example.com'
|
|
27
19
|
});
|
|
28
20
|
|
|
29
21
|
// Get user profile
|
|
30
|
-
const user = await client.
|
|
31
|
-
console.log(user.displayName);
|
|
22
|
+
const user = await client.users.getProfile({ username: 'john.doe' });
|
|
32
23
|
|
|
33
24
|
// List projects
|
|
34
|
-
const projects = await client.
|
|
35
|
-
projects.values.forEach(project => {
|
|
36
|
-
console.log(`${project.key}: ${project.name}`);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Get pull requests in your inbox
|
|
40
|
-
const prs = await client.getInboxPullRequests({ limit: 25 });
|
|
41
|
-
prs.values.forEach(pr => {
|
|
42
|
-
console.log(`PR #${pr.id}: ${pr.title}`);
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Authentication
|
|
47
|
-
|
|
48
|
-
The client uses **Bearer token authentication** with Bitbucket Personal Access Tokens:
|
|
49
|
-
|
|
50
|
-
1. Generate a Personal Access Token in Bitbucket Server:
|
|
51
|
-
- Navigate to **Profile → Manage account → Personal access tokens**
|
|
52
|
-
- Create a token with appropriate permissions (e.g., `REPO_READ`, `REPO_WRITE`)
|
|
53
|
-
2. Pass the token and base URL to the client constructor
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
// Simple configuration (most common)
|
|
57
|
-
const client = new BitbucketClient({
|
|
58
|
-
token: process.env.BITBUCKET_TOKEN!,
|
|
59
|
-
baseUrl: process.env.BITBUCKET_URL! // e.g., 'https://bitbucket.example.com'
|
|
60
|
-
});
|
|
25
|
+
const projects = await client.projects.list();
|
|
61
26
|
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
token: process.env.BITBUCKET_TOKEN!,
|
|
65
|
-
baseUrl: process.env.BITBUCKET_URL!,
|
|
66
|
-
axiosConfig: {
|
|
67
|
-
timeout: 10000,
|
|
68
|
-
headers: {
|
|
69
|
-
'X-Custom-Header': 'value'
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## API Reference
|
|
76
|
-
|
|
77
|
-
### User Operations
|
|
78
|
-
|
|
79
|
-
#### Get User Profile
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
const user = await client.getUserProfile({
|
|
83
|
-
username: 'john.doe'
|
|
84
|
-
});
|
|
85
|
-
console.log(user.displayName, user.emailAddress);
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
#### Get All Users
|
|
27
|
+
// List repositories in a project
|
|
28
|
+
const repos = await client.repositories.list({ projectKey: 'PROJ' });
|
|
89
29
|
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
filter: 'john' // Optional: filter by username, name, or email
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Project Operations
|
|
97
|
-
|
|
98
|
-
#### List Projects
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
const projects = await client.listProjects({
|
|
102
|
-
name: 'MyProject', // Optional: filter by name
|
|
103
|
-
permission: 'PROJECT_WRITE', // Optional: filter by permission
|
|
104
|
-
start: 0, // Optional: pagination start
|
|
105
|
-
limit: 25 // Optional: page size
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Repository Operations
|
|
110
|
-
|
|
111
|
-
#### List Repositories
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
const repos = await client.listRepositories({
|
|
115
|
-
projectKey: 'PROJ'
|
|
116
|
-
});
|
|
117
|
-
repos.values.forEach(repo => {
|
|
118
|
-
console.log(`${repo.slug}: ${repo.name}`);
|
|
119
|
-
});
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
#### Get Repository
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
const repo = await client.getRepository({
|
|
126
|
-
projectKey: 'PROJ',
|
|
127
|
-
repositorySlug: 'my-repo'
|
|
128
|
-
});
|
|
129
|
-
console.log(`ID: ${repo.id}, Name: ${repo.name}`);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Pull Request Operations
|
|
133
|
-
|
|
134
|
-
#### Get Inbox Pull Requests
|
|
135
|
-
|
|
136
|
-
Get all PRs where you're assigned as a reviewer:
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
const prs = await client.getInboxPullRequests({
|
|
140
|
-
start: 0,
|
|
141
|
-
limit: 25
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
#### Get Pull Request Details
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
const pr = await client.getPullRequest({
|
|
149
|
-
projectKey: 'PROJ',
|
|
150
|
-
repositorySlug: 'my-repo',
|
|
151
|
-
pullRequestId: 123
|
|
152
|
-
});
|
|
153
|
-
console.log(pr.title, pr.author?.user.displayName);
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
#### Create Pull Request
|
|
157
|
-
|
|
158
|
-
Create a new pull request. Branch names are automatically converted to full refs:
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
// Simple same-repo PR
|
|
162
|
-
const pr = await client.createPullRequest({
|
|
30
|
+
// Browse repository contents
|
|
31
|
+
const contents = await client.repositories.browse({
|
|
163
32
|
projectKey: 'PROJ',
|
|
164
33
|
repositorySlug: 'my-repo',
|
|
165
|
-
|
|
166
|
-
description: 'This PR adds the new feature as discussed',
|
|
167
|
-
fromBranch: 'feature-branch', // Just the branch name
|
|
168
|
-
toBranch: 'main'
|
|
34
|
+
path: 'src',
|
|
169
35
|
});
|
|
170
36
|
|
|
171
|
-
//
|
|
172
|
-
const
|
|
37
|
+
// Get raw file content
|
|
38
|
+
const file = await client.repositories.getRawContent({
|
|
173
39
|
projectKey: 'PROJ',
|
|
174
40
|
repositorySlug: 'my-repo',
|
|
175
|
-
|
|
176
|
-
description: 'Fixes issue #123',
|
|
177
|
-
fromBranch: 'bugfix/critical-issue',
|
|
178
|
-
toBranch: 'develop',
|
|
179
|
-
reviewers: ['john.doe', 'jane.smith']
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Draft PR
|
|
183
|
-
const draftPr = await client.createPullRequest({
|
|
184
|
-
projectKey: 'PROJ',
|
|
185
|
-
repositorySlug: 'my-repo',
|
|
186
|
-
title: 'WIP: Refactor authentication',
|
|
187
|
-
fromBranch: 'wip/auth-refactor',
|
|
188
|
-
toBranch: 'main',
|
|
189
|
-
draft: true
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Cross-repo PR (from fork to upstream)
|
|
193
|
-
const crossRepoPr = await client.createPullRequest({
|
|
194
|
-
projectKey: 'UPSTREAM',
|
|
195
|
-
repositorySlug: 'upstream-repo',
|
|
196
|
-
title: 'Contribution from fork',
|
|
197
|
-
fromBranch: 'feature',
|
|
198
|
-
toBranch: 'main',
|
|
199
|
-
fromRepositorySlug: 'my-fork',
|
|
200
|
-
fromProjectKey: 'MYPROJ'
|
|
201
|
-
});
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
#### Get Required/Default Reviewers
|
|
205
|
-
|
|
206
|
-
Get the list of default reviewers for a PR before creating it. **Important:** Default reviewers are NOT automatically added when creating PRs via API - you must fetch them and pass them explicitly.
|
|
207
|
-
|
|
208
|
-
Use `getRepository()` to obtain the repository ID:
|
|
209
|
-
|
|
210
|
-
```typescript
|
|
211
|
-
// First get the repository to obtain its ID
|
|
212
|
-
const repo = await client.getRepository({
|
|
213
|
-
projectKey: 'PROJ',
|
|
214
|
-
repositorySlug: 'my-repo'
|
|
41
|
+
path: 'package.json',
|
|
215
42
|
});
|
|
216
43
|
|
|
217
|
-
// Get
|
|
218
|
-
const
|
|
44
|
+
// Get pull request details
|
|
45
|
+
const pr = await client.pullRequests.get({
|
|
219
46
|
projectKey: 'PROJ',
|
|
220
47
|
repositorySlug: 'my-repo',
|
|
221
|
-
|
|
222
|
-
sourceBranch: 'feature-branch',
|
|
223
|
-
targetBranch: 'main'
|
|
48
|
+
pullRequestId: 123,
|
|
224
49
|
});
|
|
225
50
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// Create PR with default reviewers
|
|
229
|
-
const pr = await client.createPullRequest({
|
|
51
|
+
// Create a pull request
|
|
52
|
+
const newPr = await client.pullRequests.create({
|
|
230
53
|
projectKey: 'PROJ',
|
|
231
54
|
repositorySlug: 'my-repo',
|
|
232
|
-
title: 'My feature',
|
|
233
55
|
fromBranch: 'feature-branch',
|
|
234
56
|
toBranch: 'main',
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
#### Get Pull Request Changes
|
|
240
|
-
|
|
241
|
-
Get list of changed files:
|
|
242
|
-
|
|
243
|
-
```typescript
|
|
244
|
-
const changes = await client.getPullRequestChanges({
|
|
245
|
-
projectKey: 'PROJ',
|
|
246
|
-
repositorySlug: 'my-repo',
|
|
247
|
-
pullRequestId: 123
|
|
248
|
-
});
|
|
249
|
-
changes.values.forEach(change => {
|
|
250
|
-
console.log(`${change.type}: ${change.path?.toString}`);
|
|
251
|
-
});
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
#### Get Pull Request Diff
|
|
255
|
-
|
|
256
|
-
Get diff for entire PR or specific file:
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
// Full PR diff (text format)
|
|
260
|
-
const textDiff = await client.getPullRequestDiff({
|
|
261
|
-
projectKey: 'PROJ',
|
|
262
|
-
repositorySlug: 'my-repo',
|
|
263
|
-
pullRequestId: 123,
|
|
264
|
-
format: 'text'
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
// Structured diff for specific file
|
|
268
|
-
const structuredDiff = await client.getPullRequestDiff({
|
|
269
|
-
projectKey: 'PROJ',
|
|
270
|
-
repositorySlug: 'my-repo',
|
|
271
|
-
pullRequestId: 123,
|
|
272
|
-
path: 'src/index.ts',
|
|
273
|
-
format: 'json',
|
|
274
|
-
contextLines: 3
|
|
275
|
-
});
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
#### Get File Diff with Line Numbers
|
|
279
|
-
|
|
280
|
-
Get structured line-by-line diff for a specific file:
|
|
281
|
-
|
|
282
|
-
```typescript
|
|
283
|
-
const diff = await client.getPullRequestFileDiff({
|
|
284
|
-
projectKey: 'PROJ',
|
|
285
|
-
repositorySlug: 'my-repo',
|
|
286
|
-
pullRequestId: 123,
|
|
287
|
-
path: 'src/main.ts',
|
|
288
|
-
contextLines: 10
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// Access hunks and segments
|
|
292
|
-
diff.diffs[0]?.hunks?.forEach(hunk => {
|
|
293
|
-
hunk.segments.forEach(segment => {
|
|
294
|
-
segment.lines.forEach(line => {
|
|
295
|
-
console.log(`Line ${line.destination}: ${line.line}`);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
#### Get Pull Request Activities
|
|
302
|
-
|
|
303
|
-
Get PR activity (comments, approvals, etc.):
|
|
304
|
-
|
|
305
|
-
```typescript
|
|
306
|
-
const activities = await client.getPullRequestActivities({
|
|
307
|
-
projectKey: 'PROJ',
|
|
308
|
-
repositorySlug: 'my-repo',
|
|
309
|
-
pullRequestId: 123,
|
|
310
|
-
activityTypes: ['COMMENTED', 'REVIEW_COMMENTED'], // Optional filter
|
|
311
|
-
start: 0,
|
|
312
|
-
limit: 25
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
activities.values.forEach(activity => {
|
|
316
|
-
console.log(`${activity.action}: ${activity.comment?.text}`);
|
|
317
|
-
});
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
#### Add Pull Request Comment
|
|
321
|
-
|
|
322
|
-
Add general, file, or line comment:
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
// General comment
|
|
326
|
-
await client.addPullRequestComment({
|
|
327
|
-
projectKey: 'PROJ',
|
|
328
|
-
repositorySlug: 'my-repo',
|
|
329
|
-
pullRequestId: 123,
|
|
330
|
-
text: 'Looks good to me!'
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// File-level comment
|
|
334
|
-
await client.addPullRequestComment({
|
|
335
|
-
projectKey: 'PROJ',
|
|
336
|
-
repositorySlug: 'my-repo',
|
|
337
|
-
pullRequestId: 123,
|
|
338
|
-
text: 'This file needs refactoring',
|
|
339
|
-
path: 'src/main.ts'
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
// Inline comment on specific line
|
|
343
|
-
await client.addPullRequestComment({
|
|
344
|
-
projectKey: 'PROJ',
|
|
345
|
-
repositorySlug: 'my-repo',
|
|
346
|
-
pullRequestId: 123,
|
|
347
|
-
text: 'Consider using const here',
|
|
348
|
-
path: 'src/main.ts',
|
|
349
|
-
line: 42,
|
|
350
|
-
lineType: 'ADDED',
|
|
351
|
-
fileType: 'TO'
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
// Reply to a comment
|
|
355
|
-
await client.addPullRequestComment({
|
|
356
|
-
projectKey: 'PROJ',
|
|
357
|
-
repositorySlug: 'my-repo',
|
|
358
|
-
pullRequestId: 123,
|
|
359
|
-
text: 'Good catch!',
|
|
360
|
-
parentId: 456
|
|
361
|
-
});
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
#### Delete Pull Request Comment
|
|
365
|
-
|
|
366
|
-
```typescript
|
|
367
|
-
await client.deletePullRequestComment({
|
|
368
|
-
projectKey: 'PROJ',
|
|
369
|
-
repositorySlug: 'my-repo',
|
|
370
|
-
pullRequestId: 123,
|
|
371
|
-
commentId: 456,
|
|
372
|
-
version: 1 // Get from comment object
|
|
373
|
-
});
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
#### Update Review Status
|
|
377
|
-
|
|
378
|
-
Approve, request changes, or remove approval:
|
|
379
|
-
|
|
380
|
-
```typescript
|
|
381
|
-
// Approve PR
|
|
382
|
-
await client.updateReviewStatus({
|
|
383
|
-
projectKey: 'PROJ',
|
|
384
|
-
repositorySlug: 'my-repo',
|
|
385
|
-
pullRequestId: 123,
|
|
386
|
-
status: 'APPROVED'
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
// Request changes
|
|
390
|
-
await client.updateReviewStatus({
|
|
391
|
-
projectKey: 'PROJ',
|
|
392
|
-
repositorySlug: 'my-repo',
|
|
393
|
-
pullRequestId: 123,
|
|
394
|
-
status: 'NEEDS_WORK'
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
// Remove approval
|
|
398
|
-
await client.updateReviewStatus({
|
|
399
|
-
projectKey: 'PROJ',
|
|
400
|
-
repositorySlug: 'my-repo',
|
|
401
|
-
pullRequestId: 123,
|
|
402
|
-
status: 'UNAPPROVED'
|
|
57
|
+
title: 'Add new feature',
|
|
58
|
+
reviewers: ['reviewer1', 'reviewer2'],
|
|
403
59
|
});
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
#### Add/Remove Comment Reactions
|
|
407
60
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
await client.addPullRequestCommentReaction({
|
|
61
|
+
// Add a comment to a PR
|
|
62
|
+
await client.pullRequests.addComment({
|
|
411
63
|
projectKey: 'PROJ',
|
|
412
64
|
repositorySlug: 'my-repo',
|
|
413
65
|
pullRequestId: 123,
|
|
414
|
-
|
|
415
|
-
emoticon: 'thumbsup' // thumbsup, thumbsdown, heart, thinking_face, laughing
|
|
66
|
+
text: 'Looks good!',
|
|
416
67
|
});
|
|
417
68
|
|
|
418
|
-
//
|
|
419
|
-
await client.
|
|
69
|
+
// Approve a PR
|
|
70
|
+
await client.pullRequests.updateReviewStatus({
|
|
420
71
|
projectKey: 'PROJ',
|
|
421
72
|
repositorySlug: 'my-repo',
|
|
422
73
|
pullRequestId: 123,
|
|
423
|
-
|
|
424
|
-
emoticon: 'thumbsup'
|
|
425
|
-
});
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
## Complete Example: PR Review Workflow
|
|
429
|
-
|
|
430
|
-
```typescript
|
|
431
|
-
import { BitbucketClient } from 'bitbucket-data-center-client';
|
|
432
|
-
|
|
433
|
-
const client = new BitbucketClient({
|
|
434
|
-
token: process.env.BITBUCKET_TOKEN!,
|
|
435
|
-
baseUrl: process.env.BITBUCKET_URL!
|
|
74
|
+
status: 'APPROVED',
|
|
436
75
|
});
|
|
437
|
-
|
|
438
|
-
async function reviewPullRequest() {
|
|
439
|
-
// 1. Get PRs in your inbox
|
|
440
|
-
const inbox = await client.getInboxPullRequests({ limit: 10 });
|
|
441
|
-
const pr = inbox.values[0];
|
|
442
|
-
|
|
443
|
-
if (!pr) {
|
|
444
|
-
console.log('No PRs to review');
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
console.log(`Reviewing: ${pr.title}`);
|
|
449
|
-
|
|
450
|
-
// 2. Get PR details
|
|
451
|
-
const projectKey = pr.toRef.repository.project.key;
|
|
452
|
-
const repositorySlug = pr.toRef.repository.slug;
|
|
453
|
-
const pullRequestId = pr.id;
|
|
454
|
-
|
|
455
|
-
// 3. Get changed files
|
|
456
|
-
const changes = await client.getPullRequestChanges({
|
|
457
|
-
projectKey,
|
|
458
|
-
repositorySlug,
|
|
459
|
-
pullRequestId
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
console.log(`Changed files: ${changes.values.length}`);
|
|
463
|
-
|
|
464
|
-
// 4. Review each file
|
|
465
|
-
for (const change of changes.values) {
|
|
466
|
-
const path = change.path?.toString;
|
|
467
|
-
if (!path) continue;
|
|
468
|
-
|
|
469
|
-
// Get file diff
|
|
470
|
-
const diff = await client.getPullRequestFileDiff({
|
|
471
|
-
projectKey,
|
|
472
|
-
repositorySlug,
|
|
473
|
-
pullRequestId,
|
|
474
|
-
path
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
// Check for issues and add comments
|
|
478
|
-
diff.diffs[0]?.hunks?.forEach(hunk => {
|
|
479
|
-
hunk.segments.forEach(segment => {
|
|
480
|
-
if (segment.type === 'ADDED') {
|
|
481
|
-
segment.lines.forEach(line => {
|
|
482
|
-
if (line.line?.includes('console.log')) {
|
|
483
|
-
// Add inline comment
|
|
484
|
-
client.addPullRequestComment({
|
|
485
|
-
projectKey,
|
|
486
|
-
repositorySlug,
|
|
487
|
-
pullRequestId,
|
|
488
|
-
text: 'Please remove console.log before merging',
|
|
489
|
-
path,
|
|
490
|
-
line: line.destination!,
|
|
491
|
-
lineType: 'ADDED',
|
|
492
|
-
fileType: 'TO'
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// 5. Approve or request changes
|
|
502
|
-
await client.updateReviewStatus({
|
|
503
|
-
projectKey,
|
|
504
|
-
repositorySlug,
|
|
505
|
-
pullRequestId,
|
|
506
|
-
status: 'NEEDS_WORK'
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
console.log('Review complete!');
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
reviewPullRequest().catch(console.error);
|
|
513
76
|
```
|
|
514
77
|
|
|
515
|
-
##
|
|
78
|
+
## API Structure
|
|
516
79
|
|
|
517
|
-
|
|
80
|
+
| Domain | Methods |
|
|
81
|
+
|--------|---------|
|
|
82
|
+
| `client.users` | `getProfile`, `getAll` |
|
|
83
|
+
| `client.projects` | `list` |
|
|
84
|
+
| `client.repositories` | `list`, `get`, `browse`, `getRawContent`, `checkPermissions` |
|
|
85
|
+
| `client.pullRequests` | `getInbox`, `getDashboard`, `get`, `create`, `getChanges`, `getDiff`, `getFileDiff`, `getActivities`, `addComment`, `deleteComment`, `updateReviewStatus`, `addReaction`, `removeReaction`, `getRequiredReviewers` |
|
|
518
86
|
|
|
519
|
-
|
|
520
|
-
import type {
|
|
521
|
-
// Common
|
|
522
|
-
PaginatedResponse,
|
|
523
|
-
// User & Project
|
|
524
|
-
RestUser,
|
|
525
|
-
RestProject,
|
|
526
|
-
RestRepository,
|
|
527
|
-
// Pull Request
|
|
528
|
-
RestPullRequest,
|
|
529
|
-
InboxPullRequest,
|
|
530
|
-
RestComment,
|
|
531
|
-
RestChange,
|
|
532
|
-
DiffResponse,
|
|
533
|
-
RestPullRequestActivity,
|
|
534
|
-
// Method parameters
|
|
535
|
-
GetPullRequestParams,
|
|
536
|
-
AddPullRequestCommentParams,
|
|
537
|
-
UpdateReviewStatusParams,
|
|
538
|
-
// ... and many more
|
|
539
|
-
} from 'bitbucket-data-center-client';
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
See [types.ts](./src/types.ts) for the complete list of exported types.
|
|
543
|
-
|
|
544
|
-
## API Documentation
|
|
545
|
-
|
|
546
|
-
This library is based on the official Bitbucket Server REST API. See `BitbucketServerSwagger.json` in this package for the complete API specification.
|
|
547
|
-
|
|
548
|
-
## Error Handling
|
|
87
|
+
## Authentication
|
|
549
88
|
|
|
550
|
-
|
|
89
|
+
Generate a Personal Access Token in Bitbucket: **Profile > Manage account > Personal access tokens**
|
|
551
90
|
|
|
552
|
-
```
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
projectKey: 'PROJ',
|
|
556
|
-
repositorySlug: 'my-repo',
|
|
557
|
-
pullRequestId: 999
|
|
558
|
-
});
|
|
559
|
-
} catch (error) {
|
|
560
|
-
if (axios.isAxiosError(error)) {
|
|
561
|
-
console.error('API Error:', error.response?.data);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
91
|
+
```bash
|
|
92
|
+
export BITBUCKET_URL=https://bitbucket.example.com
|
|
93
|
+
export BITBUCKET_TOKEN=your-personal-access-token
|
|
564
94
|
```
|
|
565
95
|
|
|
566
96
|
## Requirements
|
|
@@ -571,13 +101,3 @@ try {
|
|
|
571
101
|
## License
|
|
572
102
|
|
|
573
103
|
MIT
|
|
574
|
-
|
|
575
|
-
## Contributing
|
|
576
|
-
|
|
577
|
-
Contributions are welcome! Please open an issue or submit a pull request.
|
|
578
|
-
|
|
579
|
-
## Support
|
|
580
|
-
|
|
581
|
-
For issues and questions:
|
|
582
|
-
- GitHub Issues: [your-repo-url]
|
|
583
|
-
- Documentation: See inline JSDoc comments in the source code
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type AxiosInstance } from 'axios';
|
|
2
|
+
import type { BitbucketClientConfig } from '../types/common.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base API class providing shared axios configuration for all domain APIs.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BaseApi {
|
|
7
|
+
protected client: AxiosInstance;
|
|
8
|
+
protected baseUrl: string;
|
|
9
|
+
constructor(config: BitbucketClientConfig);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE;;GAEG;AACH,qBAAa,OAAO;IAClB,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC;IAChC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEP,MAAM,EAAE,qBAAqB;CAcjD"}
|
package/dist/api/base.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Base API class providing shared axios configuration for all domain APIs.
|
|
4
|
+
*/
|
|
5
|
+
export class BaseApi {
|
|
6
|
+
client;
|
|
7
|
+
baseUrl;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
const { token, baseUrl, axiosConfig = {} } = config;
|
|
10
|
+
this.baseUrl = baseUrl;
|
|
11
|
+
this.client = axios.create({
|
|
12
|
+
...axiosConfig,
|
|
13
|
+
baseURL: `${baseUrl}/rest/api/latest`,
|
|
14
|
+
headers: {
|
|
15
|
+
...axiosConfig.headers,
|
|
16
|
+
Authorization: `Bearer ${token}`,
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/api/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,OAAO;IACR,MAAM,CAAgB;IACtB,OAAO,CAAS;IAE1B,YAAmB,MAA6B;QAC9C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACzB,GAAG,WAAW;YACd,OAAO,EAAE,GAAG,OAAO,kBAAkB;YACrC,OAAO,EAAE;gBACP,GAAG,WAAW,CAAC,OAAO;gBACtB,aAAa,EAAE,UAAU,KAAK,EAAE;gBAChC,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseApi } from './base.js';
|
|
2
|
+
export { ProjectsApi } from './projects.js';
|
|
3
|
+
export { PullRequestsApi } from './pull-requests.js';
|
|
4
|
+
export { RepositoriesApi } from './repositories.js';
|
|
5
|
+
export { UsersApi } from './users.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { BaseApi } from './base.js';
|
|
2
|
+
export { ProjectsApi } from './projects.js';
|
|
3
|
+
export { PullRequestsApi } from './pull-requests.js';
|
|
4
|
+
export { RepositoriesApi } from './repositories.js';
|
|
5
|
+
export { UsersApi } from './users.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseApi } from './base.js';
|
|
2
|
+
import type { PaginatedResponse } from '../types/common.js';
|
|
3
|
+
import type { ListProjectsParams, RestProject } from '../types/project.js';
|
|
4
|
+
/**
|
|
5
|
+
* Projects API for Bitbucket Server.
|
|
6
|
+
* Provides methods for project-related operations.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ProjectsApi extends BaseApi {
|
|
9
|
+
/**
|
|
10
|
+
* List projects, optionally filtered by name or permission
|
|
11
|
+
*/
|
|
12
|
+
list(params?: ListProjectsParams): Promise<PaginatedResponse<RestProject>>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/api/projects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE3E;;;GAGG;AACH,qBAAa,WAAY,SAAQ,OAAO;IACtC;;OAEG;IACU,IAAI,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;CAMxF"}
|