azdo-cli 0.19.0-develop.710 → 0.19.0-develop.717

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 (3) hide show
  1. package/README.md +7 -1
  2. package/dist/index.js +208 -51
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -15,7 +15,7 @@ Azure DevOps CLI focused on work item read/write workflows.
15
15
  - Attach a local file to a work item, or remove a named attachment (`add-attachment`, `delete-attachment`)
16
16
  - Read/write rich-text fields as markdown (`get-md-field`, `set-md-field`)
17
17
  - Download images embedded in rich-text fields, optionally resized for LLM use (`get-item`/`get-md-field` `--download-images`, `--resize-images`)
18
- - Check branch pull request status, open PRs to `develop` (optionally pre-filled from a repository-defined template), update an existing PR's title or description (`pr update`), list PR comment threads for any PR (`--pr-number`), resolve/reopen threads, link/unlink work items, and add/remove required or optional reviewers — all from the CLI (`pr`)
18
+ - Check branch pull request status, open PRs to `develop` (optionally pre-filled from a repository-defined template), update an existing PR's title or description (`pr update`), abandon or reactivate one (`pr abandon` / `pr reactivate`), list PR comment threads for any PR (`--pr-number`), resolve/reopen threads, link/unlink work items, and add/remove required or optional reviewers — all from the CLI (`pr`)
19
19
  - Feed long PR titles, descriptions and comment bodies from a file or a pipe instead of the shell (`--title-file`, `--description-file`, `--file`; `-` reads standard input)
20
20
  - Persist org/project/default fields in local config (`config`)
21
21
  - List all fields of a work item (`list-fields`)
@@ -102,6 +102,12 @@ cat body.md | azdo pr edit --pr-number 64 --description-file - # "edit" is an
102
102
  azdo pr update --pr-number 64 --title "A real title" --json # { pullRequestId, title, description, url, noop, updatedFields }
103
103
  # Re-running with the values it already has writes nothing and reports "noop": true.
104
104
 
105
+ # Abandon a PR you opened by mistake — reversible, never prompts, nothing is deleted
106
+ azdo pr abandon --pr-number 64 # "close" is an alias; it does NOT complete/merge the PR
107
+ azdo pr reactivate --pr-number 64 # bring it back; --pr-number-less lookup searches abandoned PRs
108
+ azdo pr abandon --pr-number 64 --json # { pullRequestId, title, status, previousStatus, url, noop }
109
+ # Already abandoned? noop, exit 0, no write. Already completed? exit 1, no write.
110
+
105
111
  # Link/unlink a work item, add/remove reviewers
106
112
  azdo pr work-items link 1234 --pr-number 64
107
113
  azdo pr work-items unlink 1234 --pr-number 64
package/dist/index.js CHANGED
@@ -4105,7 +4105,12 @@ function parsePositivePrNumber(raw) {
4105
4105
  const n = Number.parseInt(raw, 10);
4106
4106
  return Number.isFinite(n) && n > 0 ? n : null;
4107
4107
  }
4108
- var PR_NUMBER_HELP = "target the pull request with this numeric id, instead of the current branch's PR. When omitted, the CLI auto-detects the pull request whose source branch equals refs/heads/<current branch> in the Azure DevOps repository identified by the origin remote; if zero or more than one open PR matches, the command fails with a message naming the searched branch.";
4108
+ function prNumberHelp(branchStatus = "active") {
4109
+ const matched = branchStatus === "abandoned" ? "abandoned" : "open";
4110
+ return `target the pull request with this numeric id, instead of the current branch's PR. When omitted, the CLI auto-detects the pull request whose source branch equals refs/heads/<current branch> in the Azure DevOps repository identified by the origin remote; if zero or more than one ${matched} PR matches, the command fails with a message naming the searched branch.`;
4111
+ }
4112
+ var PR_NUMBER_HELP = prNumberHelp();
4113
+ var PR_NUMBER_HELP_ABANDONED = prNumberHelp("abandoned");
4109
4114
  var PR_REPO_HELP = 'Azure DevOps repository name; defaults to the repository of the git "origin" remote';
4110
4115
  function configureUnwrappedHelp(command) {
4111
4116
  return command.configureHelp({ helpWidth: 1e3 });
@@ -4123,6 +4128,13 @@ function autoDetectMultiMatch(branch, ids) {
4123
4128
  const idList = ids.map((id) => `#${id}`).join(", ");
4124
4129
  return `Multiple open pull requests match branch ${branch}: ${idList}. Re-run with --pr-number to choose.`;
4125
4130
  }
4131
+ function abandonedAutoDetectZeroMatch(branch) {
4132
+ return `No abandoned pull request matches branch ${branch}. Pass --pr-number to target a specific PR.`;
4133
+ }
4134
+ function abandonedAutoDetectMultiMatch(branch, ids) {
4135
+ const idList = ids.map((id) => `#${id}`).join(", ");
4136
+ return `Multiple abandoned pull requests match branch ${branch}: ${idList}. Re-run with --pr-number to choose.`;
4137
+ }
4126
4138
  function writeContractError(line) {
4127
4139
  process.stderr.write(`${line}
4128
4140
  `);
@@ -4595,11 +4607,14 @@ async function runPrUpdate(options) {
4595
4607
  }
4596
4608
  let context;
4597
4609
  try {
4598
- const target = await resolvePullRequestTarget(options);
4610
+ const target = await resolvePullRequestTarget(options, {
4611
+ onContextResolved: (resolved) => {
4612
+ context = resolved;
4613
+ }
4614
+ });
4599
4615
  if (target === null) {
4600
4616
  return;
4601
4617
  }
4602
- context = target.context;
4603
4618
  const current = target.pullRequest;
4604
4619
  const { fields, updatedFields, requestedFields } = diffRequestedFields(requested, current);
4605
4620
  if (updatedFields.length === 0) {
@@ -4655,6 +4670,102 @@ function createPrUpdateCommand() {
4655
4670
  });
4656
4671
  return command;
4657
4672
  }
4673
+ var PR_STATUS_CHANGES = {
4674
+ abandon: {
4675
+ target: "abandoned",
4676
+ search: "active",
4677
+ verb: "abandoned",
4678
+ applied: "Abandoned",
4679
+ refusal: "abandoned"
4680
+ },
4681
+ reactivate: {
4682
+ target: "active",
4683
+ search: "abandoned",
4684
+ verb: "active",
4685
+ applied: "Reactivated",
4686
+ refusal: "reactivated"
4687
+ }
4688
+ };
4689
+ var COMPLETED_STATUS = "completed";
4690
+ async function runPrStatusChange(options, direction) {
4691
+ const change = PR_STATUS_CHANGES[direction];
4692
+ let context;
4693
+ try {
4694
+ const target = await resolvePullRequestTarget(options, {
4695
+ branchStatus: change.search,
4696
+ onContextResolved: (resolved) => {
4697
+ context = resolved;
4698
+ }
4699
+ });
4700
+ if (target === null) {
4701
+ return;
4702
+ }
4703
+ const current = target.pullRequest;
4704
+ if (current.status === COMPLETED_STATUS) {
4705
+ writeError(
4706
+ `Pull request #${current.id} is completed and cannot be ${change.refusal}. A completed pull request is final; revert it with a new pull request instead.`
4707
+ );
4708
+ return;
4709
+ }
4710
+ if (current.status === change.target) {
4711
+ const noopResult = {
4712
+ pullRequestId: current.id,
4713
+ title: current.title,
4714
+ status: current.status,
4715
+ previousStatus: current.status,
4716
+ url: current.url,
4717
+ noop: true
4718
+ };
4719
+ if (options.json) {
4720
+ process.stdout.write(`${JSON.stringify(noopResult, null, 2)}
4721
+ `);
4722
+ return;
4723
+ }
4724
+ process.stdout.write(`Pull request #${current.id} is already ${change.verb}; nothing to do.
4725
+ `);
4726
+ return;
4727
+ }
4728
+ const updated = await updatePullRequest(target.context, target.repo, target.pat, current.id, {
4729
+ status: change.target
4730
+ });
4731
+ const result = {
4732
+ pullRequestId: updated.id,
4733
+ title: updated.title,
4734
+ status: updated.status,
4735
+ previousStatus: current.status,
4736
+ url: updated.url,
4737
+ noop: false
4738
+ };
4739
+ if (options.json) {
4740
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
4741
+ `);
4742
+ return;
4743
+ }
4744
+ process.stdout.write(`${change.applied} pull request #${updated.id} (${updated.title}).
4745
+ ${updated.url ?? "\u2014"}
4746
+ `);
4747
+ } catch (err) {
4748
+ handlePrCommandError(err, context, "write");
4749
+ }
4750
+ }
4751
+ function createPrAbandonCommand() {
4752
+ const command = new Command12("abandon");
4753
+ withCommonPrOptions(configureUnwrappedHelp(command)).alias("close").description(
4754
+ 'Abandon a pull request (status: abandoned) \u2014 reversible with "azdo pr reactivate". This does NOT complete or merge the pull request; nothing is deleted and no confirmation is asked.'
4755
+ ).option("--pr-number <N>", PR_NUMBER_HELP).option("--json", "output JSON").action(async (_options, command2) => {
4756
+ await runPrStatusChange(mergedPrOptions(command2), "abandon");
4757
+ });
4758
+ return command;
4759
+ }
4760
+ function createPrReactivateCommand() {
4761
+ const command = new Command12("reactivate");
4762
+ withCommonPrOptions(configureUnwrappedHelp(command)).description(
4763
+ "Reactivate an abandoned pull request (status: active). When --pr-number is omitted the current branch's single ABANDONED pull request is used, not the active one."
4764
+ ).option("--pr-number <N>", PR_NUMBER_HELP_ABANDONED).option("--json", "output JSON").action(async (_options, command2) => {
4765
+ await runPrStatusChange(mergedPrOptions(command2), "reactivate");
4766
+ });
4767
+ return command;
4768
+ }
4658
4769
  function createPrCommentsCommand() {
4659
4770
  const command = new Command12("comments");
4660
4771
  withCommonPrOptions(configureUnwrappedHelp(command)).description("List pull request comment threads for the current branch").option("--pr-number <N>", PR_NUMBER_HELP).option("--hide-resolved", "hide threads whose status is resolved / won't fix / closed / by design").option("--exclude-resolved", "alias of --hide-resolved: exclude resolved / won't fix / closed / by design threads").option("--code-related-only", "show only threads anchored to a file/line; omit general discussion threads").option("--exclude-system", "omit Azure DevOps system comments (branch updates, reviewer votes, build events)").option("--max-chars <N>", "truncate each comment body to N characters (0 = no limit, the default)").option("--thread <id>", "show only the thread with this numeric id; fails when the pull request has no such thread").option("--contains <text>", "show only threads holding a comment that contains this literal, case-sensitive substring (matched before --max-chars truncates)").option("--json", "output JSON").action(async (options) => {
@@ -4770,52 +4881,75 @@ function createPrCommentsCommand() {
4770
4881
  command.addCommand(createPrCommentsEditCommand());
4771
4882
  return command;
4772
4883
  }
4773
- async function resolvePullRequestTarget(options) {
4774
- validateOrgProjectPair(options);
4775
- let explicitPrId = null;
4776
- if (options.prNumber !== void 0) {
4777
- explicitPrId = parsePositivePrNumber(options.prNumber);
4778
- if (explicitPrId === null) {
4779
- writeError(`Invalid --pr-number "${options.prNumber}"; expected a positive integer.`);
4780
- return null;
4781
- }
4884
+ function parseTargetPrNumber(options) {
4885
+ if (options.prNumber === void 0) {
4886
+ return "none";
4782
4887
  }
4783
- const resolved = await resolvePrCommandContext(options, { requireBranch: explicitPrId === null });
4784
- let pullRequest;
4785
- if (explicitPrId !== null) {
4786
- try {
4787
- pullRequest = await getPullRequestById(resolved.context, resolved.repo, resolved.pat, explicitPrId);
4788
- } catch (err) {
4789
- if (err instanceof Error && err.message.startsWith("NOT_FOUND")) {
4790
- writeError(`Pull request #${explicitPrId} not found in ${resolved.context.org}/${resolved.context.project}/${resolved.repo}.`, EXIT_NOT_FOUND);
4791
- return null;
4792
- }
4793
- throw err;
4794
- }
4795
- } else {
4796
- const pullRequests = await listPullRequests(resolved.context, resolved.repo, resolved.pat, resolved.branch, {
4797
- status: "active"
4798
- });
4799
- if (pullRequests.length === 0) {
4800
- writeContractError(autoDetectZeroMatch(resolved.branch));
4801
- return null;
4802
- }
4803
- if (pullRequests.length > 1) {
4804
- writeContractError(autoDetectMultiMatch(resolved.branch, pullRequests.map((pr) => pr.id)));
4888
+ const parsed = parsePositivePrNumber(options.prNumber);
4889
+ if (parsed === null) {
4890
+ writeError(`Invalid --pr-number "${options.prNumber}"; expected a positive integer.`);
4891
+ return "invalid";
4892
+ }
4893
+ return parsed;
4894
+ }
4895
+ async function fetchTargetById(resolved, prId) {
4896
+ try {
4897
+ return await getPullRequestById(resolved.context, resolved.repo, resolved.pat, prId);
4898
+ } catch (err) {
4899
+ if (err instanceof Error && err.message.startsWith("NOT_FOUND")) {
4900
+ writeError(
4901
+ `Pull request #${prId} not found in ${resolved.context.org}/${resolved.context.project}/${resolved.repo}.`,
4902
+ EXIT_NOT_FOUND
4903
+ );
4805
4904
  return null;
4806
4905
  }
4807
- pullRequest = pullRequests[0];
4906
+ throw err;
4907
+ }
4908
+ }
4909
+ async function findBranchPullRequest(resolved, branch, branchStatus) {
4910
+ const pullRequests = await listPullRequests(resolved.context, resolved.repo, resolved.pat, branch, {
4911
+ status: branchStatus
4912
+ });
4913
+ const abandoned = branchStatus === "abandoned";
4914
+ if (pullRequests.length === 0) {
4915
+ writeContractError(abandoned ? abandonedAutoDetectZeroMatch(branch) : autoDetectZeroMatch(branch));
4916
+ return null;
4917
+ }
4918
+ if (pullRequests.length > 1) {
4919
+ const ids = pullRequests.map((pr) => pr.id);
4920
+ writeContractError(
4921
+ abandoned ? abandonedAutoDetectMultiMatch(branch, ids) : autoDetectMultiMatch(branch, ids)
4922
+ );
4923
+ return null;
4924
+ }
4925
+ return pullRequests[0];
4926
+ }
4927
+ async function resolvePullRequestTarget(options, {
4928
+ branchStatus = "active",
4929
+ onContextResolved
4930
+ } = {}) {
4931
+ validateOrgProjectPair(options);
4932
+ const explicitPrId = parseTargetPrNumber(options);
4933
+ if (explicitPrId === "invalid") {
4934
+ return null;
4935
+ }
4936
+ const byBranch = explicitPrId === "none";
4937
+ const resolved = await resolvePrCommandContext(options, { requireBranch: byBranch });
4938
+ onContextResolved?.(resolved.context);
4939
+ const pullRequest = byBranch ? await findBranchPullRequest(resolved, resolved.branch, branchStatus) : await fetchTargetById(resolved, explicitPrId);
4940
+ if (pullRequest === null) {
4941
+ return null;
4808
4942
  }
4809
4943
  return { context: resolved.context, repo: resolved.repo, pat: resolved.pat, pullRequest };
4810
4944
  }
4811
- async function resolveThreadTarget(threadIdRaw, options) {
4945
+ async function resolveThreadTarget(threadIdRaw, options, { onContextResolved } = {}) {
4812
4946
  const threadId = parsePositivePrNumber(threadIdRaw);
4813
4947
  if (threadId === null) {
4814
4948
  validateOrgProjectPair(options);
4815
4949
  writeError(`Invalid thread id "${threadIdRaw}"; expected a positive integer.`);
4816
4950
  return null;
4817
4951
  }
4818
- const target = await resolvePullRequestTarget(options);
4952
+ const target = await resolvePullRequestTarget(options, { onContextResolved });
4819
4953
  if (target === null) {
4820
4954
  return null;
4821
4955
  }
@@ -4824,11 +4958,14 @@ async function resolveThreadTarget(threadIdRaw, options) {
4824
4958
  async function runThreadStateChange(threadIdRaw, options, direction) {
4825
4959
  let context;
4826
4960
  try {
4827
- const target = await resolveThreadTarget(threadIdRaw, options);
4961
+ const target = await resolveThreadTarget(threadIdRaw, options, {
4962
+ onContextResolved: (resolved) => {
4963
+ context = resolved;
4964
+ }
4965
+ });
4828
4966
  if (target === null) {
4829
4967
  return;
4830
4968
  }
4831
- context = target.context;
4832
4969
  const threads = await getPullRequestThreads(target.context, target.repo, target.pat, target.pullRequest.id);
4833
4970
  const thread = threads.find((t) => t.id === target.threadId);
4834
4971
  if (!thread) {
@@ -4901,11 +5038,14 @@ async function runCommentReply(threadIdRaw, text, options) {
4901
5038
  if (trimmedText === null) {
4902
5039
  return;
4903
5040
  }
4904
- const target = await resolveThreadTarget(threadIdRaw, options);
5041
+ const target = await resolveThreadTarget(threadIdRaw, options, {
5042
+ onContextResolved: (resolved) => {
5043
+ context = resolved;
5044
+ }
5045
+ });
4905
5046
  if (target === null) {
4906
5047
  return;
4907
5048
  }
4908
- context = target.context;
4909
5049
  const threads = await getPullRequestThreads(target.context, target.repo, target.pat, target.pullRequest.id);
4910
5050
  const thread = threads.find((t) => t.id === target.threadId);
4911
5051
  if (!thread) {
@@ -4979,11 +5119,14 @@ async function runCommentAdd(text, options) {
4979
5119
  }
4980
5120
  status2 = match;
4981
5121
  }
4982
- const target = await resolvePullRequestTarget(options);
5122
+ const target = await resolvePullRequestTarget(options, {
5123
+ onContextResolved: (resolved) => {
5124
+ context = resolved;
5125
+ }
5126
+ });
4983
5127
  if (target === null) {
4984
5128
  return;
4985
5129
  }
4986
- context = target.context;
4987
5130
  if (options.dryRun === true) {
4988
5131
  const dryResult = {
4989
5132
  pullRequestId: target.pullRequest.id,
@@ -5122,11 +5265,14 @@ async function runCommentEdit(threadIdRaw, text, options) {
5122
5265
  return;
5123
5266
  }
5124
5267
  }
5125
- const target = await resolveThreadTarget(threadIdRaw, options);
5268
+ const target = await resolveThreadTarget(threadIdRaw, options, {
5269
+ onContextResolved: (resolved) => {
5270
+ context = resolved;
5271
+ }
5272
+ });
5126
5273
  if (target === null) {
5127
5274
  return;
5128
5275
  }
5129
- context = target.context;
5130
5276
  const thread = await fetchThreadForEdit(target);
5131
5277
  if (thread === null) {
5132
5278
  return;
@@ -5261,11 +5407,14 @@ async function runWorkItemLinkChange(workItemIdRaw, options, direction) {
5261
5407
  writeError(`Invalid work item id "${workItemIdRaw}"; expected a positive integer.`);
5262
5408
  return;
5263
5409
  }
5264
- const target = await resolvePullRequestTarget(options);
5410
+ const target = await resolvePullRequestTarget(options, {
5411
+ onContextResolved: (resolved) => {
5412
+ context = resolved;
5413
+ }
5414
+ });
5265
5415
  if (target === null) {
5266
5416
  return;
5267
5417
  }
5268
- context = target.context;
5269
5418
  let outcome;
5270
5419
  try {
5271
5420
  outcome = direction === "link" ? await linkWorkItemToPullRequest(target.context, target.repo, target.pat, target.pullRequest.id, workItemId) : await unlinkWorkItemFromPullRequest(target.context, target.repo, target.pat, target.pullRequest.id, workItemId);
@@ -5320,11 +5469,14 @@ function createPrWorkItemsCommand() {
5320
5469
  async function runReviewerAdd(reviewer, options) {
5321
5470
  let context;
5322
5471
  try {
5323
- const target = await resolvePullRequestTarget(options);
5472
+ const target = await resolvePullRequestTarget(options, {
5473
+ onContextResolved: (resolved) => {
5474
+ context = resolved;
5475
+ }
5476
+ });
5324
5477
  if (target === null) {
5325
5478
  return;
5326
5479
  }
5327
- context = target.context;
5328
5480
  let identity;
5329
5481
  try {
5330
5482
  identity = await resolveReviewerIdentity(target.context.org, target.pat, reviewer);
@@ -5375,11 +5527,14 @@ async function runReviewerAdd(reviewer, options) {
5375
5527
  async function runReviewerRemove(reviewer, options) {
5376
5528
  let context;
5377
5529
  try {
5378
- const target = await resolvePullRequestTarget(options);
5530
+ const target = await resolvePullRequestTarget(options, {
5531
+ onContextResolved: (resolved) => {
5532
+ context = resolved;
5533
+ }
5534
+ });
5379
5535
  if (target === null) {
5380
5536
  return;
5381
5537
  }
5382
- context = target.context;
5383
5538
  let identity;
5384
5539
  try {
5385
5540
  identity = await resolveReviewerIdentity(target.context.org, target.pat, reviewer);
@@ -5435,6 +5590,8 @@ function createPrCommand() {
5435
5590
  command.addCommand(createPrStatusCommand());
5436
5591
  command.addCommand(createPrOpenCommand());
5437
5592
  command.addCommand(createPrUpdateCommand());
5593
+ command.addCommand(createPrAbandonCommand());
5594
+ command.addCommand(createPrReactivateCommand());
5438
5595
  command.addCommand(createPrCommentsCommand());
5439
5596
  command.addCommand(createPrCommentResolveCommand());
5440
5597
  command.addCommand(createPrCommentReopenCommand());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.19.0-develop.710",
3
+ "version": "0.19.0-develop.717",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {