Skip to content

Instantly share code, notes, and snippets.

@BuonOmo
Last active November 5, 2020 17:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BuonOmo/1f994280fb71392c0a4b00c67bad0436 to your computer and use it in GitHub Desktop.
Save BuonOmo/1f994280fb71392c0a4b00c67bad0436 to your computer and use it in GitHub Desktop.
Archive trello columns all at once (using web, or api)
function timeout(time = 200) {
return new Promise((resolve) => {
setTimeout(resolve, time);
})
}
/**
* Prepare archiving, making sure columns are the correct ones.
*
* @param contents every column names to treat (may be only a part)
* @return dom elements corresponding to columns.
*
* @example
* selectColumns('DONE ')
*/
function selectColumns(...contents) {
columns = contents.flatMap(content =>
$(`.js-list:has(h2:contains(${content}))`).toArray()
)
console.table(columns.map(column => ({ element: column, title: $('.list-header h2', column).text() })))
return columns
}
/**
* Archive columns to the tech-archive board.
*
* @param columns the result of `selectColumns`
*
* @example
* let columns = selectColumns('DONE ')
* archive(columns)
*/
async function archive(columns) {
for (const column of columns) {
$('.list-header-extras-menu.js-open-list-menu', column).click()
await timeout()
$('a:contains(Move List)').click()
await timeout()
// here ze select a board named after archive. But you could also directly
// use the archive button.
$('.js-select-board')[0].value = $('option:contains(ARCHIVE)')[0].value
let select = $('.js-select-list-pos')[0]
select.value = select.firstChild.value
// select.value = 1
$('.pop-over form').submit()
await timeout()
}
}
# frozen_string_literal: true
require "io/console"
require "trello"
class Trello::List < Trello::BasicData
def move_to_board(board)
board = board.id unless board.is_a?(String)
client.put("/lists/#{id}/idBoard", value: board)
end
end
Trello.configure do |config|
# https://trello.com/app-key
config.developer_public_key = ENV["TRELLO_PUBLIC_KEY"]
config.member_token = ENV["TRELLO_TOKEN"]
end
all_boards = Trello::Board.all
archive = all_boards.detect { |board| board.name == "TECH - ARCHIVES" }
chouettes = all_boards.detect { |board| board.name == "TECH - CHOUETTES" }
lists_to_move = chouettes.lists.select { |list| list.name.match?(/^DONE /) }
puts <<~TEXT
Will move:
#{lists_to_move.map { |list| "- " + list.name } * "\n"}
OK ? [yN]
TEXT
exit 1 unless STDIN.getch == "y"
lists_to_move.each do |list|
# Cannot run in parallel, they need a board lock :/
list.move_to_board(archive)
puts "Moved " + list.name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment