private JiraItem ProcessItem(string issueKey, HashSet <string> skipList)
        {
            var issue = JiraItem.CreateFromRest(issueKey, this);

            skipList.Add(issue.Key);
            return(issue);
        }
        internal WiItem Map(JiraItem issue)
        {
            var wiItem = new WiItem();

            if (_config.TypeMap.Types != null)
            {
                var type = (from t in _config.TypeMap.Types where t.Source == issue.Type select t.Target).FirstOrDefault();

                if (type != null)
                {
                    var revisions = issue.Revisions.Select(r => MapRevision(r)).ToList();
                    MapLastDescription(revisions, issue);

                    wiItem.OriginId  = issue.Key;
                    wiItem.Type      = type;
                    wiItem.Revisions = revisions;
                }
                else
                {
                    Logger.Log(LogLevel.Warning, $"Type mapping missing for {issue.Key} with Jira type {issue.Type}. Item not exported which may cause missing links in related issues.");
                    return(null);
                }
            }
            return(wiItem);
        }
Beispiel #3
0
        internal WiItem Map(JiraItem issue)
        {
            var wiItem = new WiItem();

            if (_config.TypeMap.Types != null)
            {
                var type = (from t in _config.TypeMap.Types where t.Source == issue.Type select t.Target).FirstOrDefault();

                if (type != null)
                {
                    var revisions = issue.Revisions.Select(r => MapRevision(r)).ToList();
                    MapLastDescription(revisions, issue);

                    wiItem.OriginId  = issue.Key;
                    wiItem.Type      = type;
                    wiItem.Revisions = revisions;
                    wiItem.WikiURL   = issue.ConfluenceLink;
                }
                else
                {
                    Logger.Log(LogLevel.Error, $"Type mapping missing for '{issue.Key}' with Jira type '{issue.Type}'. Item was not exported which may cause missing links in issues referencing this item.");
                    return(null);
                }
            }
            return(wiItem);
        }
Beispiel #4
0
        private JiraItem ProcessItem(string issueKey, HashSet <string> skipList, string successMessage)
        {
            var issue = JiraItem.CreateFromRest(issueKey, this);

            Logger.Log(LogLevel.Info, $"Downloaded {issueKey} - {successMessage}");
            skipList.Add(issue.Key);
            return(issue);
        }
        private JiraItem ProcessItem(string issueKey, HashSet <string> skipList)
        {
            var issue = JiraItem.CreateFromRest(issueKey, this);

            if (issue == null)
            {
                return(default(JiraItem));
            }

            skipList.Add(issue.Key);
            return(issue);
        }
        public static JiraItem CreateFromRest(string issueKey, JiraProvider jiraProvider)
        {
            var remoteIssue = jiraProvider.DownloadIssue(issueKey);

            Logger.Log(LogLevel.Debug, $"Downloaded {issueKey}");

            var jiraItem  = new JiraItem(jiraProvider, remoteIssue);
            var revisions = BuildRevisions(jiraItem, jiraProvider);

            jiraItem.Revisions = revisions;
            Logger.Log(LogLevel.Debug, $"Formed representation of jira item {issueKey}");

            return(jiraItem);
        }
Beispiel #7
0
        public static JiraItem CreateFromRest(string issueKey, JiraProvider jiraProvider)
        {
            var remoteIssue = jiraProvider.DownloadIssue(issueKey);

            Logger.Log(LogLevel.Debug, $"Downloaded item.");

            var jiraItem  = new JiraItem(jiraProvider, remoteIssue);
            var revisions = BuildRevisions(jiraItem, jiraProvider);

            jiraItem.Revisions = revisions;
            Logger.Log(LogLevel.Debug, $"Created {revisions.Count} history revisions.");

            return(jiraItem);
        }
        private static List <JiraRevision> BuildCommentRevisions(JiraItem jiraItem, JiraProvider jiraProvider)
        {
            var comments = jiraProvider.Jira.Issues.GetCommentsAsync(jiraItem.Key).Result;

            return(comments.Select(c => new JiraRevision(jiraItem)
            {
                Author = c.Author,
                Time = c.CreatedDate.Value,
                Fields = new Dictionary <string, object>()
                {
                    { "comment", c.Body }
                },
                AttachmentActions = new List <RevisionAction <JiraAttachment> >(),
                LinkActions = new List <RevisionAction <JiraLink> >()
            }).ToList());
        }
        internal WiItem Map(JiraItem issue)
        {
            var wiItem = new WiItem();

            if (_config.TypeMap.Types != null)
            {
                var type = (from t in _config.TypeMap.Types where t.Source == issue.Type select t.Target).FirstOrDefault();

                if (type != null)
                {
                    var revisions = issue.Revisions.Select(r => MapRevision(r)).ToList();
                    MapLastDescription(revisions, issue);

                    wiItem.OriginId  = issue.Key;
                    wiItem.Type      = type;
                    wiItem.Revisions = revisions;
                }
            }
            return(wiItem);
        }
        private static List <JiraRevision> BuildCommentRevisions(JiraItem jiraItem, JiraProvider jiraProvider)
        {
            var renderedFields = jiraItem.RemoteIssue.SelectToken("$.renderedFields.comment.comments");
            var comments       = jiraProvider.Jira.Issues.GetCommentsAsync(jiraItem.Key).Result;

            return(comments.Select((c, i) => {
                var rc = renderedFields.SelectToken($"$.[{i}].body");
                return new JiraRevision(jiraItem)
                {
                    Author = c.Author,
                    Time = c.CreatedDate.Value,
                    Fields = new Dictionary <string, object>()
                    {
                        { "comment", c.Body }, { "comment$Rendered", RenderedComment(rc.Value <string>()) }
                    },
                    AttachmentActions = new List <RevisionAction <JiraAttachment> >(),
                    LinkActions = new List <RevisionAction <JiraLink> >()
                };
            }).ToList());
        }
        private static List <JiraRevision> BuildRevisions(JiraItem jiraItem, JiraProvider jiraProvider)
        {
            string issueKey    = jiraItem.Key;
            var    remoteIssue = jiraItem.RemoteIssue;
            Dictionary <string, object> fields      = ExtractFields(issueKey, (JObject)remoteIssue.SelectToken("$.fields"), jiraProvider);
            List <JiraAttachment>       attachments = ExtractAttachments(remoteIssue.SelectTokens("$.fields.attachment[*]").Cast <JObject>()) ?? new List <JiraAttachment>();
            List <JiraLink>             links       = ExtractLinks(issueKey, remoteIssue.SelectTokens("$.fields.issuelinks[*]").Cast <JObject>()) ?? new List <JiraLink>();


            var changelog = jiraProvider.DownloadChangelog(issueKey).ToList();

            changelog.Reverse();

            Stack <JiraRevision> revisions = new Stack <JiraRevision>();

            foreach (var change in changelog)
            {
                DateTime created = change.ExValue <DateTime>("$.created");
                string   author  = change.ExValue <string>("$.author.name");

                List <RevisionAction <JiraLink> >       linkChanges       = new List <RevisionAction <JiraLink> >();
                List <RevisionAction <JiraAttachment> > attachmentChanges = new List <RevisionAction <JiraAttachment> >();
                Dictionary <string, object>             fieldChanges      = new Dictionary <string, object>();

                var items = change.SelectTokens("$.items[*]").Cast <JObject>().Select(i => new JiraChangeItem(i));
                foreach (var item in items)
                {
                    if (item.Field == "Link")
                    {
                        var linkChange = TransformLinkChange(item, issueKey, jiraProvider);
                        if (linkChange == null)
                        {
                            continue;
                        }

                        linkChanges.Add(linkChange);

                        UndoLinkChange(linkChange, links);
                    }
                    else if (item.Field == "Attachment")
                    {
                        var attachmentChange = TransformAttachmentChange(item);
                        if (attachmentChange == null)
                        {
                            continue;
                        }

                        attachmentChanges.Add(attachmentChange);

                        UndoAttachmentChange(attachmentChange, attachments);
                    }
                    else
                    {
                        var(fieldref, from, to) = TransformFieldChange(item, jiraProvider);

                        fieldChanges[fieldref] = to;

                        // undo field change
                        if (string.IsNullOrEmpty(from))
                        {
                            fields.Remove(fieldref);
                        }
                        else
                        {
                            fields[fieldref] = from;
                        }
                    }
                }

                var revision = new JiraRevision(jiraItem)
                {
                    Time = created, Author = author, AttachmentActions = attachmentChanges, LinkActions = linkChanges, Fields = fieldChanges
                };
                revisions.Push(revision);
            }

            // what is left after undoing all changes is first revision
            var attActions = attachments.Select(a => new RevisionAction <JiraAttachment>()
            {
                ChangeType = RevisionChangeType.Added, Value = a
            }).ToList();
            var linkActions = links.Select(l => new RevisionAction <JiraLink>()
            {
                ChangeType = RevisionChangeType.Added, Value = l
            }).ToList();
            var fieldActions = fields;

            var reporter  = (string)fields["reporter"];
            var createdOn = (DateTime)fields["created"];

            var firstRevision = new JiraRevision(jiraItem)
            {
                Time = createdOn, Author = reporter, AttachmentActions = attActions, Fields = fieldActions, LinkActions = linkActions
            };

            revisions.Push(firstRevision);
            var listOfRevisions = revisions.ToList();

            List <JiraRevision> commentRevisions = BuildCommentRevisions(jiraItem, jiraProvider);

            listOfRevisions.AddRange(commentRevisions);
            listOfRevisions.Sort();

            foreach (var revAndI in listOfRevisions.Select((r, i) => (r, i)))
            {
                revAndI.Item1.Index = revAndI.Item2;
            }

            return(listOfRevisions);
        }
Beispiel #12
0
        private static List <JiraRevision> BuildRevisions(JiraItem jiraItem, JiraProvider jiraProvider)
        {
            string issueKey    = jiraItem.Key;
            var    remoteIssue = jiraItem.RemoteIssue;
            Dictionary <string, object> fields      = ExtractFields(issueKey, (JObject)remoteIssue, jiraProvider);
            List <JiraAttachment>       attachments = ExtractAttachments(remoteIssue.SelectTokens("$.fields.attachment[*]").Cast <JObject>()) ?? new List <JiraAttachment>();
            List <JiraLink>             links       = ExtractLinks(issueKey, remoteIssue.SelectTokens("$.fields.issuelinks[*]").Cast <JObject>()) ?? new List <JiraLink>();

            // save these field since these might be removed in the loop
            string reporter  = GetAuthor(fields);
            var    createdOn = fields.TryGetValue("created", out object crdate) ? (DateTime)crdate : default(DateTime);

            if (createdOn == DateTime.MinValue)
            {
                Logger.Log(LogLevel.Debug, "created key was not found, using DateTime default value");
            }


            var changelog = jiraProvider.DownloadChangelog(issueKey).ToList();

            Logger.Log(LogLevel.Debug, $"Downloaded issue: {issueKey} changelog.");
            changelog.Reverse();

            Stack <JiraRevision> revisions = new Stack <JiraRevision>();

            foreach (var change in changelog)
            {
                DateTime created = change.ExValue <DateTime>("$.created");
                string   author  = GetAuthor(change);

                List <RevisionAction <JiraLink> >       linkChanges       = new List <RevisionAction <JiraLink> >();
                List <RevisionAction <JiraAttachment> > attachmentChanges = new List <RevisionAction <JiraAttachment> >();
                Dictionary <string, object>             fieldChanges      = new Dictionary <string, object>(StringComparer.InvariantCultureIgnoreCase);

                var items = change.SelectTokens("$.items[*]")?.Cast <JObject>()?.Select(i => new JiraChangeItem(i));

                foreach (var item in items)
                {
                    if (item.Field == "Link")
                    {
                        var linkChange = TransformLinkChange(item, issueKey, jiraProvider);
                        if (linkChange == null)
                        {
                            continue;
                        }

                        linkChanges.Add(linkChange);

                        UndoLinkChange(linkChange, links);
                    }
                    else if (item.Field == "Attachment")
                    {
                        var attachmentChange = TransformAttachmentChange(item);
                        if (attachmentChange == null)
                        {
                            continue;
                        }

                        attachmentChanges.Add(attachmentChange);

                        UndoAttachmentChange(attachmentChange, attachments);
                    }
                    else
                    {
                        var(fieldref, from, to) = TransformFieldChange(item, jiraProvider);

                        fieldChanges[fieldref] = to;

                        // undo field change
                        if (string.IsNullOrEmpty(from))
                        {
                            fields.Remove(fieldref);
                        }
                        else
                        {
                            fields[fieldref] = from;
                        }
                    }
                }

                var revision = new JiraRevision(jiraItem)
                {
                    Time = created, Author = author, AttachmentActions = attachmentChanges, LinkActions = linkChanges, Fields = fieldChanges
                };
                revisions.Push(revision);
            }

            // what is left after undoing all changes is first revision
            var attActions = attachments.Select(a => new RevisionAction <JiraAttachment>()
            {
                ChangeType = RevisionChangeType.Added, Value = a
            }).ToList();
            var linkActions = links.Select(l => new RevisionAction <JiraLink>()
            {
                ChangeType = RevisionChangeType.Added, Value = l
            }).ToList();
            var fieldActions = fields;

            var firstRevision = new JiraRevision(jiraItem)
            {
                Time = createdOn, Author = reporter, AttachmentActions = attActions, Fields = fieldActions, LinkActions = linkActions
            };

            revisions.Push(firstRevision);
            var listOfRevisions = revisions.ToList();

            List <JiraRevision> commentRevisions = BuildCommentRevisions(jiraItem, jiraProvider);

            listOfRevisions.AddRange(commentRevisions);
            listOfRevisions.Sort();

            foreach (var revAndI in listOfRevisions.Select((r, i) => (r, i)))
            {
                revAndI.Item1.Index = revAndI.Item2;
            }

            return(listOfRevisions);
        }
        internal WiItem Map(JiraItem issue)
        {
            var wiItem = new WiItem();

            if (_config.TypeMap.Types != null)
            {
                var type = (from t in _config.TypeMap.Types where t.Source == issue.Type select t.Target).FirstOrDefault();

                if (type != null)
                {
                    var revisions = issue.Revisions.Select(r => MapRevision(r)).ToList();

                    // TODO: Add revision for snapshot fields
                    const string pfPrefix = "Preserve.";

                    var pfContent = new StringBuilder();
                    pfContent.AppendLine($"<h3>Migration Preserved Fields</h3>");
                    pfContent.AppendLine($"<table><tr><th>Field</th><th>Value</th></tr>");
                    var hasPreserveFields = false;

                    foreach (var r in revisions)
                    {
                        var preserveFields = from f in r.Fields
                                             where f.ReferenceName.StartsWith(pfPrefix)
                                             select f;
                        hasPreserveFields = hasPreserveFields || preserveFields.Count() > 0;
                        foreach (var pf in preserveFields.ToList())
                        {
                            pfContent.AppendLine($"<tr><td>{pf.ReferenceName.Replace(pfPrefix, "")}</td><td>{pf.Value?.ToString().Trim()}</td></tr>");
                            r.Fields.Remove(pf);
                        }
                    }
                    pfContent.AppendLine($"</table>");

                    if (hasPreserveFields)
                    {
                        revisions.Add(new WiRevision()
                        {
                            ParentOriginId = issue.Key,
                            Index          = revisions.Count,
                            Author         = MapUser("*****@*****.**"),
                            Fields         = new List <WiField>()
                            {
                                new WiField()
                                {
                                    ReferenceName = "System.History", Value = pfContent.ToString()
                                }
                            }
                        });
                    }
                    wiItem.OriginId  = issue.Key;
                    wiItem.Type      = type;
                    wiItem.Revisions = revisions;
                }
                else
                {
                    Logger.Log(LogLevel.Error, $"Type mapping missing for '{issue.Key}' with Jira type '{issue.Type}'. Item was not exported which may cause missing links in issues referencing this item.");
                    return(null);
                }
            }
            return(wiItem);
        }
Beispiel #14
0
 public JiraRevision(JiraItem parentItem)
 {
     ParentItem = parentItem;
 }