Skip to content

Commit

Permalink
Merge support for Trello commented cards [#170]
Browse files Browse the repository at this point in the history
  • Loading branch information
psss committed Dec 19, 2018
2 parents 21c8e7d + 55326c5 commit bca47a3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
23 changes: 20 additions & 3 deletions did/plugins/trello.py
Expand Up @@ -49,7 +49,7 @@
from did.stats import Stats, StatsGroup

DEFAULT_FILTERS = [
"createCard", "updateCard",
"commentCard", "createCard", "updateCard",
"updateCard:idList", "updateCard:closed",
"updateCheckItemStateOnCard"]

Expand Down Expand Up @@ -149,7 +149,7 @@ def fetch(self):
# Trello updateCard
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class TrelloCards(TrelloStats):
class TrelloCardsUpdated(TrelloStats):
""" Trello cards updated"""

def fetch(self):
Expand All @@ -165,6 +165,22 @@ def fetch(self):
self.stats = sorted(list(set(actions)))


class TrelloCardsCommented(TrelloStats):
""" Trello cards commented"""

def fetch(self):
log.info(
"Searching for cards commented in %s by %s",
self.parent.option, self.user)
actions = [
act['data']['card']['name']
for act in self.trello.get_actions(
filters=self.filt,
since=self.options.since.date,
before=self.options.until.date)]
self.stats = sorted(list(set(actions)))


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Trello updateCard:closed
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -256,7 +272,8 @@ def __init__(self, option, name=None, parent=None, user=None):
'Boards': {},
'Lists': {},
'Cards': {
'updateCard': TrelloCards,
'commentCard': TrelloCardsCommented,
'updateCard': TrelloCardsUpdated,
'updateCard:closed': TrelloCardsClosed,
'updateCard:idList': TrelloCardsMoved,
'createCard': TrelloCardsCreated},
Expand Down
37 changes: 23 additions & 14 deletions tests/plugins/test_trello.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# @Author: Eduard Trott
# Test Board: https://trello.com/b/sH1cMiyg/public-test-board
# coding: utf-8
# Test Board: https://trello.com/b/YcOfywBd/did-testing

""" Tests for the Trello plugin """

Expand All @@ -14,14 +13,14 @@
# Constants
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

INTERVAL = "--since 2015-10-01 --until 2015-10-03"
INTERVAL = "--since 2018-12-19 --until 2018-12-19"

CONFIG = """
[general]
email = "Eduard Trott" <etrott@redhat.com>
email = "Did Tester" <the.did.tester@gmail.com>
[trello]
type = trello
user = maybelinot
user = didtester
"""


Expand All @@ -35,7 +34,7 @@ def test_trello_cards_created():
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[0].stats
print stats
assert any([
"Card2" in unicode(stat) for stat in stats])
"CreatedCard" in unicode(stat) for stat in stats])


def test_trello_cards_updated():
Expand All @@ -44,7 +43,7 @@ def test_trello_cards_updated():
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[1].stats
print stats
assert any([
"Card4"
"UpdatedCard"
in unicode(stat) for stat in stats])


Expand All @@ -54,32 +53,42 @@ def test_trello_cards_closed():
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[2].stats
print stats
assert any([
"Archived Card: closed"
"ClosedCard: closed"
in unicode(stat) for stat in stats])


def test_trello_cards_commented():
""" Commented cards """
did.base.Config(CONFIG)
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[3].stats
print stats
assert any([
"CommentedCard"
in unicode(stat) for stat in stats])


def test_trello_cards_moved():
""" Moved cards """
did.base.Config(CONFIG)
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[3].stats
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[4].stats
print stats
assert any([
"[Card3] moved from [List1] to [List3]"
"[MovedCard] moved from [new] to [active]"
in unicode(stat) for stat in stats])


def test_trello_checklists_checkitem():
""" Completed Checkitems in checklists """
did.base.Config(CONFIG)
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[4].stats
stats = did.cli.main(INTERVAL)[0][0].stats[0].stats[5].stats
print stats
# print[unicode(stat) for stat in stats]
assert any([
"Card1: CheckItem3"
"ChecklistCard: CheckItem"
in unicode(stat) for stat in stats])


def test_trello_missing_apikey():
def test_trello_missing_username():
""" Missing username """
did.base.Config("[trello]\ntype = trello")
with pytest.raises(did.base.ReportError):
Expand Down

0 comments on commit bca47a3

Please sign in to comment.