jira-azuredevops-migrator
jira-azuredevops-migrator copied to clipboard
Inline text attachments or pdf file attachments inside description are not working
When you add a file apart from image inside description as inline file. They are not mapping as expected.
And images added in comment are also not mapping with or without space between words
AB#5927
I fixed as given below:
private string[] fileExtensions = { "pdf", "txt" };
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;
//var splitfileName = !string.IsNullOrEmpty(fileName) ? fileName.TakeWhile(x => x != '.').ToString().Split(' ') : null;
char[] spearator = {' ', '.' };
var splitfileName = fileName.Split(spearator, StringSplitOptions.RemoveEmptyEntries).Where(x => NotGuid(x)).ToArray();
var joinedFileName = string.Join("+", splitfileName, 0, splitfileName.Count()-1);
var extension = splitfileName[splitfileName.Count()-1];
if (textField.Contains(fileName) || (splitfileName != null && textField.Contains(joinedFileName)))
{
var tfsAtt = IdentifyAttachment(att, wi);
if (tfsAtt != null && !fileExtensions.Contains(extension.ToLower()))
{
string imageSrcPattern = $"src.*?=.*?\"([^\"])(?=.*{att.AttOriginId}).*?\"";
textField = Regex.Replace(textField, imageSrcPattern, $"src=\"{tfsAtt.Uri.AbsoluteUri}\"");
isUpdated = true;
}
else if (fileExtensions.Contains(extension.ToLower()))
{
string imageSrcPattern = $"href.*?=.*?\"([^\"])(?=.*{att.AttOriginId}).*?\"";
textField = Regex.Replace(textField, imageSrcPattern, $"href=\"{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;
}
}
private bool NotGuid(string fileName) { var guidMatch = Regex.Match(fileName, @"({){0,1}[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(}){0,1}", RegexOptions.IgnoreCase); return !guidMatch.Success; }
I'm having a similar issue, but the proposed solution didn't work for me.
In Jira I have a comment with an inline attachment. In the history I see that the comment and the attachment are added at the same time.
In DevOps I have also a comment, but the link of the attachment doesn't work. The attachment is however correctly added to the list attachment. Just the link in the comment doesn't work.
If I run the source code, I see that the revision of the comment is before the upload of the attachment. The method CorrectComment
is therefor run to late.
This all results in the error:
Attachment '{att.ToString()}' referenced in text but is missing from work item {wiItem.OriginId}/{wi.Id}.
We had the same issue with zip files and other less common file types. I added the suggested code changes locally and it worked. So thanks to @mahidharguggilam. Not sure what "Under observation" means, but it would be nice to have the fix included from the beginning.
I faced this issue as well. And based on @mahidharguggilam's way to fix, I have fixed it for myself, too, slightly simpler: https://github.com/tung-nt-niteco/jira-azuredevops-migrator/commit/bb758f853e33b2f934897c509ac6bc79eaab63c2 and https://github.com/tung-nt-niteco/jira-azuredevops-migrator/commit/85826373390136f74187d03bc1a9d94d94b56b2a
Have same issue
Should be fixed by: https://github.com/solidify/jira-azuredevops-migrator/pull/489