Skip to content

Commit b4ab525

Browse files
committed
fix(comments): ensure filePath has leading slash for inline comments
Without a leading / in filePath, Azure DevOps does not set changeTrackingId on the thread. This causes the web UI to show 'This file no longer exists in the latest pull request changes' even though the file exists. Verified against real Azure DevOps API: - Without leading /: changeTrackingId is MISSING - With leading /: changeTrackingId is set correctly Added ensure_leading_slash/1 helper to normalize user input.
1 parent dd65ce7 commit b4ab525

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/ado_cli/cli/pull_requests.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,9 @@ defmodule AdoCli.CLI.PullRequests do
11871187
get_in(change, ["item", "path"]) || change["originalPath"] || change["path"] || "?"
11881188
end
11891189

1190+
defp ensure_leading_slash("/" <> _ = path), do: path
1191+
defp ensure_leading_slash(path), do: "/#{path}"
1192+
11901193
defp change_type(change) do
11911194
# Azure DevOps can return changeType as string ("add") or integer (1).
11921195
# Normalize to integer first, then map to display string.
@@ -2100,6 +2103,10 @@ defmodule AdoCli.CLI.PullRequests do
21002103

21012104
path = "/#{project}/_apis/git/repositories/#{repo_id}/pullrequests/#{pr_id}/threads"
21022105

2106+
# Azure DevOps requires filePath with a leading /. Without it,
2107+
# changeTrackingId is missing and the web UI shows "file no longer exists".
2108+
canonical_path = ensure_leading_slash(file_path)
2109+
21032110
body = %{
21042111
"comments" => [
21052112
%{
@@ -2110,15 +2117,15 @@ defmodule AdoCli.CLI.PullRequests do
21102117
],
21112118
"status" => status,
21122119
"threadContext" => %{
2113-
"filePath" => file_path,
2120+
"filePath" => canonical_path,
21142121
"rightFileStart" => %{"line" => line, "offset" => 1},
21152122
"rightFileEnd" => %{"line" => line, "offset" => 2}
21162123
}
21172124
}
21182125

21192126
case Client.post(path, body) do
21202127
{:ok, result} ->
2121-
render_add_result(result, "Comment added to #{file_path}:#{line}.", json?)
2128+
render_add_result(result, "Comment added to #{canonical_path}:#{line}.", json?)
21222129

21232130
{:error, reason} ->
21242131
bail(reason, parsed)

test/ado_cli/cli/pull_requests_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ defmodule AdoCli.CLI.PullRequestsTest do
10211021
],
10221022
"status" => "active",
10231023
"threadContext" => %{
1024-
"filePath" => "src/foo.ex",
1024+
"filePath" => "/src/foo.ex",
10251025
"rightFileStart" => %{"line" => 42, "offset" => 1},
10261026
"rightFileEnd" => %{"line" => 42, "offset" => 2}
10271027
}

0 commit comments

Comments
 (0)