Skip to content

Commit

Permalink
feat: move create folders cmd to board
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyqu committed Jun 14, 2024
1 parent 6f4fdc2 commit d2e56e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/focalboard/focalboard_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ def get_custom_fields(self, card_id: str) -> objects.CardCustomFields:
card_fields._data = card_labels
return card_fields

def set_card_custom_field(self, card_id, field_alias, value):
board_id = self.board_id
field_id = self.custom_fields_config[field_alias]
data = {
"updatedFields": {
"properties": {
field_id: value
}
}
}
code = self._make_patch_request(
f"api/v2/boards/{board_id}/blocks/{card_id}", payload=data
)
logger.debug(f"set_card_custom_field: {code}")

def get_members(self, board_id) -> List[objects.TrelloMember]:
_, data = self._make_request(f"api/v2/boards/{board_id}/members")
members = []
Expand Down Expand Up @@ -375,3 +390,10 @@ def _make_request(self, uri, payload={}):
)
logger.debug(f"{response.url}")
return response.status_code, response.json()

def _make_patch_request(self, uri, payload={}):
response = requests.patch(
urljoin(self.url, uri), params=payload, headers=self.headers
)
logger.debug(f"{response.url}")
return response.status_code, response.json()
30 changes: 22 additions & 8 deletions src/jobs/create_folders_for_illustrators_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ def _create_folders(
list_aliases: List[TrelloListAlias],
) -> List[Tuple[IllustratorFolderState, str]]:
logger.info("Started counting:")
list_ids = app_context.trello_client.get_list_id_from_aliases(list_aliases)
cards = app_context.trello_client.get_cards(list_ids)
if app_context.trello_client.deprecated:
list_ids = app_context.focalboard_client.get_list_id_from_aliases(list_aliases)
cards = app_context.focalboard_client.get_cards(list_ids)
else:
list_ids = app_context.trello_client.get_list_id_from_aliases(list_aliases)
cards = app_context.trello_client.get_cards(list_ids)

parse_failure_counter = 0
result = []
Expand All @@ -68,7 +72,10 @@ def _create_folders(
parse_failure_counter += 1
continue

card_fields = app_context.trello_client.get_custom_fields(card.id)
if app_context.trello_client.deprecated:
card_fields = app_context.focalboard_client.get_custom_fields(card.id)
else:
card_fields = app_context.trello_client.get_custom_fields(card.id)

label_names = [
label.name
Expand Down Expand Up @@ -113,11 +120,18 @@ def _create_folders(
logger.info(
f"Trying to put {card_fields.cover} as cover field for {card.url}"
)
app_context.trello_client.set_card_custom_field(
card.id,
TrelloCustomFieldTypeAlias.COVER,
card_fields.cover,
)
if app_context.trello_client.deprecated:
app_context.focalboard_client.set_card_custom_field(
card.id,
TrelloCustomFieldTypeAlias.COVER,
card_fields.cover,
)
else:
app_context.trello_client.set_card_custom_field(
card.id,
TrelloCustomFieldTypeAlias.COVER,
card_fields.cover,
)
cover = load(
"create_folders_for_illustrators_job__cover",
url=card_fields.cover,
Expand Down

0 comments on commit d2e56e7

Please sign in to comment.