jira-azuredevops-migrator icon indicating copy to clipboard operation
jira-azuredevops-migrator copied to clipboard

Inline text attachments or pdf file attachments inside description are not working

Open mahidharguggilam opened this issue 4 years ago • 5 comments

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

mahidharguggilam avatar Apr 30 '20 11:04 mahidharguggilam

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; }

mahidharguggilam avatar Apr 30 '20 14:04 mahidharguggilam

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}.

jerone avatar May 20 '20 15:05 jerone

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.

carolinewarn avatar Nov 16 '20 14:11 carolinewarn

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

tung-nt-niteco avatar Sep 26 '21 03:09 tung-nt-niteco

Have same issue

RoyalWulf avatar May 06 '22 01:05 RoyalWulf

Should be fixed by: https://github.com/solidify/jira-azuredevops-migrator/pull/489

Alexander-Hjelm avatar Aug 27 '22 12:08 Alexander-Hjelm