private bool CorrectDescription(WorkItem wi, WiItem wiItem, WiRevision rev) { string currentDescription = wi.Type.Name == "Bug" ? wi.Fields["Microsoft.VSTS.TCM.ReproSteps"].Value.ToString() : wi.Description; if (string.IsNullOrWhiteSpace(currentDescription)) { return(false); } bool descUpdated = false; foreach (var att in wiItem.Revisions.SelectMany(r => r.Attachments.Where(a => a.Change == ReferenceChangeType.Added))) { if (currentDescription.Contains(att.FilePath)) { var tfsAtt = IdentifyAttachment(att, wi); descUpdated = true; if (tfsAtt != null) { currentDescription = currentDescription.Replace(att.FilePath, tfsAtt.Uri.AbsoluteUri); descUpdated = true; } else { Logger.Log(LogLevel.Warning, $"Attachment '{att.ToString()}' referenced in description but is missing from work item {wiItem.OriginId}/{wi.Id}."); } } } if (descUpdated) { DateTime changedDate; if (wiItem.Revisions.Count > rev.Index + 1) { changedDate = RevisionUtility.NextValidDeltaRev(rev.Time, wiItem.Revisions[rev.Index + 1].Time); } else { changedDate = RevisionUtility.NextValidDeltaRev(rev.Time); } wi.Fields["System.ChangedDate"].Value = changedDate; wi.Fields["System.ChangedBy"].Value = rev.Author; if (wi.Type.Name == "Bug") { wi.Fields["Microsoft.VSTS.TCM.ReproSteps"].Value = currentDescription; } else { wi.Fields["System.Description"].Value = currentDescription; } } return(descUpdated); }
private void EnsureIncreasingTimes(List <RevisionReference> actionPlan) { for (int i = 1; i < actionPlan.Count; i++) { var prev = actionPlan[i - 1]; var current = actionPlan[i]; DateTime?nextTime = null; if (i + 1 < actionPlan.Count) { var next = actionPlan[i + 1]; if (next.Time > prev.Time) { nextTime = next.Time; } } if (prev.Time >= current.Time) { current.Time = RevisionUtility.NextValidDeltaRev(prev.Time, nextTime); } } }
private void CorrectImagePath(WorkItem wi, WiItem wiItem, WiRevision rev, ref string textField, ref bool isUpdated) { foreach (var att in wiItem.Revisions.SelectMany(r => r.Attachments.Where(a => a.Change == ReferenceChangeType.Added))) { var fileName = att.FilePath.Split('\\')?.Last() ?? string.Empty; if (textField.Contains(fileName)) { var tfsAtt = IdentifyAttachment(att, wi); if (tfsAtt != null) { string imageSrcPattern = $"src.*?=.*?\"([^\"])(?=.*{att.AttOriginId}).*?\""; textField = Regex.Replace(textField, imageSrcPattern, $"src=\"{tfsAtt.Uri.AbsoluteUri}\""); isUpdated = true; } else { Logger.Log(LogLevel.Warning, $"Attachment '{att.ToString()}' referenced in text but is missing from work item {wiItem.OriginId}/{wi.Id}."); } } } if (isUpdated) { DateTime changedDate; if (wiItem.Revisions.Count > rev.Index + 1) { changedDate = RevisionUtility.NextValidDeltaRev(rev.Time, wiItem.Revisions[rev.Index + 1].Time); } else { changedDate = RevisionUtility.NextValidDeltaRev(rev.Time); } wi.Fields[WiFieldReference.ChangedDate].Value = changedDate; wi.Fields[WiFieldReference.ChangedBy].Value = rev.Author; } }