Skip to content

Instantly share code, notes, and snippets.

@afomi
Created February 20, 2016 16:22
Show Gist options
  • Save afomi/3c086c048300b3b3dcb0 to your computer and use it in GitHub Desktop.
Save afomi/3c086c048300b3b3dcb0 to your computer and use it in GitHub Desktop.
Create Cards from one Trello Card's Activities
require 'ruby-trello'
# Also requires your Trello Keys (see the .gem docs)
board_id = "ENTER-YOUR-OWN-BOARD-ID"
# Getting actions from one Card
@board = Trello::Board.find(board_id)
@lists = @board.lists
@list = @lists.first
@cards = @list.cards
@card = @cards.first
actions = @card.actions
# Creating an array from the Actions
array = []
actions.each do |a|
array << a.attributes[:data]["text"]
end
array.compact!
array
# Writing Actions from the Array
@board = Trello::Board.find(board_id)
@list = @board.lists.select { |l| l.name == "NAME-OF-YOUR-LIST" }.first
# reversed, because Actions are sorted DESC
# Newly created Cards go on top
array.reverse.each do |za|
Trello::Card.create(list_id: @list.id, name: za)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment