Ejemplo n.º 1
0
        /// <summary>
        /// parse a commit message, following specified syntax
        /// </summary>
        /// <param name="CommitMessage">commit message</param>
        /// <returns>list of comments to push up to Trello</returns>
        public List<Comment> ParseCommitMessage(string CommitMessage)
        {
            var Messages = Regex.Split(CommitMessage, "\r\n|\r|\n");
            var Comments = new List<Comment>();
            foreach (var Message in Messages)
            {
                try
                {
                    var Tokens = Message.Split(' ').ToList();
                    var Comment = new Comment();
                    var Verb = Tokens[0].ToLower();
                    if (VERBS.Keys.Contains(Verb))
                    {
                        Comment.List = VERBS[Verb];
                        Tokens.RemoveAt(0);
                    }
                    int CardIndex = Tokens.FindIndex(x => x.ToLower().Equals("card"));
                    if (CardIndex < 0) break;
                    Comment.BoardName = string.Join(" ", Tokens.GetRange(0, CardIndex));
                    if (string.IsNullOrEmpty(Comment.BoardName.Trim()) || Comment.BoardName.Equals("card"))
                    {
                        break;
                    }
                    Comment.CardId = int.Parse(Regex.Replace(Tokens.ElementAt(CardIndex + 1), "[^0-9]+", string.Empty));
                    Comment.Message = string.Join(" ", Tokens.GetRange(CardIndex + 2, Tokens.Count - CardIndex - 2)).Trim();

                    Comments.Add(Comment);
                }
                catch (Exception) { Console.WriteLine("Caught poorly formatted message: " + Message); }
            }
            return Comments;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// add a single comment to a card on the specified Board
 /// </summary>
 /// <param name="Board">Trello Board</param>
 /// <param name="Comment">Comment object</param>
 private void PushComment(TrelloNet.Board Board, Comment Comment)
 {
     var Card = Trello.Cards.WithShortId(Comment.CardId, Board);
     Trello.Cards.AddComment(Card, Comment.ToString());
     Console.WriteLine("Added comment to card #" + Card.IdShort + " on the " + Board.Name + " board");
     if (Comment.List != null)
     {
         var List = Trello.Lists.ForBoard(Board).Single(x => x.Name.Equals(Comment.List));
         Trello.Cards.Move(Card, List);
     }
 }