azdo-cli 0.19.0-feature-038-pr-update.708 → 0.19.0-feature-039-pr-abandon.713

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 +117 -5
  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
  `);
@@ -4655,6 +4667,98 @@ function createPrUpdateCommand() {
4655
4667
  });
4656
4668
  return command;
4657
4669
  }
4670
+ var PR_STATUS_CHANGES = {
4671
+ abandon: {
4672
+ target: "abandoned",
4673
+ search: "active",
4674
+ verb: "abandoned",
4675
+ applied: "Abandoned",
4676
+ refusal: "abandoned"
4677
+ },
4678
+ reactivate: {
4679
+ target: "active",
4680
+ search: "abandoned",
4681
+ verb: "active",
4682
+ applied: "Reactivated",
4683
+ refusal: "reactivated"
4684
+ }
4685
+ };
4686
+ var COMPLETED_STATUS = "completed";
4687
+ async function runPrStatusChange(options, direction) {
4688
+ const change = PR_STATUS_CHANGES[direction];
4689
+ let context;
4690
+ try {
4691
+ const target = await resolvePullRequestTarget(options, { branchStatus: change.search });
4692
+ if (target === null) {
4693
+ return;
4694
+ }
4695
+ context = target.context;
4696
+ const current = target.pullRequest;
4697
+ if (current.status === COMPLETED_STATUS) {
4698
+ writeError(
4699
+ `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.`
4700
+ );
4701
+ return;
4702
+ }
4703
+ if (current.status === change.target) {
4704
+ const noopResult = {
4705
+ pullRequestId: current.id,
4706
+ title: current.title,
4707
+ status: current.status,
4708
+ previousStatus: current.status,
4709
+ url: current.url,
4710
+ noop: true
4711
+ };
4712
+ if (options.json) {
4713
+ process.stdout.write(`${JSON.stringify(noopResult, null, 2)}
4714
+ `);
4715
+ return;
4716
+ }
4717
+ process.stdout.write(`Pull request #${current.id} is already ${change.verb}; nothing to do.
4718
+ `);
4719
+ return;
4720
+ }
4721
+ const updated = await updatePullRequest(target.context, target.repo, target.pat, current.id, {
4722
+ status: change.target
4723
+ });
4724
+ const result = {
4725
+ pullRequestId: updated.id,
4726
+ title: updated.title,
4727
+ status: updated.status,
4728
+ previousStatus: current.status,
4729
+ url: updated.url,
4730
+ noop: false
4731
+ };
4732
+ if (options.json) {
4733
+ process.stdout.write(`${JSON.stringify(result, null, 2)}
4734
+ `);
4735
+ return;
4736
+ }
4737
+ process.stdout.write(`${change.applied} pull request #${updated.id} (${updated.title}).
4738
+ ${updated.url ?? "\u2014"}
4739
+ `);
4740
+ } catch (err) {
4741
+ handlePrCommandError(err, context, "write");
4742
+ }
4743
+ }
4744
+ function createPrAbandonCommand() {
4745
+ const command = new Command12("abandon");
4746
+ withCommonPrOptions(configureUnwrappedHelp(command)).alias("close").description(
4747
+ '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.'
4748
+ ).option("--pr-number <N>", PR_NUMBER_HELP).option("--json", "output JSON").action(async (_options, command2) => {
4749
+ await runPrStatusChange(mergedPrOptions(command2), "abandon");
4750
+ });
4751
+ return command;
4752
+ }
4753
+ function createPrReactivateCommand() {
4754
+ const command = new Command12("reactivate");
4755
+ withCommonPrOptions(configureUnwrappedHelp(command)).description(
4756
+ "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."
4757
+ ).option("--pr-number <N>", PR_NUMBER_HELP_ABANDONED).option("--json", "output JSON").action(async (_options, command2) => {
4758
+ await runPrStatusChange(mergedPrOptions(command2), "reactivate");
4759
+ });
4760
+ return command;
4761
+ }
4658
4762
  function createPrCommentsCommand() {
4659
4763
  const command = new Command12("comments");
4660
4764
  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,7 +4874,7 @@ function createPrCommentsCommand() {
4770
4874
  command.addCommand(createPrCommentsEditCommand());
4771
4875
  return command;
4772
4876
  }
4773
- async function resolvePullRequestTarget(options) {
4877
+ async function resolvePullRequestTarget(options, { branchStatus = "active" } = {}) {
4774
4878
  validateOrgProjectPair(options);
4775
4879
  let explicitPrId = null;
4776
4880
  if (options.prNumber !== void 0) {
@@ -4794,14 +4898,20 @@ async function resolvePullRequestTarget(options) {
4794
4898
  }
4795
4899
  } else {
4796
4900
  const pullRequests = await listPullRequests(resolved.context, resolved.repo, resolved.pat, resolved.branch, {
4797
- status: "active"
4901
+ status: branchStatus
4798
4902
  });
4903
+ const abandoned = branchStatus === "abandoned";
4799
4904
  if (pullRequests.length === 0) {
4800
- writeContractError(autoDetectZeroMatch(resolved.branch));
4905
+ writeContractError(
4906
+ abandoned ? abandonedAutoDetectZeroMatch(resolved.branch) : autoDetectZeroMatch(resolved.branch)
4907
+ );
4801
4908
  return null;
4802
4909
  }
4803
4910
  if (pullRequests.length > 1) {
4804
- writeContractError(autoDetectMultiMatch(resolved.branch, pullRequests.map((pr) => pr.id)));
4911
+ const ids = pullRequests.map((pr) => pr.id);
4912
+ writeContractError(
4913
+ abandoned ? abandonedAutoDetectMultiMatch(resolved.branch, ids) : autoDetectMultiMatch(resolved.branch, ids)
4914
+ );
4805
4915
  return null;
4806
4916
  }
4807
4917
  pullRequest = pullRequests[0];
@@ -5435,6 +5545,8 @@ function createPrCommand() {
5435
5545
  command.addCommand(createPrStatusCommand());
5436
5546
  command.addCommand(createPrOpenCommand());
5437
5547
  command.addCommand(createPrUpdateCommand());
5548
+ command.addCommand(createPrAbandonCommand());
5549
+ command.addCommand(createPrReactivateCommand());
5438
5550
  command.addCommand(createPrCommentsCommand());
5439
5551
  command.addCommand(createPrCommentResolveCommand());
5440
5552
  command.addCommand(createPrCommentReopenCommand());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.19.0-feature-038-pr-update.708",
3
+ "version": "0.19.0-feature-039-pr-abandon.713",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {