public async Task <IEnumerable <JsonPatchOperation> > Process(IMigrationContext migrationContext, IBatchMigrationContext batchContext, WorkItem sourceWorkItem, WorkItem targetWorkItem) { IList <JsonPatchOperation> jsonPatchOperations = new List <JsonPatchOperation>(); if (sourceWorkItem.Relations == null) { return(jsonPatchOperations); } IList <WorkItemRelation> sourceWorkItemLinkRelations = GetWorkItemLinkRelations(migrationContext, sourceWorkItem.Relations); if (sourceWorkItemLinkRelations.Any()) { foreach (WorkItemRelation sourceWorkItemLinkRelation in sourceWorkItemLinkRelations) { int linkedSourceId = ClientHelpers.GetWorkItemIdFromApiEndpoint(sourceWorkItemLinkRelation.Url); int targetWorkItemId = targetWorkItem.Id.Value; int linkedTargetId; if (!migrationContext.SourceToTargetIds.TryGetValue(linkedSourceId, out linkedTargetId)) { continue; } string comment = MigrationHelpers.GetCommentFromAttributes(sourceWorkItemLinkRelation); WorkItemLink newWorkItemLink = new WorkItemLink(linkedTargetId, sourceWorkItemLinkRelation.Rel, false, false, comment, 0); JsonPatchOperation workItemLinkAddOperation = MigrationHelpers.GetWorkItemLinkAddOperation(migrationContext, newWorkItemLink); jsonPatchOperations.Add(workItemLinkAddOperation); } } return(jsonPatchOperations); }
public static JsonPatchOperation GetWorkItemLinkAddOperation(IMigrationContext migrationContext, WorkItemLink workItemLink) { string workItemEndpoint = ClientHelpers.GetWorkItemApiEndpoint(migrationContext.Config.TargetConnection.Account, workItemLink.Id); JsonPatchOperation jsonPatchOperation = new JsonPatchOperation(); jsonPatchOperation.Operation = Operation.Add; jsonPatchOperation.Path = $"/{Constants.Relations}/-"; jsonPatchOperation.Value = new { rel = workItemLink.ReferenceName, url = workItemEndpoint, attributes = new { comment = workItemLink.Comment } }; return(jsonPatchOperation); }