def run_task_move(self, card: Card, to_list: trello.List): card_labels = card.labels if card_labels is None: card_labels = [] # find all labels need to apply after moving labels_to_apply: List[Label] = [] for label in card_labels: label_list = self.label_mapping.get(label, []) labels_to_apply += label_list # find all members need to assign after moving members_to_assign: List[str] = [] for label in card_labels: member_list = self.member_via_label.get(label.id, []) members_to_assign += member_list # find all comments need to make after moving comments_to_make: List[str] = [] for label in card_labels: comment_list = self.comment_via_label.get(label.id, []) comments_to_make += comment_list # remove all members for member in card.idMembers: card.unassign(member) # remove all labels for label in card_labels: card.remove_label(label) # find comment for list comments_via_list = self.comment_from_list.get(card.list_id, []) comments_to_make += comments_via_list # move card card.change_board(to_list.board.id, to_list.id) # assign members for member in members_to_assign: card.assign(member) # label for label in labels_to_apply: try: card.add_label(label) except: pass # comment for comment in comments_to_make: card.comment(comment)
def run_task_copy(self, card: Card, to_list: trello.List): card_labels = card.labels if card_labels is None: card_labels = [] # find all labels need to apply after moving labels_to_apply: List[Label] = [] for label in card_labels: label_list = self.label_mapping.get(label, []) labels_to_apply += label_list labels_to_apply = set([x.id for x in labels_to_apply]) # find all members need to assign after moving members_to_assign: List[str] = [] for label in card_labels: member_list = self.member_via_label.get(label.id, []) members_to_assign += member_list members_to_assign = set(members_to_assign) # find all comments need to make after moving comments_to_make: List[str] = [] for label in card_labels: comment_list = self.comment_via_label.get(label.id, []) comments_to_make += comment_list # copy card new_card = copy_card(card, to_list, labels_to_apply, members_to_assign) # comments for comment in comments_to_make: new_card.comment(comment) if self.config.get('comment_original_card_share_link_to_copied_card', False): new_card.comment(card.short_url) card.comment(new_card.short_url) # remove mapping labels and add label via labels_to_change_with_label_mapping_labels if present labels_to_remove = [label for label in card_labels if label.id in self.label_to_list_mapping] change_label_mapping = self.config.get('labels_to_change_with_label_mapping_labels', {}) for label in labels_to_remove: card.remove_label(label) if change_label_mapping.get(label.id, None): try: card.add_label(Label(self.client, change_label_mapping.get(label.id, None), '')) except: pass