Skip to content

Commit 36a9d46

Browse files
committed
Addressed review comments
1 parent ce9511b commit 36a9d46

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
name: 'pylint'
2222
command: |
2323
source /usr/local/share/virtualenvs/tap-trello/bin/activate
24-
pylint tap_trello --disable 'broad-except,chained-comparison,empty-docstring,fixme,invalid-name,line-too-long,missing-class-docstring,missing-function-docstring,missing-module-docstring,no-else-raise,no-else-return,too-few-public-methods,too-many-arguments,too-many-branches,too-many-lines,too-many-locals,ungrouped-imports,wrong-spelling-in-comment,wrong-spelling-in-docstring,consider-using-f-string,unspecified-encoding,broad-exception-raised,use-yield-from,logging-format-interpolation,unnecessary-pass,too-many-positional-arguments,too-many-statements'
24+
pylint tap_trello -d C,R,W
2525
- run:
2626
name: 'Unit Tests'
2727
command: |

tap_trello/schemas/card_custom_field_items.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@
6262
"string"
6363
]
6464
}
65-
},
66-
"required": ["id", "card_id"]
65+
}
6766
}

tap_trello/streams/abstracts.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,26 @@
1111

1212
LOGGER = get_logger()
1313

14+
1415
class OrderChecker:
1516
""" Class with context manager to check ordering of values. """
1617
order = None
1718
_last_value = None
19+
check_paired_order = None
1820

1921
def __init__(self, order='ASC'):
2022
self.order = order
23+
self.check_paired_order = operator.lt if order == 'ASC' else operator.gt
2124

2225
def check_order(self, current_value):
2326
"""
2427
We are sub-paginating based on a sort order descending assumption for
2528
Actions, this ensures that this holds up.
2629
"""
27-
if self.order == 'ASC':
28-
check_paired_order = operator.lt
29-
else:
30-
check_paired_order = operator.gt
31-
3230
if self._last_value is None:
3331
self._last_value = current_value
3432

35-
if check_paired_order(current_value, self._last_value):
33+
if self.check_paired_order(current_value, self._last_value):
3634
asc_desc = "ascending" if self.order == 'ASC' else "descending"
3735
gt_lt = "less than" if self.order == 'ASC' else "greater than"
3836
raise Exception(
@@ -57,9 +55,11 @@ def __enter__(self):
5755
def __exit__(self, *args):
5856
""" Required for context manager usage. """
5957

58+
6059
class Mixin:
6160
""" Empty class to mark mixin classes as such. """
6261

62+
6363
class Unsortable(Mixin):
6464
"""
6565
Mixin class to mark a Stream subclass as Unsortable
@@ -73,6 +73,7 @@ class MyStream(Unsortable, Stream):
7373
# NB: We've observed that Trello will only return 50 actions, this is to sub-paginate
7474
MAX_API_RESPONSE_SIZE = 50
7575

76+
7677
class DateWindowPaginated(Mixin):
7778
"""
7879
Mixin class to provide date windowing on the `get_records` requests
@@ -171,7 +172,6 @@ def _paginate_window(self, window_start, window_end, format_values):
171172
break
172173

173174

174-
175175
class LegacyStream:
176176
"""
177177
Legacy base class for Trello streams (pre-refactor).
@@ -240,6 +240,7 @@ def sync(self):
240240
for rec in self.get_records(self.get_format_values()):
241241
yield rec
242242

243+
243244
class AddCustomFields(Mixin):
244245
def _get_dropdown_option_key(self, field_id, option_id):
245246
return field_id + '_' + option_id
@@ -274,7 +275,6 @@ def modify_record(self, record, **kwargs):
274275
return record
275276

276277

277-
278278
class AddBoardId(Mixin):
279279
def modify_record(self, record, **kwargs):
280280
board_id_list = kwargs['parent_id_list']
@@ -423,7 +423,6 @@ def sync(
423423
- https://github.com/singer-io/getting-started/blob/master/docs/SYNC_MODE.md
424424
"""
425425

426-
427426
def get_records(self) -> Iterator:
428427
"""Interacts with api client interaction and pagination."""
429428
self.params["page"] = self.page_size

tap_trello/streams/cards.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Cards(AddCustomFields, ChildStream):
1717

1818
def get_records(self, format_values, additional_params=None):
1919
# Get max_api_response_size from config and set to parameter
20-
cards_response_size = self.config.get('cards_response_size')
21-
self.MAX_API_RESPONSE_SIZE = int(cards_response_size) if cards_response_size else self.MAX_API_RESPONSE_SIZE
20+
cards_response_size = int(self.config.get('cards_response_size') or self.MAX_API_RESPONSE_SIZE)
21+
self.MAX_API_RESPONSE_SIZE = min(cards_response_size, 1000)
2222
self.params = {'limit': self.MAX_API_RESPONSE_SIZE, 'customFieldItems': 'true'}
2323

2424
# Set window_end with current time
@@ -27,21 +27,14 @@ def get_records(self, format_values, additional_params=None):
2727
# Build custom fields and dropdown object map for the specific parent
2828
custom_fields_map, dropdown_options_map = self.build_custom_fields_maps(parent_id_list=format_values)
2929

30-
while True:
30+
has_more_pages = True
31+
while has_more_pages:
3132

3233
# Get records for cards before specified time
3334
# Reference: https://developer.atlassian.com/cloud/trello/guides/rest-api/api-introduction/#paging
3435
records = self.client.get(self._format_endpoint(format_values), params={"before": window_end,
3536
**self.params})
3637

37-
# Raise exception if API returns more data than specified limit
38-
if self.MAX_API_RESPONSE_SIZE and len(records) > self.MAX_API_RESPONSE_SIZE:
39-
raise Exception(
40-
("{}: Number of records returned is greater than the requested API response size of {}.").format(
41-
self.stream_id,
42-
self.MAX_API_RESPONSE_SIZE)
43-
)
44-
4538
# Yielding records after adding custom fields and dropdown object map to all records
4639
for rec in records:
4740
yield self.modify_record(rec, parent_id_list = format_values, custom_fields_map = custom_fields_map, dropdown_options_map = dropdown_options_map)
@@ -58,5 +51,5 @@ def get_records(self, format_values, additional_params=None):
5851
# API returns latest records so set window_end to smallest card id to get older data
5952
window_end = records[0]["id"]
6053
else:
61-
# API returns less records than limit, break the pagination
62-
break
54+
# API returns less records than limit, stop pagination
55+
has_more_pages = False

0 commit comments

Comments
 (0)