Skip to content

feat(review): add Azure DevOps PR review support - #414

Closed
jmbp1999 wants to merge 1 commit into
backnotprop:mainfrom
jmbp1999:feat/azure-devops-pr-review
Closed

jmbp1999 wants to merge 1 commit into
backnotprop:mainfrom
jmbp1999:feat/azure-devops-pr-review

Conversation

@jmbp1999

Copy link
Copy Markdown

Summary

Adds full Azure DevOps pull request review as a first-class platform alongside GitHub and GitLab, following the same provider pattern used throughout the codebase.

What's included

New platform support

  • Parse dev.azure.com and legacy visualstudio.com PR URLs
  • URL-encoded project/repo names decoded automatically
  • Case-insensitive pullrequest segment

Diff fetching (two-stage fallback)

  1. Try git diff <baseSha>..<headSha> locally (fast path — works when repo is cloned)
  2. Fall back to ADO REST API: fetches changed file list from PR iteration changes, then fetches old/new file content at base/head SHAs and builds a git-style unified diff using a self-contained LCS diff engine (no external deps)

Review submission

  • General comments → POST /threads via ADO REST API
  • Inline file comments → POST /threads with threadContext position info
  • Approve → PUT /reviewers/{userId} with vote: 10; user ID resolved from _apis/connectionData
  • All az rest calls use --resource 499b84ac-1321-427f-aa17-267ca6975798 to get an ADO-scoped token (ARM token is rejected by ADO APIs)

UI

  • New AzureDevOpsIcon component added
  • Review destination button shows ADO icon for ADO PRs
  • Fixed missing @plannotator/ui/config export in packages/ui/package.json (the config/ directory existed but was not declared in exports)

New types

  • AzureDevOpsPRRef, AzureDevOpsPRMetadata in pr-provider.ts
  • Platform union extended: github | gitlab | azuredevops
  • All label helpers (getPlatformLabel, getMRLabel, getMRNumberLabel, getDisplayRepo, getCliName, getCliInstallUrl) updated
  • New types re-exported from packages/server/pr.ts

Tests

22 new tests in packages/shared/pr-azuredevops.test.ts:

  • URL parsing: dev.azure.com, visualstudio.com, URL-encoded names, case-insensitive, large IDs
  • GitHub/GitLab regression coverage
  • buildFilePatch: add/edit/delete/rename, identical files, no trailing newline, hunk merging, hunk splitting
  • computeHunks: identical, add, delete, replace

All 170 tests pass (148 pre-existing + 22 new).

Prerequisites (user-side)

brew install azure-cli
az extension add --name azure-devops
az login

Usage

/plannotator-review https://dev.azure.com/{org}/{project}/_git/{repo}/pullrequest/{id}
/plannotator-review https://{org}.visualstudio.com/{project}/_git/{repo}/pullrequest/{id}

Test plan

  • URL parser covers both ADO URL formats, encoded names, large IDs
  • GitHub and GitLab URL parsing unaffected (regression tests)
  • Diff engine: add/edit/delete/rename files, hunk merging/splitting
  • 170/170 tests pass
  • Full build succeeds (review editor + hook + binary)
  • Tested against real ADO PR (zuelligpharmadevops/eZRxPlus — PR #155857): metadata fetch, diff via API, comment posting, approval vote

Adds full Azure DevOps pull request review support as a first-class
platform alongside GitHub and GitLab, following the same provider
pattern (pr-provider.ts dispatch → platform-specific implementation).

## What's new

### URL parsing
- `https://dev.azure.com/{org}/{project}/_git/{repo}/pullrequest/{id}`
- `https://{org}.visualstudio.com/{project}/_git/{repo}/pullrequest/{id}` (legacy)
- URL-encoded project/repo names decoded automatically
- Case-insensitive `pullrequest` segment

### PR diff strategy
1. Try `git diff <baseSha>..<headSha>` locally (fast path)
2. If commits not present, try `git fetch origin` + retry
3. Fall back to ADO REST API: iterates PR change entries, fetches
   old/new file content at the base/head SHAs, builds a git-style
   unified diff using a self-contained LCS diff engine (no deps)

### Submitting reviews
- General comments → `POST /threads` via ADO REST API
- Inline file comments → `POST /threads` with `threadContext` position
- Approve → `PUT /reviewers/{userId}` with `vote: 10`
- User ID resolved from `_apis/connectionData` at submit time

### Auth
- All `az rest` calls use `--resource 499b84ac-1321-427f-aa17-267ca6975798`
  to acquire an ADO-scoped token (ARM token rejected by ADO APIs)
- `az repos pr show` uses ADO extension which handles auth natively

### UI
- `AzureDevOpsIcon` component added to `packages/ui/components/`
- Review destination button shows the ADO icon when reviewing ADO PRs
- `@plannotator/ui/config` export added to `packages/ui/package.json`
  (was missing — `config/index.ts` existed but was undeclared)

### Types
- `AzureDevOpsPRRef` and `AzureDevOpsPRMetadata` added to `pr-provider.ts`
- `Platform` union extended to `"github" | "gitlab" | "azuredevops"`
- All label helpers (`getPlatformLabel`, `getMRLabel`, etc.) updated
- New types re-exported from `packages/server/pr.ts`

### Tests (22 new)
- Full URL parsing coverage (dev.azure.com, visualstudio.com, encoded,
  case-insensitive, large IDs)
- GitHub/GitLab regression tests
- `buildFilePatch`: add/edit/delete/rename, empty diff, no-trailing-newline,
  hunk merging for nearby changes, hunk splitting for distant changes
- `computeHunks`: identical, add, delete, replace

## Prerequisites (user-side)
```bash
brew install azure-cli
az extension add --name azure-devops
az login
```

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@backnotprop

Copy link
Copy Markdown
Owner

TLDR: Closing in favor of an extension seam rather than per-platform core patches. AI-assisted note. Thanks @jmbp1999 for the complete implementation. The direction we want is the provider override discussed in #671, so third-party platforms (Azure DevOps, Bitbucket, Gitea) plug in without each needing a merged core patch. Azure DevOps is the natural first consumer of that seam, and this PR is a solid reference for it. If you want to help shape the seam, #671 is the thread.

backnotprop added a commit that referenced this pull request Nov 4, 2026
…f a tree stack's chain only

Thread name (owner, q-49bd0699 A): pullHandoffThreadName gives
"Review #869: <title>" (GitLab !61; a stack "Review #412 to #414: …"),
one line, cut to the thread-name limit. Hand sends it as the person's
thread_name and starts the thread without it when another open thread
has it; + New agent opens compose with it in the chip. The message body
is unchanged.

Review fixes: a tree stack hands over only the chain up to the layer the
view is open on (handoffStack), so its list, step 1's "to" branch and
"in list order" stay true. One open-layer helper (openLayers,
isOpenPull); the opening and step 2 are built once for a PR and a stack.
Tests for the names, the prefill, a taken name, a tree, a GHE host; the
server fixture's ask_line is the current step 1.

Co-Authored-By: Claude <[email protected]>
backnotprop added a commit that referenced this pull request Nov 4, 2026
…be handed on its own

Review findings 2 to 5 on #2606 (finding 1, the name on a re-handed PR, waits on the owner).

- Tree stacks: the thread name says "#412 to #414" only for a straight run of the
  stack's open layers; a chain that skips one reads "Review #412, #414: <title>"
  (numbers cut with ", …" past 60 characters, the name within 120).
- handoffStack(stack, links, thread) replaces the target parameter the UI never
  used: the layers no thread has yet (or the ones a thread has, for Hand again).
  After #412 and #414 go to one thread, the stack view says "No agent yet for
  #413" and hands #413 on its own, a single PR's hand-off against #412's branch.
- layerVerdictLink: in a tree a layer falls back only to the thread of a layer
  above it on its own chain, so #413's verdict never goes to #412/#414's thread.
- One open-PR rule: core exports inboxPullIsOpen; the stacks, the server's pull
  review route, postRules, PullReview's layer strip and PullsPage use it. The
  thread name is computed once per hand-off line.
- Titles are cut between graphemes (Intl.Segmenter), never inside a ZWJ
  sequence or a flag; a title of only zero-width characters is "(no title)".

Message text is byte-identical for every non-tree variant (before/after compare).
backnotprop added a commit that referenced this pull request Nov 4, 2026
The owner has not approved "No agent yet for #413" or a second "Ask for"
line, and is redesigning this page, so this PR adds no visible text or
layout. The stack view renders as on main: "No agent yet" only with no
agent, one hand-off line (Ask for, or Hand again for). A tree's sibling
left out of the agent's chain shows what main shows for any linked stack.

Kept (invisible): tree verdict routing (#413 has no agent until it is
linked), "Review #412, #414: …" for a chain that skips a layer, the shared
inboxPullIsOpen, grapheme-safe titles. handoffStack is unchanged; the page
uses it for the first hand-off (the chain to the top) and Hand again.

Tests: the DOM test for the sibling's own hand-off line is gone; a DOM test
now checks the page hands a tree's chain to its top and then shows no
extra line. Routing and name tests stay.
backnotprop added a commit that referenced this pull request Nov 4, 2026
Main's pull hand-off work (isOpenPull/openLayers, handoffStack for a tree) meets
this branch's topology.ts. stackLink, layerVerdictLink, startLayer and nextLayer
stay in topology.ts; main's tree hand-off helpers stay in model.ts.
layerVerdictLink keeps both rules: a layer takes the thread of a linked layer on
its own line, and in a fork never a thread that has an open layer on another
branch (a thread handed #412 and #414 is not #413's). pullHandoffThreadName
takes the links, as stackTitle now does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants