Skip to content

Commit 70a214a

Browse files
viamusclaude
andcommitted
fix: derive work item ParentId from Hierarchy-Reverse relation
System.Parent field is not consistently populated by the Azure DevOps REST API, causing parentId to come back null even when the work item has a parent. Read the parent ID from the System.LinkTypes.Hierarchy-Reverse relation URL, keeping the System.Parent field read as a fallback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d59a012 commit 70a214a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Viamus.Azure.Devops.Mcp.Server/Services/AzureDevOpsService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,15 @@ private static WorkItemDto MapToDto(WorkItem workItem, bool includeAllFields = f
366366

367367
foreach (var relation in workItem.Relations)
368368
{
369-
if (relation.Rel == "ArtifactLink" && !string.IsNullOrEmpty(relation.Url))
369+
if (relation.Rel == "System.LinkTypes.Hierarchy-Reverse" && !string.IsNullOrEmpty(relation.Url))
370+
{
371+
var lastSlash = relation.Url.LastIndexOf('/');
372+
if (lastSlash >= 0 && int.TryParse(relation.Url[(lastSlash + 1)..], out var parentIdFromRelation))
373+
{
374+
dto = dto with { ParentId = parentIdFromRelation };
375+
}
376+
}
377+
else if (relation.Rel == "ArtifactLink" && !string.IsNullOrEmpty(relation.Url))
370378
{
371379
// Commit URL format: vstfs:///Git/Commit/{projectId}%2F{repoId}%2F{commitId}
372380
// Pull Request URL format: vstfs:///Git/PullRequestId/{projectId}%2F{repoId}%2F{prId}

0 commit comments

Comments
 (0)