azdo-cli 0.5.0-017-pr-comments-threads.238 → 0.5.0-017-pr-comments-threads.242

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 (2) hide show
  1. package/dist/index.js +27 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2340,7 +2340,7 @@ function mapPullRequest(repo, pullRequest) {
2340
2340
  targetRefName: pullRequest.targetRefName,
2341
2341
  status: pullRequest.status,
2342
2342
  createdBy: pullRequest.createdBy?.displayName ?? null,
2343
- url: pullRequest._links.web.href
2343
+ url: pullRequest._links?.web?.href ?? null
2344
2344
  };
2345
2345
  }
2346
2346
  function mapPullRequestCheckName(status) {
@@ -2385,9 +2385,6 @@ function mapComment(comment) {
2385
2385
  };
2386
2386
  }
2387
2387
  function mapThread(thread) {
2388
- if (thread.status !== "active" && thread.status !== "pending") {
2389
- return null;
2390
- }
2391
2388
  const comments = thread.comments.map(mapComment).filter((comment) => comment !== null);
2392
2389
  if (comments.length === 0) {
2393
2390
  return null;
@@ -2399,6 +2396,10 @@ function mapThread(thread) {
2399
2396
  comments
2400
2397
  };
2401
2398
  }
2399
+ var RESOLVED_THREAD_STATUSES = /* @__PURE__ */ new Set(["fixed", "wontFix", "closed", "byDesign"]);
2400
+ function isThreadResolved(status) {
2401
+ return RESOLVED_THREAD_STATUSES.has(status);
2402
+ }
2402
2403
  async function readJsonResponse(response) {
2403
2404
  if (!response.ok) {
2404
2405
  throw new Error(`HTTP_${response.status}`);
@@ -2480,25 +2481,30 @@ function formatBranchName(refName) {
2480
2481
  function writeError(message) {
2481
2482
  process.stderr.write(`Error: ${message}
2482
2483
  `);
2483
- process.exit(1);
2484
+ process.exitCode = 1;
2484
2485
  }
2485
2486
  function handlePrCommandError(err, context, mode = "read") {
2486
2487
  const error = err instanceof Error ? err : new Error(String(err));
2487
2488
  if (error.message === "AUTH_FAILED") {
2488
2489
  const scopeLabel = mode === "write" ? "Code (Read & Write)" : "Code (Read)";
2489
2490
  writeError(`Authentication failed. Check that your PAT is valid and has the "${scopeLabel}" scope.`);
2491
+ return;
2490
2492
  }
2491
2493
  if (error.message === "PERMISSION_DENIED") {
2492
2494
  writeError(`Access denied. Your PAT may lack ${mode} permissions for project "${context?.project}".`);
2495
+ return;
2493
2496
  }
2494
2497
  if (error.message === "NETWORK_ERROR") {
2495
2498
  writeError("Could not connect to Azure DevOps. Check your network connection.");
2499
+ return;
2496
2500
  }
2497
2501
  if (error.message.startsWith("NOT_FOUND")) {
2498
2502
  writeError(`Azure DevOps repository not found in ${context?.org}/${context?.project}.`);
2503
+ return;
2499
2504
  }
2500
2505
  if (error.message.startsWith("HTTP_")) {
2501
2506
  writeError(`Azure DevOps request failed with ${error.message}.`);
2507
+ return;
2502
2508
  }
2503
2509
  writeError(error.message);
2504
2510
  }
@@ -2519,14 +2525,17 @@ function formatPullRequestBlock(pullRequest) {
2519
2525
  return [
2520
2526
  `#${pullRequest.id} [${pullRequest.status}] ${pullRequest.title}`,
2521
2527
  `${formatBranchName(pullRequest.sourceRefName)} -> ${formatBranchName(pullRequest.targetRefName)}`,
2522
- pullRequest.url,
2528
+ pullRequest.url ?? "\u2014",
2523
2529
  ...formatPullRequestChecks(pullRequest.checks)
2524
2530
  ].join("\n");
2525
2531
  }
2532
+ function threadStatusLabel(status) {
2533
+ return isThreadResolved(status) ? "resolved" : status;
2534
+ }
2526
2535
  function formatThreads(prId, title, threads) {
2527
2536
  const lines = [`Active comments for pull request #${prId}: ${title}`];
2528
2537
  for (const thread of threads) {
2529
- lines.push("", `Thread #${thread.id} [${thread.status}] ${thread.threadContext ?? "(general)"}`);
2538
+ lines.push("", `Thread #${thread.id} [${threadStatusLabel(thread.status)}] ${thread.threadContext ?? "(general)"}`);
2530
2539
  for (const comment of thread.comments) {
2531
2540
  lines.push(` ${comment.author ?? "Unknown"}: ${comment.content}`);
2532
2541
  }
@@ -2587,10 +2596,12 @@ function createPrOpenCommand() {
2587
2596
  const title = options.title?.trim();
2588
2597
  if (!title) {
2589
2598
  writeError("--title is required for pull request creation.");
2599
+ return;
2590
2600
  }
2591
2601
  const description = options.description?.trim();
2592
2602
  if (!description) {
2593
2603
  writeError("--description is required for pull request creation.");
2604
+ return;
2594
2605
  }
2595
2606
  let context;
2596
2607
  try {
@@ -2598,6 +2609,7 @@ function createPrOpenCommand() {
2598
2609
  context = resolved.context;
2599
2610
  if (resolved.branch === "develop") {
2600
2611
  writeError("Pull request creation requires a source branch other than develop.");
2612
+ return;
2601
2613
  }
2602
2614
  const result = await openPullRequest(
2603
2615
  resolved.context,
@@ -2614,19 +2626,20 @@ function createPrOpenCommand() {
2614
2626
  }
2615
2627
  if (result.created) {
2616
2628
  process.stdout.write(`Created pull request #${result.pullRequest.id}: ${result.pullRequest.title}
2617
- ${result.pullRequest.url}
2629
+ ${result.pullRequest.url ?? "\u2014"}
2618
2630
  `);
2619
2631
  return;
2620
2632
  }
2621
2633
  process.stdout.write(
2622
2634
  `Active pull request already exists for ${resolved.branch} -> develop: #${result.pullRequest.id}
2623
- ${result.pullRequest.url}
2635
+ ${result.pullRequest.url ?? "\u2014"}
2624
2636
  `
2625
2637
  );
2626
2638
  } catch (err) {
2627
2639
  if (err instanceof Error && err.message.startsWith("AMBIGUOUS_PRS:")) {
2628
2640
  const ids = err.message.replace("AMBIGUOUS_PRS:", "").split(",").map((id) => `#${id}`).join(", ");
2629
2641
  writeError(`Multiple active pull requests already exist for this branch targeting develop: ${ids}. Use pr status to review them.`);
2642
+ return;
2630
2643
  }
2631
2644
  handlePrCommandError(err, context, "write");
2632
2645
  }
@@ -2635,7 +2648,7 @@ ${result.pullRequest.url}
2635
2648
  }
2636
2649
  function createPrCommentsCommand() {
2637
2650
  const command = new Command12("comments");
2638
- command.description("List active pull request comments for the current branch").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project").option("--json", "output JSON").action(async (options) => {
2651
+ command.description("List pull request comment threads for the current branch").option("--org <org>", "Azure DevOps organization").option("--project <project>", "Azure DevOps project").option("--hide-resolved", "hide threads whose status is resolved / won't fix / closed / by design").option("--json", "output JSON").action(async (options) => {
2639
2652
  validateOrgProjectPair(options);
2640
2653
  let context;
2641
2654
  try {
@@ -2646,13 +2659,16 @@ function createPrCommentsCommand() {
2646
2659
  });
2647
2660
  if (pullRequests.length === 0) {
2648
2661
  writeError(`No active pull request found for branch ${resolved.branch}.`);
2662
+ return;
2649
2663
  }
2650
2664
  if (pullRequests.length > 1) {
2651
2665
  const ids = pullRequests.map((pullRequest2) => `#${pullRequest2.id}`).join(", ");
2652
2666
  writeError(`Multiple active pull requests found for branch ${resolved.branch}: ${ids}. Use pr status to review them.`);
2667
+ return;
2653
2668
  }
2654
2669
  const pullRequest = pullRequests[0];
2655
- const threads = await getPullRequestThreads(resolved.context, resolved.repo, resolved.pat, pullRequest.id);
2670
+ const allThreads = await getPullRequestThreads(resolved.context, resolved.repo, resolved.pat, pullRequest.id);
2671
+ const threads = options.hideResolved ? allThreads.filter((thread) => !isThreadResolved(thread.status)) : allThreads;
2656
2672
  const result = { branch: resolved.branch, pullRequest, threads };
2657
2673
  if (options.json) {
2658
2674
  process.stdout.write(`${JSON.stringify(result, null, 2)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.5.0-017-pr-comments-threads.238",
3
+ "version": "0.5.0-017-pr-comments-threads.242",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {