@symbo.ls/sdk 2.34.35 → 3.1.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.
Files changed (187) hide show
  1. package/README.md +2 -143
  2. package/dist/cjs/config/environment.js +30 -98
  3. package/dist/cjs/index.js +24 -144
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +305 -738
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +1185 -0
  8. package/dist/cjs/services/CoreService.js +1751 -0
  9. package/dist/cjs/services/SocketIOService.js +307 -0
  10. package/dist/cjs/services/SocketService.js +161 -0
  11. package/dist/cjs/services/SymstoryService.js +571 -0
  12. package/dist/cjs/services/index.js +16 -64
  13. package/dist/cjs/utils/TokenManager.js +30 -78
  14. package/dist/cjs/utils/basedQuerys.js +181 -0
  15. package/dist/cjs/utils/services.js +103 -301
  16. package/dist/cjs/utils/symstoryClient.js +259 -0
  17. package/dist/cjs/utils/validation.js +3 -0
  18. package/dist/esm/config/environment.js +30 -98
  19. package/dist/esm/index.js +8797 -49416
  20. package/dist/esm/services/AIService.js +185 -0
  21. package/dist/esm/services/AuthService.js +386 -1493
  22. package/dist/esm/services/BaseService.js +6 -757
  23. package/dist/esm/services/BasedService.js +5278 -0
  24. package/dist/esm/services/CoreService.js +2264 -0
  25. package/dist/esm/services/SocketIOService.js +470 -0
  26. package/dist/esm/services/SocketService.js +191 -0
  27. package/dist/esm/services/SymstoryService.js +7041 -0
  28. package/dist/esm/services/index.js +8690 -49015
  29. package/dist/esm/utils/TokenManager.js +30 -78
  30. package/dist/esm/utils/basedQuerys.js +163 -0
  31. package/dist/esm/utils/services.js +103 -301
  32. package/dist/esm/utils/symstoryClient.js +370 -0
  33. package/dist/esm/utils/validation.js +7 -4
  34. package/dist/node/config/environment.js +30 -98
  35. package/dist/node/index.js +32 -175
  36. package/dist/node/services/AIService.js +136 -0
  37. package/dist/node/services/AuthService.js +310 -742
  38. package/dist/node/services/BaseService.js +6 -148
  39. package/dist/node/services/BasedService.js +1156 -0
  40. package/dist/node/services/CoreService.js +1722 -0
  41. package/dist/node/services/SocketIOService.js +278 -0
  42. package/dist/node/services/SocketService.js +142 -0
  43. package/dist/node/services/SymstoryService.js +542 -0
  44. package/dist/node/services/index.js +16 -64
  45. package/dist/node/utils/TokenManager.js +30 -78
  46. package/dist/node/utils/basedQuerys.js +162 -0
  47. package/dist/node/utils/services.js +103 -301
  48. package/dist/node/utils/symstoryClient.js +230 -0
  49. package/dist/node/utils/validation.js +3 -0
  50. package/package.json +16 -35
  51. package/src/config/environment.js +28 -99
  52. package/src/index.js +36 -181
  53. package/src/services/AIService.js +150 -0
  54. package/src/services/AuthService.js +328 -874
  55. package/src/services/BaseService.js +6 -166
  56. package/src/services/BasedService.js +1301 -0
  57. package/src/services/CoreService.js +1943 -0
  58. package/src/services/SocketIOService.js +334 -0
  59. package/src/services/SocketService.js +168 -0
  60. package/src/services/SymstoryService.js +649 -0
  61. package/src/services/index.js +13 -80
  62. package/src/utils/TokenManager.js +33 -88
  63. package/src/utils/basedQuerys.js +164 -0
  64. package/src/utils/services.js +107 -326
  65. package/src/utils/symstoryClient.js +252 -0
  66. package/src/utils/validation.js +3 -0
  67. package/dist/cjs/services/AdminService.js +0 -351
  68. package/dist/cjs/services/BranchService.js +0 -484
  69. package/dist/cjs/services/CollabService.js +0 -743
  70. package/dist/cjs/services/DnsService.js +0 -340
  71. package/dist/cjs/services/FeatureFlagService.js +0 -175
  72. package/dist/cjs/services/FileService.js +0 -201
  73. package/dist/cjs/services/IntegrationService.js +0 -538
  74. package/dist/cjs/services/MetricsService.js +0 -62
  75. package/dist/cjs/services/PaymentService.js +0 -271
  76. package/dist/cjs/services/PlanService.js +0 -426
  77. package/dist/cjs/services/ProjectService.js +0 -1207
  78. package/dist/cjs/services/PullRequestService.js +0 -503
  79. package/dist/cjs/services/ScreenshotService.js +0 -304
  80. package/dist/cjs/services/SubscriptionService.js +0 -396
  81. package/dist/cjs/services/TrackingService.js +0 -661
  82. package/dist/cjs/services/WaitlistService.js +0 -148
  83. package/dist/cjs/state/RootStateManager.js +0 -65
  84. package/dist/cjs/state/rootEventBus.js +0 -74
  85. package/dist/cjs/utils/CollabClient.js +0 -223
  86. package/dist/cjs/utils/changePreprocessor.js +0 -199
  87. package/dist/cjs/utils/jsonDiff.js +0 -145
  88. package/dist/cjs/utils/ordering.js +0 -309
  89. package/dist/esm/services/AdminService.js +0 -1132
  90. package/dist/esm/services/BranchService.js +0 -1265
  91. package/dist/esm/services/CollabService.js +0 -26838
  92. package/dist/esm/services/DnsService.js +0 -1121
  93. package/dist/esm/services/FeatureFlagService.js +0 -956
  94. package/dist/esm/services/FileService.js +0 -982
  95. package/dist/esm/services/IntegrationService.js +0 -1319
  96. package/dist/esm/services/MetricsService.js +0 -843
  97. package/dist/esm/services/PaymentService.js +0 -1052
  98. package/dist/esm/services/PlanService.js +0 -1207
  99. package/dist/esm/services/ProjectService.js +0 -2526
  100. package/dist/esm/services/PullRequestService.js +0 -1284
  101. package/dist/esm/services/ScreenshotService.js +0 -1085
  102. package/dist/esm/services/SubscriptionService.js +0 -1177
  103. package/dist/esm/services/TrackingService.js +0 -18343
  104. package/dist/esm/services/WaitlistService.js +0 -929
  105. package/dist/esm/state/RootStateManager.js +0 -90
  106. package/dist/esm/state/rootEventBus.js +0 -56
  107. package/dist/esm/utils/CollabClient.js +0 -18901
  108. package/dist/esm/utils/changePreprocessor.js +0 -542
  109. package/dist/esm/utils/jsonDiff.js +0 -7011
  110. package/dist/esm/utils/ordering.js +0 -291
  111. package/dist/node/services/AdminService.js +0 -332
  112. package/dist/node/services/BranchService.js +0 -465
  113. package/dist/node/services/CollabService.js +0 -724
  114. package/dist/node/services/DnsService.js +0 -321
  115. package/dist/node/services/FeatureFlagService.js +0 -156
  116. package/dist/node/services/FileService.js +0 -182
  117. package/dist/node/services/IntegrationService.js +0 -519
  118. package/dist/node/services/MetricsService.js +0 -43
  119. package/dist/node/services/PaymentService.js +0 -252
  120. package/dist/node/services/PlanService.js +0 -407
  121. package/dist/node/services/ProjectService.js +0 -1188
  122. package/dist/node/services/PullRequestService.js +0 -484
  123. package/dist/node/services/ScreenshotService.js +0 -285
  124. package/dist/node/services/SubscriptionService.js +0 -377
  125. package/dist/node/services/TrackingService.js +0 -632
  126. package/dist/node/services/WaitlistService.js +0 -129
  127. package/dist/node/state/RootStateManager.js +0 -36
  128. package/dist/node/state/rootEventBus.js +0 -55
  129. package/dist/node/utils/CollabClient.js +0 -194
  130. package/dist/node/utils/changePreprocessor.js +0 -180
  131. package/dist/node/utils/jsonDiff.js +0 -116
  132. package/dist/node/utils/ordering.js +0 -290
  133. package/src/services/AdminService.js +0 -374
  134. package/src/services/BranchService.js +0 -536
  135. package/src/services/CollabService.js +0 -900
  136. package/src/services/DnsService.js +0 -366
  137. package/src/services/FeatureFlagService.js +0 -174
  138. package/src/services/FileService.js +0 -213
  139. package/src/services/IntegrationService.js +0 -548
  140. package/src/services/MetricsService.js +0 -40
  141. package/src/services/PaymentService.js +0 -287
  142. package/src/services/PlanService.js +0 -468
  143. package/src/services/ProjectService.js +0 -1366
  144. package/src/services/PullRequestService.js +0 -537
  145. package/src/services/ScreenshotService.js +0 -258
  146. package/src/services/SubscriptionService.js +0 -425
  147. package/src/services/TrackingService.js +0 -853
  148. package/src/services/WaitlistService.js +0 -130
  149. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  150. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  151. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  152. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  153. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  154. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  155. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  156. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  157. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  158. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  159. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  160. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  161. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  162. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  163. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  164. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  165. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  166. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  167. package/src/services/tests/FileService/validateFile.test.js +0 -63
  168. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  169. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  170. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  171. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  172. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  173. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  174. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  175. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  176. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  177. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  178. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  179. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  180. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  181. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  182. package/src/state/RootStateManager.js +0 -76
  183. package/src/state/rootEventBus.js +0 -67
  184. package/src/utils/CollabClient.js +0 -248
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -1,484 +0,0 @@
1
- import { BaseService } from "./BaseService.js";
2
- class PullRequestService extends BaseService {
3
- // ==================== PULL REQUEST METHODS ====================
4
- /**
5
- * Create a new pull request
6
- */
7
- async createPullRequest(projectId, pullRequestData) {
8
- this._requireReady("createPullRequest");
9
- if (!projectId) {
10
- throw new Error("Project ID is required");
11
- }
12
- if (!pullRequestData.source || !pullRequestData.target || !pullRequestData.title) {
13
- throw new Error("Source branch, target branch, and title are required");
14
- }
15
- try {
16
- const response = await this._request(
17
- `/projects/${projectId}/pull-requests`,
18
- {
19
- method: "POST",
20
- body: JSON.stringify(pullRequestData),
21
- methodName: "createPullRequest"
22
- }
23
- );
24
- if (response.success) {
25
- return response.data;
26
- }
27
- throw new Error(response.message);
28
- } catch (error) {
29
- throw new Error(`Failed to create pull request: ${error.message}`, { cause: error });
30
- }
31
- }
32
- /**
33
- * List pull requests for a project with filtering options
34
- */
35
- async listPullRequests(projectId, options = {}) {
36
- this._requireReady("listPullRequests");
37
- if (!projectId) {
38
- throw new Error("Project ID is required");
39
- }
40
- const { status = "open", source, target, page = 1, limit = 20 } = options;
41
- const queryParams = new URLSearchParams({
42
- status,
43
- page: page.toString(),
44
- limit: limit.toString()
45
- });
46
- if (source) {
47
- queryParams.append("source", source);
48
- }
49
- if (target) {
50
- queryParams.append("target", target);
51
- }
52
- try {
53
- const response = await this._request(
54
- `/projects/${projectId}/pull-requests?${queryParams.toString()}`,
55
- {
56
- method: "GET",
57
- methodName: "listPullRequests"
58
- }
59
- );
60
- if (response.success) {
61
- return response.data;
62
- }
63
- throw new Error(response.message);
64
- } catch (error) {
65
- throw new Error(`Failed to list pull requests: ${error.message}`, { cause: error });
66
- }
67
- }
68
- /**
69
- * Get detailed information about a specific pull request
70
- */
71
- async getPullRequest(projectId, prId) {
72
- this._requireReady("getPullRequest");
73
- if (!projectId) {
74
- throw new Error("Project ID is required");
75
- }
76
- if (!prId) {
77
- throw new Error("Pull request ID is required");
78
- }
79
- try {
80
- const response = await this._request(
81
- `/projects/${projectId}/pull-requests/${prId}`,
82
- {
83
- method: "GET",
84
- methodName: "getPullRequest"
85
- }
86
- );
87
- if (response.success) {
88
- return response.data;
89
- }
90
- throw new Error(response.message);
91
- } catch (error) {
92
- throw new Error(`Failed to get pull request: ${error.message}`, { cause: error });
93
- }
94
- }
95
- /**
96
- * Submit a review for a pull request
97
- */
98
- async reviewPullRequest(projectId, prId, reviewData) {
99
- this._requireReady("reviewPullRequest");
100
- if (!projectId) {
101
- throw new Error("Project ID is required");
102
- }
103
- if (!prId) {
104
- throw new Error("Pull request ID is required");
105
- }
106
- const validStatuses = ["approved", "requested_changes", "feedback"];
107
- if (reviewData.status && !validStatuses.includes(reviewData.status)) {
108
- throw new Error(
109
- `Invalid review status. Must be one of: ${validStatuses.join(", ")}`
110
- );
111
- }
112
- try {
113
- const response = await this._request(
114
- `/projects/${projectId}/pull-requests/${prId}/review`,
115
- {
116
- method: "POST",
117
- body: JSON.stringify(reviewData),
118
- methodName: "reviewPullRequest"
119
- }
120
- );
121
- if (response.success) {
122
- return response;
123
- }
124
- throw new Error(response.message);
125
- } catch (error) {
126
- throw new Error(`Failed to review pull request: ${error.message}`, { cause: error });
127
- }
128
- }
129
- /**
130
- * Add a comment to an existing review thread
131
- */
132
- async addPullRequestComment(projectId, prId, commentData) {
133
- this._requireReady("addPullRequestComment");
134
- if (!projectId) {
135
- throw new Error("Project ID is required");
136
- }
137
- if (!prId) {
138
- throw new Error("Pull request ID is required");
139
- }
140
- if (!commentData.value) {
141
- throw new Error("Comment value is required");
142
- }
143
- try {
144
- const response = await this._request(
145
- `/projects/${projectId}/pull-requests/${prId}/comment`,
146
- {
147
- method: "POST",
148
- body: JSON.stringify(commentData),
149
- methodName: "addPullRequestComment"
150
- }
151
- );
152
- if (response.success) {
153
- return response;
154
- }
155
- throw new Error(response.message);
156
- } catch (error) {
157
- throw new Error(`Failed to add pull request comment: ${error.message}`, { cause: error });
158
- }
159
- }
160
- /**
161
- * Merge an approved pull request
162
- */
163
- async mergePullRequest(projectId, prId) {
164
- this._requireReady("mergePullRequest");
165
- if (!projectId) {
166
- throw new Error("Project ID is required");
167
- }
168
- if (!prId) {
169
- throw new Error("Pull request ID is required");
170
- }
171
- try {
172
- const response = await this._request(
173
- `/projects/${projectId}/pull-requests/${prId}/merge`,
174
- {
175
- method: "POST",
176
- methodName: "mergePullRequest"
177
- }
178
- );
179
- if (response.success) {
180
- return response;
181
- }
182
- throw new Error(response.message);
183
- } catch (error) {
184
- if (error.message.includes("conflicts") || error.message.includes("409")) {
185
- throw new Error(`Pull request has merge conflicts: ${error.message}`, { cause: error });
186
- }
187
- throw new Error(`Failed to merge pull request: ${error.message}`, { cause: error });
188
- }
189
- }
190
- /**
191
- * Get the diff/changes for a pull request
192
- */
193
- async getPullRequestDiff(projectId, prId) {
194
- this._requireReady("getPullRequestDiff");
195
- if (!projectId) {
196
- throw new Error("Project ID is required");
197
- }
198
- if (!prId) {
199
- throw new Error("Pull request ID is required");
200
- }
201
- try {
202
- const response = await this._request(
203
- `/projects/${projectId}/pull-requests/${prId}/diff`,
204
- {
205
- method: "GET",
206
- methodName: "getPullRequestDiff"
207
- }
208
- );
209
- if (response.success) {
210
- return response.data;
211
- }
212
- throw new Error(response.message);
213
- } catch (error) {
214
- throw new Error(`Failed to get pull request diff: ${error.message}`, { cause: error });
215
- }
216
- }
217
- // ==================== PULL REQUEST HELPER METHODS ====================
218
- /**
219
- * Helper method to create a pull request with validation
220
- */
221
- async createPullRequestWithValidation(projectId, data) {
222
- const { source, target, title, description, changes } = data;
223
- if (source === target) {
224
- throw new Error("Source and target branches cannot be the same");
225
- }
226
- if (!title || title.trim().length === 0) {
227
- throw new Error("Pull request title cannot be empty");
228
- }
229
- if (title.length > 200) {
230
- throw new Error("Pull request title cannot exceed 200 characters");
231
- }
232
- const pullRequestData = {
233
- source: source.trim(),
234
- target: target.trim(),
235
- title: title.trim(),
236
- ...description && { description: description.trim() },
237
- ...changes && { changes }
238
- };
239
- return await this.createPullRequest(projectId, pullRequestData);
240
- }
241
- /**
242
- * Helper method to approve a pull request
243
- */
244
- async approvePullRequest(projectId, prId, comment = "") {
245
- const reviewData = {
246
- status: "approved",
247
- ...comment && {
248
- threads: [
249
- {
250
- comment,
251
- type: "praise"
252
- }
253
- ]
254
- }
255
- };
256
- return await this.reviewPullRequest(projectId, prId, reviewData);
257
- }
258
- /**
259
- * Helper method to request changes on a pull request
260
- */
261
- async requestPullRequestChanges(projectId, prId, threads = []) {
262
- if (!threads || threads.length === 0) {
263
- throw new Error("Must provide specific feedback when requesting changes");
264
- }
265
- const reviewData = {
266
- status: "requested_changes",
267
- threads
268
- };
269
- return await this.reviewPullRequest(projectId, prId, reviewData);
270
- }
271
- /**
272
- * Helper method to get pull requests by status
273
- */
274
- async getOpenPullRequests(projectId, options = {}) {
275
- return await this.listPullRequests(projectId, {
276
- ...options,
277
- status: "open"
278
- });
279
- }
280
- async getClosedPullRequests(projectId, options = {}) {
281
- return await this.listPullRequests(projectId, {
282
- ...options,
283
- status: "closed"
284
- });
285
- }
286
- async getMergedPullRequests(projectId, options = {}) {
287
- return await this.listPullRequests(projectId, {
288
- ...options,
289
- status: "merged"
290
- });
291
- }
292
- /**
293
- * Helper method to check if a pull request is canMerge
294
- */
295
- async isPullRequestMergeable(projectId, prId) {
296
- var _a;
297
- try {
298
- const prData = await this.getPullRequest(projectId, prId);
299
- return ((_a = prData == null ? void 0 : prData.data) == null ? void 0 : _a.canMerge) || false;
300
- } catch (error) {
301
- throw new Error(
302
- `Failed to check pull request mergeability: ${error.message}`,
303
- { cause: error }
304
- );
305
- }
306
- }
307
- /**
308
- * Helper method to get pull request status summary
309
- */
310
- async getPullRequestStatusSummary(projectId, prId) {
311
- var _a, _b, _c;
312
- try {
313
- const prData = await this.getPullRequest(projectId, prId);
314
- const pr = prData == null ? void 0 : prData.data;
315
- if (!pr) {
316
- throw new Error("Pull request not found");
317
- }
318
- return {
319
- status: pr.status,
320
- reviewStatus: pr.reviewStatus,
321
- canMerge: pr.canMerge,
322
- hasConflicts: !pr.canMerge,
323
- reviewCount: ((_a = pr.reviews) == null ? void 0 : _a.length) || 0,
324
- approvedReviews: ((_b = pr.reviews) == null ? void 0 : _b.filter((r) => r.status === "approved").length) || 0,
325
- changesRequested: ((_c = pr.reviews) == null ? void 0 : _c.filter((r) => r.status === "requested_changes").length) || 0
326
- };
327
- } catch (error) {
328
- throw new Error(
329
- `Failed to get pull request status summary: ${error.message}`,
330
- { cause: error }
331
- );
332
- }
333
- }
334
- /**
335
- * Helper method to validate pull request data
336
- */
337
- validatePullRequestData(data) {
338
- const errors = [];
339
- if (!data.source || typeof data.source !== "string") {
340
- errors.push("Source branch is required and must be a string");
341
- }
342
- if (!data.target || typeof data.target !== "string") {
343
- errors.push("Target branch is required and must be a string");
344
- }
345
- if (data.source === data.target) {
346
- errors.push("Source and target branches cannot be the same");
347
- }
348
- if (!data.title || typeof data.title !== "string") {
349
- errors.push("Title is required and must be a string");
350
- } else if (data.title.trim().length === 0) {
351
- errors.push("Title cannot be empty");
352
- } else if (data.title.length > 200) {
353
- errors.push("Title cannot exceed 200 characters");
354
- }
355
- if (data.description && typeof data.description !== "string") {
356
- errors.push("Description must be a string");
357
- }
358
- return {
359
- isValid: errors.length === 0,
360
- errors
361
- };
362
- }
363
- /**
364
- * Helper method to validate review data
365
- */
366
- validateReviewData(reviewData) {
367
- const errors = [];
368
- const validStatuses = ["approved", "requested_changes", "feedback"];
369
- if (reviewData.status && !validStatuses.includes(reviewData.status)) {
370
- errors.push(`Invalid review status. Must be one of: ${validStatuses.join(", ")}`);
371
- }
372
- if (reviewData.threads && !Array.isArray(reviewData.threads)) {
373
- errors.push("Threads must be an array");
374
- }
375
- if (reviewData.threads) {
376
- reviewData.threads.forEach((thread, index) => {
377
- if (!thread.comment || typeof thread.comment !== "string") {
378
- errors.push(`Thread ${index + 1}: Comment is required and must be a string`);
379
- }
380
- if (thread.type && !["praise", "issue", "suggestion"].includes(thread.type)) {
381
- errors.push(`Thread ${index + 1}: Invalid thread type`);
382
- }
383
- });
384
- }
385
- return {
386
- isValid: errors.length === 0,
387
- errors
388
- };
389
- }
390
- /**
391
- * Helper method to get pull request statistics
392
- */
393
- async getPullRequestStats(projectId, options = {}) {
394
- try {
395
- const { status = "open" } = options;
396
- const pullRequests = await this.listPullRequests(projectId, { status });
397
- const stats = {
398
- total: pullRequests.length,
399
- open: 0,
400
- closed: 0,
401
- merged: 0,
402
- withConflicts: 0,
403
- readyToMerge: 0
404
- };
405
- pullRequests.forEach((pr) => {
406
- if (pr.status === "open") {
407
- stats.open++;
408
- }
409
- if (pr.status === "closed") {
410
- stats.closed++;
411
- }
412
- if (pr.status === "merged") {
413
- stats.merged++;
414
- }
415
- if (pr.hasConflicts) {
416
- stats.withConflicts++;
417
- }
418
- if (pr.canMerge) {
419
- stats.readyToMerge++;
420
- }
421
- });
422
- return stats;
423
- } catch (error) {
424
- throw new Error(`Failed to get pull request stats: ${error.message}`, { cause: error });
425
- }
426
- }
427
- /**
428
- * Helper method to close a pull request
429
- */
430
- async closePullRequest(projectId, prId) {
431
- this._requireReady("closePullRequest");
432
- if (!projectId) {
433
- throw new Error("Project ID is required");
434
- }
435
- if (!prId) {
436
- throw new Error("Pull request ID is required");
437
- }
438
- try {
439
- const response = await this._request(
440
- `/projects/${projectId}/pull-requests/${prId}/close`,
441
- {
442
- method: "POST",
443
- methodName: "closePullRequest"
444
- }
445
- );
446
- if (response.success) {
447
- return response.data;
448
- }
449
- throw new Error(response.message);
450
- } catch (error) {
451
- throw new Error(`Failed to close pull request: ${error.message}`, { cause: error });
452
- }
453
- }
454
- /**
455
- * Helper method to reopen a closed pull request
456
- */
457
- async reopenPullRequest(projectId, prId) {
458
- this._requireReady("reopenPullRequest");
459
- if (!projectId) {
460
- throw new Error("Project ID is required");
461
- }
462
- if (!prId) {
463
- throw new Error("Pull request ID is required");
464
- }
465
- try {
466
- const response = await this._request(
467
- `/projects/${projectId}/pull-requests/${prId}/reopen`,
468
- {
469
- method: "POST",
470
- methodName: "reopenPullRequest"
471
- }
472
- );
473
- if (response.success) {
474
- return response.data;
475
- }
476
- throw new Error(response.message);
477
- } catch (error) {
478
- throw new Error(`Failed to reopen pull request: ${error.message}`, { cause: error });
479
- }
480
- }
481
- }
482
- export {
483
- PullRequestService
484
- };