コード例 #1
0
        private void PullUpdated(Pull pull, Card card, BoardMapping boardMapping)
        {
            Log.Info("Pull [{0}] updated, comparing to corresponding card...", pull.Id);

            long boardId = boardMapping.Identity.LeanKit;

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

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

            if (pull.Body.SanitizeCardDescription() != card.Description)
            {
                card.Description = pull.Body.SanitizeCardDescription();
                saveCard         = true;
            }

            var priority = pull.LeanKitPriority();

            if (priority != card.Priority)
            {
                card.Priority = priority;
                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 (saveCard)
            {
                Log.Info("Updating card [{0}]", card.Id);
                LeanKit.UpdateCard(boardId, card);
            }
        }
コード例 #2
0
        private void CreateCardFromItem(BoardMapping project, Pull pull)
        {
			if (pull == null) return;
        
            var boardId = project.Identity.LeanKit;
        
            var mappedCardType = pull.LeanKitCardType(project);
            var laneId = project.LanesFromState(pull.State).First();
            var card = new Card
            {
			    Active = true,
                Title = pull.Title,
				Description = pull.Body.SanitizeCardDescription(),
				Priority = pull.LeanKitPriority(),
                TypeId = mappedCardType.Id,
                TypeName = mappedCardType.Name,
                LaneId = laneId,
                ExternalCardID = pull.Id.ToString() + "|" + pull.Number.ToString(),
                ExternalSystemName = ServiceName, 				
				ExternalSystemUrl = string.Format(_externalUrlTemplate, project.Identity.Target, pull.Number)
            };

			var assignedUserId = pull.LeanKitAssignedUser(boardId, LeanKit);
			if (assignedUserId != null)
				card.AssignedUserIds = new[] { assignedUserId.Value };

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

            Log.Info("Creating a card of type [{0}] for Pull Request [{1}] on Board [{2}] on Lane [{3}]", mappedCardType.Name, pull.Number, boardId, laneId);

	        CardAddResult cardAddResult = null;

			int tries = 0;
			bool success = false;
			while (tries < 10 && !success) 
			{
				if (tries > 0) 
				{
					Log.Error(string.Format("Attempting to create card for Pull Request [{0}] attempt number [{1}]", pull.Id,
											 tries));
					// wait 5 seconds before trying again
					Thread.Sleep(new TimeSpan(0, 0, 5));
				}

				try {
					cardAddResult = LeanKit.AddCard(boardId, card, "New Card From GitHub Pull Request");
					success = true;
				} catch (Exception ex) {
					Log.Error(string.Format("An error occurred: {0} - {1} - {2}", ex.GetType(), ex.Message, ex.StackTrace));
				}
				tries++;
			}
	        if (cardAddResult != null) card.Id = cardAddResult.CardId;

	        Log.Info("Created a card [{0}] of type [{1}] for Pull Request [{2}] on Board [{3}] on Lane [{4}]", card.Id, mappedCardType.Name, pull.Number, boardId, laneId);
        }
コード例 #3
0
		private void PullUpdated(Pull pull, Card card, BoardMapping boardMapping) 
		{
			Log.Info("Pull [{0}] updated, comparing to corresponding card...", pull.Id);

			long boardId = boardMapping.Identity.LeanKit;

			// sync and save those items that are different (of title, description, priority)
			bool saveCard = false;
			if (pull.Title != card.Title) 
			{
				card.Title = pull.Title;
				saveCard = true;
			}

			if (pull.Body.SanitizeCardDescription() != card.Description) 
			{
				card.Description = pull.Body.SanitizeCardDescription();
				saveCard = true;
			}

			var priority = pull.LeanKitPriority();
			if (priority != card.Priority) 
			{
				card.Priority = priority;
				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 (saveCard) 
			{
				Log.Info("Updating card [{0}]", card.Id);
				LeanKit.UpdateCard(boardId, card);
			}
		}
コード例 #4
0
        private void CreateCardFromItem(BoardMapping project, Pull pull)
        {
            if (pull == null)
            {
                return;
            }

            var boardId = project.Identity.LeanKit;

            var mappedCardType = pull.LeanKitCardType(project);
            var laneId         = project.LanesFromState(pull.State).First();
            var card           = new Card
            {
                Active             = true,
                Title              = pull.Title,
                Description        = pull.Body.SanitizeCardDescription(),
                Priority           = pull.LeanKitPriority(),
                TypeId             = mappedCardType.Id,
                TypeName           = mappedCardType.Name,
                LaneId             = laneId,
                ExternalCardID     = pull.Id.ToString() + "|" + pull.Number.ToString(),
                ExternalSystemName = ServiceName,
                ExternalSystemUrl  = string.Format(_externalUrlTemplate, project.Identity.Target, pull.Number)
            };

            var assignedUserId = pull.LeanKitAssignedUser(boardId, LeanKit);

            if (assignedUserId != null)
            {
                card.AssignedUserIds = new[] { assignedUserId.Value }
            }
            ;

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

            Log.Info("Creating a card of type [{0}] for Pull Request [{1}] on Board [{2}] on Lane [{3}]", mappedCardType.Name, pull.Number, boardId, laneId);

            CardAddResult cardAddResult = null;

            int  tries   = 0;
            bool success = false;

            while (tries < 10 && !success)
            {
                if (tries > 0)
                {
                    Log.Error(string.Format("Attempting to create card for Pull Request [{0}] attempt number [{1}]", pull.Id,
                                            tries));
                    // wait 5 seconds before trying again
                    Thread.Sleep(new TimeSpan(0, 0, 5));
                }

                try {
                    cardAddResult = LeanKit.AddCard(boardId, card, "New Card From GitHub Pull Request");
                    success       = true;
                } catch (Exception ex) {
                    Log.Error(string.Format("An error occurred: {0} - {1} - {2}", ex.GetType(), ex.Message, ex.StackTrace));
                }
                tries++;
            }
            if (cardAddResult != null)
            {
                card.Id = cardAddResult.CardId;
            }

            Log.Info("Created a card [{0}] of type [{1}] for Pull Request [{2}] on Board [{3}] on Lane [{4}]", card.Id, mappedCardType.Name, pull.Number, boardId, laneId);
        }