Exemplo n.º 1
0
        private void IssueUpdated(Issue issue, Card card, BoardMapping boardMapping)
        {
            Log.Info("Issue [{0}] updated, comparing to corresponding card...", issue.Key);

            long boardId = boardMapping.Identity.LeanKit;

            // sync and save those items that are different (of title, description, priority)
            bool saveCard = false;

            if (issue.Fields != null)
            {
                if (issue.Fields.Summary != null && issue.Fields.Summary != card.Title)
                {
                    card.Title = issue.Fields.Summary;
                    saveCard   = true;
                }

                if (issue.Fields.Description != null && issue.Fields.Description.SanitizeCardDescription() != card.Description)
                {
                    card.Description = issue.Fields.Description.SanitizeCardDescription();
                    saveCard         = true;
                }

                var priority = issue.LeanKitPriority();
                if (priority != card.Priority)
                {
                    card.Priority = priority;
                    saveCard      = true;
                }

                if (issue.Fields.Labels != null && issue.Fields.Labels.Count > 0)
                {
                    var tags = string.Join(",", issue.Fields.Labels.Select(x => x));
                    if (card.Tags != tags)
                    {
                        card.Tags = tags;
                        saveCard  = true;
                    }
                }
                else if (!string.IsNullOrEmpty(card.Tags))
                {
                    card.Tags = "";
                    saveCard  = true;
                }

                if ((card.Tags == null || !card.Tags.Contains(ServiceName)) && boardMapping.TagCardsWithTargetSystemName)
                {
                    if (string.IsNullOrEmpty(card.Tags))
                    {
                        card.Tags = ServiceName;
                    }
                    else
                    {
                        card.Tags += "," + ServiceName;
                    }
                    saveCard = true;
                }

                if (issue.Fields.DueDate != null && CurrentUser != null)
                {
                    var dateFormat    = CurrentUser.DateFormat ?? "MM/dd/yyyy";
                    var dueDateString = issue.Fields.DueDate.Value.ToString(dateFormat, CultureInfo.InvariantCulture);
                    if (card.DueDate != dueDateString)
                    {
                        card.DueDate = dueDateString;
                        saveCard     = true;
                    }
                }
                else if (!string.IsNullOrEmpty(card.DueDate))
                {
                    card.DueDate = "";
                    saveCard     = true;
                }
            }

            if (saveCard)
            {
                Log.Info("Updating card [{0}]", card.Id);
                LeanKit.UpdateCard(boardId, card);
            }

            // check the state of the work item
            // if we have the state mapped to a lane then check to see if the card is in that lane
            // if it is not in that lane then move it to that lane
            if (boardMapping.UpdateCardLanes && issue.Fields != null && issue.Fields.Status != null && !string.IsNullOrEmpty(issue.Fields.Status.Name))
            {
                // if card is already in archive lane then we do not want to move it to the end lane
                // because it is effectively the same thing with respect to integrating with TFS
                if (card.LaneId == boardMapping.ArchiveLaneId)
                {
                    return;
                }

                var laneIds = boardMapping.LanesFromState(issue.Fields.Status.Name);
                if (laneIds.Any())
                {
                    if (!laneIds.Contains(card.LaneId))
                    {
                        // first let's see if any of the lanes are sibling lanes, if so then
                        // we should be using one of them. So we'll limit the results to just siblings
                        if (boardMapping.ValidLanes != null)
                        {
                            var siblingLaneIds = (from siblingLaneId in laneIds
                                                  let parentLane =
                                                      boardMapping.ValidLanes.FirstOrDefault(x =>
                                                                                             x.HasChildLanes &&
                                                                                             x.ChildLaneIds.Contains(siblingLaneId) &&
                                                                                             x.ChildLaneIds.Contains(card.LaneId))
                                                      where parentLane != null
                                                      select siblingLaneId).ToList();
                            if (siblingLaneIds.Any())
                            {
                                laneIds = siblingLaneIds;
                            }
                        }

                        LeanKit.MoveCard(boardMapping.Identity.LeanKit, card.Id, laneIds.First(), 0, "Moved Lane From Jira Issue");
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void WorkItemUpdated(WorkItem workItem, Card card, BoardMapping project)
        {
            Log.Info("WorkItem [{0}] updated, comparing to corresponding card...", workItem.Id);

            var boardId = project.Identity.LeanKit;

            // sync and save those items that are different (of title, description, priority)
            var saveCard = false;

            if (workItem.Title != card.Title)
            {
                card.Title = workItem.Title;
                saveCard   = true;
            }

            var description = workItem.LeanKitDescription(GetTfsVersion());

            if (description != card.Description)
            {
                card.Description = description;
                saveCard         = true;
            }

            var priority = workItem.LeanKitPriority();

            if (priority != card.Priority)
            {
                card.Priority = priority;
                saveCard      = true;
            }

            if (workItem.Fields != null &&
                workItem.Fields.Contains("Tags") &&
                workItem.Fields["Tags"] != null &&
                workItem.Fields["Tags"].Value.ToString() != card.Tags)
            {
                var tfsTags = workItem.Fields["Tags"].Value.ToString();
                // since we cannot set the tags in TFS we cannot blindly overwrite the LK tags
                // with what is in TFS. Instead we can only add TFS tags to LK
                if (!string.IsNullOrEmpty(tfsTags))
                {
                    var tfsTagsArr = tfsTags.Split(',');
                    foreach (var tag in tfsTagsArr)
                    {
                        if (card.Tags.ToLowerInvariant().Contains(tag.ToLowerInvariant()))
                        {
                            continue;
                        }
                        if (card.Tags == string.Empty)
                        {
                            card.Tags = tag;
                        }
                        else
                        {
                            card.Tags += "," + tag;
                        }
                        saveCard = true;
                    }
                }
            }

            if (workItem.Fields != null && (workItem.Fields.Contains("Original Estimate") || workItem.Fields.Contains("Story Points")))
            {
                if (workItem.Fields.Contains("Original Estimate") && workItem.Fields["Original Estimate"] != null && workItem.Fields["Original Estimate"].Value != null)
                {
                    double cardSize;
                    var    isNumber = Double.TryParse(workItem.Fields["Original Estimate"].Value.ToString(), out cardSize);
                    if (isNumber)
                    {
                        var size = (int)cardSize;
                        if (card.Size != size)
                        {
                            card.Size = size;
                            saveCard  = true;
                        }
                    }
                }
                else if (workItem.Fields.Contains("Story Points") && workItem.Fields["Story Points"] != null && workItem.Fields["Story Points"].Value != null)
                {
                    double cardSize;
                    var    isNumber = Double.TryParse(workItem.Fields["Story Points"].Value.ToString(), out cardSize);
                    if (isNumber)
                    {
                        var size = (int)cardSize;
                        if (card.Size != size)
                        {
                            card.Size = size;
                            saveCard  = true;
                        }
                    }
                }
            }

            if ((card.Tags == null || !card.Tags.Contains(ServiceName)) && project.TagCardsWithTargetSystemName)
            {
                if (string.IsNullOrEmpty(card.Tags))
                {
                    card.Tags = ServiceName;
                }
                else
                {
                    card.Tags += "," + ServiceName;
                }
                saveCard = true;
            }

            if (saveCard)
            {
                Log.Info("Updating card [{0}]", card.Id);
                LeanKit.UpdateCard(boardId, card);
            }

            // check the state of the work item
            // if we have the state mapped to a lane then check to see if the card is in that lane
            // if it is not in that lane then move it to that lane
            if (!project.UpdateCardLanes || string.IsNullOrEmpty(workItem.State))
            {
                return;
            }

            // if card is already in archive lane then we do not want to move it to the end lane
            // because it is effectively the same thing with respect to integrating with TFS
            if (card.LaneId == project.ArchiveLaneId)
            {
                return;
            }

            var laneIds = project.LanesFromState(workItem.State);

            if (laneIds.Any())
            {
                if (!laneIds.Contains(card.LaneId))
                {
                    // first let's see if any of the lanes are sibling lanes, if so then
                    // we should be using one of them. So we'll limit the results to just siblings
                    if (project.ValidLanes != null)
                    {
                        var siblingLaneIds = (from siblingLaneId in laneIds
                                              let parentLane =
                                                  project.ValidLanes.FirstOrDefault(x =>
                                                                                    x.HasChildLanes &&
                                                                                    x.ChildLaneIds.Contains(siblingLaneId) &&
                                                                                    x.ChildLaneIds.Contains(card.LaneId))
                                                  where parentLane != null
                                                  select siblingLaneId).ToList();
                        if (siblingLaneIds.Any())
                        {
                            laneIds = siblingLaneIds;
                        }
                    }

                    LeanKit.MoveCard(project.Identity.LeanKit, card.Id, laneIds.First(), 0, "Moved Lane From TFS Work Item");
                }
            }
        }