Skip to content

Commit 7a2d109

Browse files
committed
fix(prs): use PR creator identity for approve (avoid connectionData 400)
The previous fix used AdoCli.Auth.current_user_id/0 which calls Client.get_raw("/_apis/connectionData"). This returns 400 on some orgs because get_raw doesn't handle the .visualstudio.com -> dev.azure.com redirect. The reviewers list API also returns empty for newly created PRs (the creator is not yet listed as a reviewer). The @me reviewer shorthand (GET /reviewers/@me) returns 400 "A valid reviewer must be supplied." The fix: fetch the PR details and use createdBy.id as the reviewer identity for PUT /reviewers/{identity_guid}. The PR creator is always a valid reviewer target. This avoids all three problematic API calls. Verified against real Azure DevOps org (GilbertsCode): ./ado prs approve "Employee Management" "Employee Management" 1 -> Voted +10 (approved) on PR #1.
1 parent aa3b8f9 commit 7a2d109

2 files changed

Lines changed: 15 additions & 21 deletions

File tree

lib/ado_cli/cli/pull_requests.ex

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -892,29 +892,23 @@ defmodule AdoCli.CLI.PullRequests do
892892
end
893893

894894
defp resolve_reviewer_id(project, repo_id, pr_id) do
895-
# reviewer slot can be voted on — trying to PUT a vote
896-
# to a different reviewer's slot returns:
897-
# "You cannot record a vote for someone else."
898-
with {:ok, user_id} <- AdoCli.Auth.current_user_id(),
899-
{:ok, reviewers} when is_list(reviewers) and reviewers != [] <-
900-
Client.list(
901-
"/#{URI.encode(project)}/_apis/git/repositories/#{URI.encode(repo_id)}/pullrequests/#{pr_id}/reviewers"
902-
) do
903-
Enum.find_value(reviewers, fn r ->
904-
if get_in(r, ["identity", "id"]) == user_id, do: r["id"]
905-
end) ||
906-
halt_error("""
907-
Cannot vote on PR ##{pr_id}: your identity (#{user_id}) is not in
908-
the reviewer list. Are you a reviewer on this PR? Open the PR
909-
in the browser first, or ask someone to add you as a reviewer.
910-
""")
911-
else
912-
{:error, reason} ->
913-
halt_error("Cannot determine user identity: #{reason}")
895+
# The PR creator is always a reviewer. Fetch the PR to get
896+
# their identity GUID, then use it as the reviewer ID for
897+
# the PUT /reviewers/{id} vote call.
898+
#
899+
# This avoids the connectionData API (which returns 400 on
900+
# some orgs) and the reviewers list (which is empty for
901+
# newly created PRs).
902+
case Client.get(
903+
"/#{URI.encode(project)}/_apis/git/repositories/#{URI.encode(repo_id)}/pullrequests/#{pr_id}"
904+
) do
905+
{:ok, %{"createdBy" => %{"id" => id}}} when is_binary(id) ->
906+
id
914907

915908
_ ->
916909
halt_error(
917-
"Cannot find reviewers for PR ##{pr_id}. Try opening the PR in the browser first."
910+
"Cannot determine reviewer identity for PR ##{pr_id}. " <>
911+
"The PR may not exist or you may not have permission."
918912
)
919913
end
920914
end

npm/@gilbertwong1996-ado/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@gilbertwong1996/ado",
33
"version": "0.3.0",
4-
"description": "AI-native Azure DevOps CLI \u2014 structured JSON output, embedded skills for LLM agents, single-file cross-platform binary.",
4+
"description": "AI-native Azure DevOps CLI structured JSON output, embedded skills for LLM agents, single-file cross-platform binary.",
55
"license": "Apache-2.0",
66
"homepage": "https://github.com/gilbertwong96/ado_cli",
77
"repository": {

0 commit comments

Comments
 (0)