bitbucket-data-center-client 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Evrim Alacan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,490 @@
1
+ # Bitbucket Data Center Client
2
+
3
+ A TypeScript client library for Bitbucket Server/Data Center REST API. This library provides a simple, type-safe interface for interacting with Bitbucket Server's REST API.
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
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install bitbucket-data-center-client
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```typescript
21
+ import { BitbucketClient } from 'bitbucket-data-center-client';
22
+
23
+ // Initialize the client
24
+ const client = new BitbucketClient({
25
+ token: 'your-personal-access-token',
26
+ baseUrl: 'https://bitbucket.example.com'
27
+ });
28
+
29
+ // Get user profile
30
+ const user = await client.getUserProfile({ username: 'john.doe' });
31
+ console.log(user.displayName);
32
+
33
+ // List projects
34
+ const projects = await client.listProjects({ limit: 10 });
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
+ });
61
+
62
+ // Advanced: with custom axios configuration
63
+ const client = new BitbucketClient({
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
89
+
90
+ ```typescript
91
+ const users = await client.getAllUsers({
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
+ ### Pull Request Operations
123
+
124
+ #### Get Inbox Pull Requests
125
+
126
+ Get all PRs where you're assigned as a reviewer:
127
+
128
+ ```typescript
129
+ const prs = await client.getInboxPullRequests({
130
+ start: 0,
131
+ limit: 25
132
+ });
133
+ ```
134
+
135
+ #### Get Pull Request Details
136
+
137
+ ```typescript
138
+ const pr = await client.getPullRequest({
139
+ projectKey: 'PROJ',
140
+ repositorySlug: 'my-repo',
141
+ pullRequestId: 123
142
+ });
143
+ console.log(pr.title, pr.author?.user.displayName);
144
+ ```
145
+
146
+ #### Get Pull Request Changes
147
+
148
+ Get list of changed files:
149
+
150
+ ```typescript
151
+ const changes = await client.getPullRequestChanges({
152
+ projectKey: 'PROJ',
153
+ repositorySlug: 'my-repo',
154
+ pullRequestId: 123
155
+ });
156
+ changes.values.forEach(change => {
157
+ console.log(`${change.type}: ${change.path?.toString}`);
158
+ });
159
+ ```
160
+
161
+ #### Get Pull Request Diff
162
+
163
+ Get diff for entire PR or specific file:
164
+
165
+ ```typescript
166
+ // Full PR diff (text format)
167
+ const textDiff = await client.getPullRequestDiff({
168
+ projectKey: 'PROJ',
169
+ repositorySlug: 'my-repo',
170
+ pullRequestId: 123,
171
+ format: 'text'
172
+ });
173
+
174
+ // Structured diff for specific file
175
+ const structuredDiff = await client.getPullRequestDiff({
176
+ projectKey: 'PROJ',
177
+ repositorySlug: 'my-repo',
178
+ pullRequestId: 123,
179
+ path: 'src/index.ts',
180
+ format: 'json',
181
+ contextLines: 3
182
+ });
183
+ ```
184
+
185
+ #### Get File Diff with Line Numbers
186
+
187
+ Get structured line-by-line diff for a specific file:
188
+
189
+ ```typescript
190
+ const diff = await client.getPullRequestFileDiff({
191
+ projectKey: 'PROJ',
192
+ repositorySlug: 'my-repo',
193
+ pullRequestId: 123,
194
+ path: 'src/main.ts',
195
+ contextLines: 10
196
+ });
197
+
198
+ // Access hunks and segments
199
+ diff.diffs[0]?.hunks?.forEach(hunk => {
200
+ hunk.segments.forEach(segment => {
201
+ segment.lines.forEach(line => {
202
+ console.log(`Line ${line.destination}: ${line.line}`);
203
+ });
204
+ });
205
+ });
206
+ ```
207
+
208
+ #### Get Pull Request Activities
209
+
210
+ Get PR activity (comments, approvals, etc.):
211
+
212
+ ```typescript
213
+ const activities = await client.getPullRequestActivities({
214
+ projectKey: 'PROJ',
215
+ repositorySlug: 'my-repo',
216
+ pullRequestId: 123,
217
+ activityTypes: ['COMMENTED', 'REVIEW_COMMENTED'], // Optional filter
218
+ start: 0,
219
+ limit: 25
220
+ });
221
+
222
+ activities.values.forEach(activity => {
223
+ console.log(`${activity.action}: ${activity.comment?.text}`);
224
+ });
225
+ ```
226
+
227
+ #### Add Pull Request Comment
228
+
229
+ Add general, file, or line comment:
230
+
231
+ ```typescript
232
+ // General comment
233
+ await client.addPullRequestComment({
234
+ projectKey: 'PROJ',
235
+ repositorySlug: 'my-repo',
236
+ pullRequestId: 123,
237
+ text: 'Looks good to me!'
238
+ });
239
+
240
+ // File-level comment
241
+ await client.addPullRequestComment({
242
+ projectKey: 'PROJ',
243
+ repositorySlug: 'my-repo',
244
+ pullRequestId: 123,
245
+ text: 'This file needs refactoring',
246
+ path: 'src/main.ts'
247
+ });
248
+
249
+ // Inline comment on specific line
250
+ await client.addPullRequestComment({
251
+ projectKey: 'PROJ',
252
+ repositorySlug: 'my-repo',
253
+ pullRequestId: 123,
254
+ text: 'Consider using const here',
255
+ path: 'src/main.ts',
256
+ line: 42,
257
+ lineType: 'ADDED',
258
+ fileType: 'TO'
259
+ });
260
+
261
+ // Reply to a comment
262
+ await client.addPullRequestComment({
263
+ projectKey: 'PROJ',
264
+ repositorySlug: 'my-repo',
265
+ pullRequestId: 123,
266
+ text: 'Good catch!',
267
+ parentId: 456
268
+ });
269
+ ```
270
+
271
+ #### Delete Pull Request Comment
272
+
273
+ ```typescript
274
+ await client.deletePullRequestComment({
275
+ projectKey: 'PROJ',
276
+ repositorySlug: 'my-repo',
277
+ pullRequestId: 123,
278
+ commentId: 456,
279
+ version: 1 // Get from comment object
280
+ });
281
+ ```
282
+
283
+ #### Update Review Status
284
+
285
+ Approve, request changes, or remove approval:
286
+
287
+ ```typescript
288
+ // Approve PR
289
+ await client.updateReviewStatus({
290
+ projectKey: 'PROJ',
291
+ repositorySlug: 'my-repo',
292
+ pullRequestId: 123,
293
+ status: 'APPROVED'
294
+ });
295
+
296
+ // Request changes
297
+ await client.updateReviewStatus({
298
+ projectKey: 'PROJ',
299
+ repositorySlug: 'my-repo',
300
+ pullRequestId: 123,
301
+ status: 'NEEDS_WORK'
302
+ });
303
+
304
+ // Remove approval
305
+ await client.updateReviewStatus({
306
+ projectKey: 'PROJ',
307
+ repositorySlug: 'my-repo',
308
+ pullRequestId: 123,
309
+ status: 'UNAPPROVED'
310
+ });
311
+ ```
312
+
313
+ #### Add/Remove Comment Reactions
314
+
315
+ ```typescript
316
+ // Add reaction
317
+ await client.addPullRequestCommentReaction({
318
+ projectKey: 'PROJ',
319
+ repositorySlug: 'my-repo',
320
+ pullRequestId: 123,
321
+ commentId: 456,
322
+ emoticon: 'thumbsup' // thumbsup, thumbsdown, heart, thinking_face, laughing
323
+ });
324
+
325
+ // Remove reaction
326
+ await client.removePullRequestCommentReaction({
327
+ projectKey: 'PROJ',
328
+ repositorySlug: 'my-repo',
329
+ pullRequestId: 123,
330
+ commentId: 456,
331
+ emoticon: 'thumbsup'
332
+ });
333
+ ```
334
+
335
+ ## Complete Example: PR Review Workflow
336
+
337
+ ```typescript
338
+ import { BitbucketClient } from 'bitbucket-data-center-client';
339
+
340
+ const client = new BitbucketClient({
341
+ token: process.env.BITBUCKET_TOKEN!,
342
+ baseUrl: process.env.BITBUCKET_URL!
343
+ });
344
+
345
+ async function reviewPullRequest() {
346
+ // 1. Get PRs in your inbox
347
+ const inbox = await client.getInboxPullRequests({ limit: 10 });
348
+ const pr = inbox.values[0];
349
+
350
+ if (!pr) {
351
+ console.log('No PRs to review');
352
+ return;
353
+ }
354
+
355
+ console.log(`Reviewing: ${pr.title}`);
356
+
357
+ // 2. Get PR details
358
+ const projectKey = pr.toRef.repository.project.key;
359
+ const repositorySlug = pr.toRef.repository.slug;
360
+ const pullRequestId = pr.id;
361
+
362
+ // 3. Get changed files
363
+ const changes = await client.getPullRequestChanges({
364
+ projectKey,
365
+ repositorySlug,
366
+ pullRequestId
367
+ });
368
+
369
+ console.log(`Changed files: ${changes.values.length}`);
370
+
371
+ // 4. Review each file
372
+ for (const change of changes.values) {
373
+ const path = change.path?.toString;
374
+ if (!path) continue;
375
+
376
+ // Get file diff
377
+ const diff = await client.getPullRequestFileDiff({
378
+ projectKey,
379
+ repositorySlug,
380
+ pullRequestId,
381
+ path
382
+ });
383
+
384
+ // Check for issues and add comments
385
+ diff.diffs[0]?.hunks?.forEach(hunk => {
386
+ hunk.segments.forEach(segment => {
387
+ if (segment.type === 'ADDED') {
388
+ segment.lines.forEach(line => {
389
+ if (line.line?.includes('console.log')) {
390
+ // Add inline comment
391
+ client.addPullRequestComment({
392
+ projectKey,
393
+ repositorySlug,
394
+ pullRequestId,
395
+ text: 'Please remove console.log before merging',
396
+ path,
397
+ line: line.destination!,
398
+ lineType: 'ADDED',
399
+ fileType: 'TO'
400
+ });
401
+ }
402
+ });
403
+ }
404
+ });
405
+ });
406
+ }
407
+
408
+ // 5. Approve or request changes
409
+ await client.updateReviewStatus({
410
+ projectKey,
411
+ repositorySlug,
412
+ pullRequestId,
413
+ status: 'NEEDS_WORK'
414
+ });
415
+
416
+ console.log('Review complete!');
417
+ }
418
+
419
+ reviewPullRequest().catch(console.error);
420
+ ```
421
+
422
+ ## Type Definitions
423
+
424
+ This library exports comprehensive TypeScript types for all API entities:
425
+
426
+ ```typescript
427
+ import type {
428
+ // Common
429
+ PaginatedResponse,
430
+ // User & Project
431
+ RestUser,
432
+ RestProject,
433
+ RestRepository,
434
+ // Pull Request
435
+ RestPullRequest,
436
+ InboxPullRequest,
437
+ RestComment,
438
+ RestChange,
439
+ DiffResponse,
440
+ RestPullRequestActivity,
441
+ // Method parameters
442
+ GetPullRequestParams,
443
+ AddPullRequestCommentParams,
444
+ UpdateReviewStatusParams,
445
+ // ... and many more
446
+ } from 'bitbucket-data-center-client';
447
+ ```
448
+
449
+ See [types.ts](./src/types.ts) for the complete list of exported types.
450
+
451
+ ## API Documentation
452
+
453
+ This library is based on the official Bitbucket Server REST API. See `BitbucketServerSwagger.json` in this package for the complete API specification.
454
+
455
+ ## Error Handling
456
+
457
+ The client throws axios errors for failed requests:
458
+
459
+ ```typescript
460
+ try {
461
+ const pr = await client.getPullRequest({
462
+ projectKey: 'PROJ',
463
+ repositorySlug: 'my-repo',
464
+ pullRequestId: 999
465
+ });
466
+ } catch (error) {
467
+ if (axios.isAxiosError(error)) {
468
+ console.error('API Error:', error.response?.data);
469
+ }
470
+ }
471
+ ```
472
+
473
+ ## Requirements
474
+
475
+ - Node.js >= 18.0.0
476
+ - Bitbucket Server/Data Center 7.0+
477
+
478
+ ## License
479
+
480
+ MIT
481
+
482
+ ## Contributing
483
+
484
+ Contributions are welcome! Please open an issue or submit a pull request.
485
+
486
+ ## Support
487
+
488
+ For issues and questions:
489
+ - GitHub Issues: [your-repo-url]
490
+ - Documentation: See inline JSDoc comments in the source code
@@ -0,0 +1,21 @@
1
+ import type { AddPullRequestCommentParams, AddPullRequestCommentReactionParams, BitbucketClientConfig, ChangesResponse, DeletePullRequestCommentParams, DiffResponse, GetAllUsersParams, GetInboxPullRequestsParams, GetPullRequestActivitiesParams, GetPullRequestChangesParams, GetPullRequestDiffParams, GetPullRequestFileDiffParams, GetPullRequestParams, GetUserProfileParams, InboxPullRequest, ListProjectsParams, ListRepositoriesParams, PaginatedResponse, RemovePullRequestCommentReactionParams, RepositoriesResponse, RestComment, RestProject, RestPullRequest, RestPullRequestActivityApiResponse, RestPullRequestParticipant, RestUser, RestUserReaction, UpdateReviewStatusParams } from './types.js';
2
+ export declare class BitbucketClient {
3
+ private client;
4
+ constructor(config: BitbucketClientConfig);
5
+ getUserProfile(params: GetUserProfileParams): Promise<RestUser>;
6
+ getAllUsers(params?: GetAllUsersParams): Promise<PaginatedResponse<RestUser>>;
7
+ listProjects(params?: ListProjectsParams): Promise<PaginatedResponse<RestProject>>;
8
+ listRepositories(params: ListRepositoriesParams): Promise<RepositoriesResponse>;
9
+ getInboxPullRequests(params?: GetInboxPullRequestsParams): Promise<PaginatedResponse<InboxPullRequest>>;
10
+ getPullRequest(params: GetPullRequestParams): Promise<RestPullRequest>;
11
+ getPullRequestChanges(params: GetPullRequestChangesParams): Promise<ChangesResponse>;
12
+ getPullRequestFileDiff(params: GetPullRequestFileDiffParams): Promise<DiffResponse>;
13
+ getPullRequestDiff(params: GetPullRequestDiffParams): Promise<string | DiffResponse>;
14
+ getPullRequestActivities(params: GetPullRequestActivitiesParams): Promise<PaginatedResponse<RestPullRequestActivityApiResponse>>;
15
+ addPullRequestComment(params: AddPullRequestCommentParams): Promise<RestComment>;
16
+ deletePullRequestComment(params: DeletePullRequestCommentParams): Promise<void>;
17
+ updateReviewStatus(params: UpdateReviewStatusParams): Promise<RestPullRequestParticipant>;
18
+ addPullRequestCommentReaction(params: AddPullRequestCommentReactionParams): Promise<RestUserReaction>;
19
+ removePullRequestCommentReaction(params: RemovePullRequestCommentReactionParams): Promise<void>;
20
+ }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C,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,YAAY,CAAC;IAgBnF,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC;IAgCpF,wBAAwB,CAC5B,MAAM,EAAE,8BAA8B,GACrC,OAAO,CAAC,iBAAiB,CAAC,kCAAkC,CAAC,CAAC;IAY3D,qBAAqB,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC;IA2BhF,wBAAwB,CAAC,MAAM,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IAc/E,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAiBzF,6BAA6B,CAAC,MAAM,EAAE,mCAAmC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAiBrG,gCAAgC,CAAC,MAAM,EAAE,sCAAsC,GAAG,OAAO,CAAC,IAAI,CAAC;CAWtG"}
package/dist/client.js ADDED
@@ -0,0 +1,121 @@
1
+ import axios from 'axios';
2
+ export class BitbucketClient {
3
+ client;
4
+ constructor(config) {
5
+ const { token, baseUrl, axiosConfig = {} } = config;
6
+ this.client = axios.create({
7
+ ...axiosConfig,
8
+ baseURL: `${baseUrl}/rest/api/latest`,
9
+ headers: {
10
+ ...axiosConfig.headers,
11
+ Authorization: `Bearer ${token}`,
12
+ 'Content-Type': 'application/json',
13
+ },
14
+ });
15
+ }
16
+ async getUserProfile(params) {
17
+ const response = await this.client.get(`/users/${params.username}`);
18
+ return response.data;
19
+ }
20
+ async getAllUsers(params) {
21
+ const response = await this.client.get('/users', {
22
+ params: params?.filter ? { filter: params.filter } : {},
23
+ });
24
+ return response.data;
25
+ }
26
+ async listProjects(params) {
27
+ const response = await this.client.get('/projects', {
28
+ params,
29
+ });
30
+ return response.data;
31
+ }
32
+ async listRepositories(params) {
33
+ const response = await this.client.get(`/projects/${params.projectKey}/repos`);
34
+ return response.data;
35
+ }
36
+ async getInboxPullRequests(params) {
37
+ const response = await this.client.get('/inbox/pull-requests', { params });
38
+ return response.data;
39
+ }
40
+ async getPullRequest(params) {
41
+ const { projectKey, repositorySlug, pullRequestId } = params;
42
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}`);
43
+ return response.data;
44
+ }
45
+ async getPullRequestChanges(params) {
46
+ const { projectKey, repositorySlug, pullRequestId, limit } = params;
47
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/changes`, { params: limit ? { limit } : {} });
48
+ return response.data;
49
+ }
50
+ async getPullRequestFileDiff(params) {
51
+ const { projectKey, repositorySlug, pullRequestId, path, contextLines } = params;
52
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/diff/${path}`, { params: contextLines ? { contextLines } : {} });
53
+ return response.data;
54
+ }
55
+ async getPullRequestDiff(params) {
56
+ const { projectKey, repositorySlug, pullRequestId, path, sinceId, untilId, contextLines, whitespace, format = 'text', } = params;
57
+ const queryParams = {};
58
+ if (sinceId)
59
+ queryParams['sinceId'] = sinceId;
60
+ if (untilId)
61
+ queryParams['untilId'] = untilId;
62
+ if (contextLines !== undefined)
63
+ queryParams['contextLines'] = contextLines;
64
+ if (whitespace)
65
+ queryParams['whitespace'] = whitespace;
66
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/diff/${path || ''}`, {
67
+ params: queryParams,
68
+ headers: { Accept: format === 'text' ? 'text/plain' : 'application/json' },
69
+ });
70
+ return response.data;
71
+ }
72
+ async getPullRequestActivities(params) {
73
+ const { projectKey, repositorySlug, pullRequestId, ...queryParams } = params;
74
+ const response = await this.client.get(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/activities`, { params: queryParams });
75
+ return response.data;
76
+ }
77
+ async addPullRequestComment(params) {
78
+ const { projectKey, repositorySlug, pullRequestId, text, parentId, path, line, lineType, fileType } = params;
79
+ const body = { text };
80
+ if (parentId)
81
+ body.parent = { id: parentId };
82
+ if (path) {
83
+ body.anchor = {
84
+ path,
85
+ diffType: 'EFFECTIVE',
86
+ ...(line !== undefined && { line }),
87
+ ...(lineType && { lineType }),
88
+ ...(fileType && { fileType }),
89
+ };
90
+ }
91
+ const response = await this.client.post(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments`, body);
92
+ return response.data;
93
+ }
94
+ async deletePullRequestComment(params) {
95
+ const { projectKey, repositorySlug, pullRequestId, commentId, version } = params;
96
+ await this.client.delete(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}`, {
97
+ params: { version },
98
+ });
99
+ }
100
+ async updateReviewStatus(params) {
101
+ const { projectKey, repositorySlug, pullRequestId, status } = params;
102
+ const propertiesResponse = await this.client.get('/application-properties');
103
+ const userSlug = propertiesResponse.headers['x-ausername'];
104
+ const response = await this.client.put(`/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/participants/${userSlug}`, { status });
105
+ return response.data;
106
+ }
107
+ async addPullRequestCommentReaction(params) {
108
+ const { projectKey, repositorySlug, pullRequestId, commentId, emoticon } = params;
109
+ const response = await this.client.put(`/comment-likes/latest/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}/reactions/${emoticon}`, {}, {
110
+ baseURL: this.client.defaults.baseURL?.replace('/rest/api/latest', '/rest'),
111
+ });
112
+ return response.data;
113
+ }
114
+ async removePullRequestCommentReaction(params) {
115
+ const { projectKey, repositorySlug, pullRequestId, commentId, emoticon } = params;
116
+ await this.client.delete(`/comment-likes/latest/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments/${commentId}/reactions/${emoticon}`, {
117
+ baseURL: this.client.defaults.baseURL?.replace('/rest/api/latest', '/rest'),
118
+ });
119
+ }
120
+ }
121
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
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M,CAAC,MAAM,CACtB,kCAAkC,UAAU,UAAU,cAAc,kBAAkB,aAAa,aAAa,SAAS,cAAc,QAAQ,EAAE,EACjJ;YACE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,kBAAkB,EAAE,OAAO,CAAC;SAC5E,CACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from './client.js';
2
+ export type * from './types.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,mBAAmB,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './client.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}