buddy-workbench 0.1.7 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buddy-workbench",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -375,4 +375,59 @@ router.get('/review-prs', async (req, res) => {
375
375
  }
376
376
  });
377
377
 
378
+ router.post('/comment', async (req, res) => {
379
+ const { projectKey, repositorySlug, pullRequestId, filePath, line, commentText } = req.body || {};
380
+ if (!projectKey || !repositorySlug || !pullRequestId || !commentText) {
381
+ return res.status(400).json({ error: 'Missing required parameters.' });
382
+ }
383
+
384
+ const host = getBitbucketHost();
385
+ const settings = readSettings();
386
+ const token = settings.bitbucketAccessToken;
387
+
388
+ if (!host || !token) {
389
+ return res.status(400).json({ error: 'Bitbucket Access Token or Host not configured.' });
390
+ }
391
+
392
+ const url = `https://${host}/rest/api/1.0/projects/${projectKey}/repos/${repositorySlug}/pull-requests/${pullRequestId}/comments`;
393
+ const headers = {
394
+ 'Content-Type': 'application/json',
395
+ 'Accept': 'application/json',
396
+ 'Authorization': `Bearer ${token}`
397
+ };
398
+
399
+ const payload = {
400
+ text: commentText
401
+ };
402
+
403
+ if (filePath && line) {
404
+ payload.anchor = {
405
+ line: parseInt(line, 10),
406
+ lineType: 'ADDED',
407
+ fileType: 'TO',
408
+ path: filePath
409
+ };
410
+ }
411
+
412
+ try {
413
+ const response = await fetch(url, {
414
+ method: 'POST',
415
+ headers,
416
+ body: JSON.stringify(payload)
417
+ });
418
+
419
+ if (!response.ok) {
420
+ const errJson = await response.json().catch(() => ({}));
421
+ return res.status(response.status).json({
422
+ error: errJson.errors?.[0]?.message || errJson.message || `Bitbucket API error: ${response.statusText}`
423
+ });
424
+ }
425
+
426
+ const data = await response.json();
427
+ res.json({ success: true, data });
428
+ } catch (error) {
429
+ res.status(500).json({ error: error.message });
430
+ }
431
+ });
432
+
378
433
  export default router;