trello-bulk-card-creator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/trello-bulk +151 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 77b0b8491d39a6e92c2afb17641c850f57aceb7209603f8ecd3a221faa3b7ed8
|
4
|
+
data.tar.gz: b0a1f99af3a971ab57906c0d26230ed6a91c4e476916fdf634cb5729980cbe5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03e8a2627aab5afdf003672f331d094d71876f9c6bc66cc808f6f4ec6c2ffa8cae556701da2fab3c77a71d7a1cb5401bb7627398a630d559a58d59c51f612c06
|
7
|
+
data.tar.gz: 398cc17ed5f5c5fe9bc0a2bfa4d9174b1bfaf2b990205cf24f54d11a8fde41248b624d9b68045b57041e27c7220003679e4729dd43985fea4c7676edeb9c1908
|
data/trello-bulk
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'time'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'optparse'
|
7
|
+
require 'trello'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
def _get_board_id(boards, board_name)
|
11
|
+
# Get all open boards
|
12
|
+
open_boards = boards.reject(&:closed)
|
13
|
+
board = open_boards.select { |b| b.name == board_name }
|
14
|
+
|
15
|
+
if board.empty?
|
16
|
+
warn "#{APP_NAME}: failed to find a board named `#{board_name}`"
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
board[0].id # Assume name is unique so take the first match
|
21
|
+
end
|
22
|
+
|
23
|
+
def _get_list_id(board_id, list_name)
|
24
|
+
lists = Trello::Board.find(board_id).lists
|
25
|
+
list = lists.select { |l| l.name == list_name }
|
26
|
+
|
27
|
+
if list.empty?
|
28
|
+
warn "#{APP_NAME}: failed to find a list named `#{list_name}`"
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
list[0].id # Assume name is unique so take the first match
|
33
|
+
end
|
34
|
+
|
35
|
+
def _get_ids(user_handle, options)
|
36
|
+
id = OpenStruct.new
|
37
|
+
|
38
|
+
id.board = _get_board_id(user_handle.boards, options[:board])
|
39
|
+
id.list = _get_list_id(id.board, options[:list])
|
40
|
+
|
41
|
+
id
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_cards(card_set)
|
45
|
+
unless File.exist? card_set
|
46
|
+
warn "#{APP_NAME}: Failed to find `#{card_set}`"
|
47
|
+
exit 1
|
48
|
+
end
|
49
|
+
|
50
|
+
begin
|
51
|
+
yaml = YAML.safe_load(File.read(card_set))
|
52
|
+
rescue Psych::SyntaxError => e
|
53
|
+
warn "#{APP_NAME}: Failed to load YAML from `#{card_set}`: #{e.inspect}"
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
|
57
|
+
expand_cards(yaml['cards'])
|
58
|
+
end
|
59
|
+
|
60
|
+
def expand_cards(cards)
|
61
|
+
expanded_cards = []
|
62
|
+
|
63
|
+
cards.each do |card|
|
64
|
+
expanded = OpenStruct.new
|
65
|
+
|
66
|
+
# Allow future due dates, relative to when this script is run
|
67
|
+
if card.key? 'due'
|
68
|
+
future_date = Date.today + card['due'] # set the due date in the future
|
69
|
+
expanded.due_date = future_date.to_time.iso8601 # convert to ruby-trello required format
|
70
|
+
end
|
71
|
+
|
72
|
+
expanded.description = card['description']
|
73
|
+
expanded.title = card['title']
|
74
|
+
|
75
|
+
expanded_cards << expanded
|
76
|
+
end
|
77
|
+
|
78
|
+
expanded_cards
|
79
|
+
end
|
80
|
+
|
81
|
+
##############################################################
|
82
|
+
|
83
|
+
APP_NAME = File.basename $PROGRAM_NAME
|
84
|
+
|
85
|
+
%w[TRELLO_DEVELOPER_PUBLIC_KEY TRELLO_MEMBER_TOKEN].each do |variable|
|
86
|
+
unless ENV.key? variable
|
87
|
+
warn "#{APP_NAME} requires #{variable} to be set"
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
Trello.configure do |config|
|
93
|
+
config.developer_public_key = ENV['TRELLO_DEVELOPER_PUBLIC_KEY']
|
94
|
+
config.member_token = ENV['TRELLO_MEMBER_TOKEN']
|
95
|
+
end
|
96
|
+
|
97
|
+
options = {}
|
98
|
+
OptionParser.new do |opts|
|
99
|
+
opts.banner = "Usage: #{APP_NAME} --user dwilson --board 'Testy Board' --list TODO --cards card-sets/pip.yaml"
|
100
|
+
|
101
|
+
opts.on('-u USER', '--user USER', 'Trello username that owns the boards') do |v|
|
102
|
+
options[:user] = v
|
103
|
+
end
|
104
|
+
|
105
|
+
opts.on('-b BOARD', '--board BOARD', 'Trello board name') do |v|
|
106
|
+
options[:board] = v
|
107
|
+
end
|
108
|
+
|
109
|
+
opts.on('-l LIST', '--list LIST', 'Trello list / column name') do |v|
|
110
|
+
options[:list] = v
|
111
|
+
end
|
112
|
+
|
113
|
+
opts.on('-c CARD_FILE', '--cards CARD_FILE', 'YAML file containing the cards to create') do |v|
|
114
|
+
options[:cards] = v
|
115
|
+
end
|
116
|
+
|
117
|
+
opts.on('-r REPLACE', '--replace REPLACE', 'Text to replace in the cardset. Given in the format `original==replacement`') do |v|
|
118
|
+
options[:replace] = v
|
119
|
+
end
|
120
|
+
end.parse!
|
121
|
+
|
122
|
+
# Do the local actions before calling the Trello API
|
123
|
+
cards = load_cards(options[:cards])
|
124
|
+
|
125
|
+
user = Trello::Member.find(options[:user])
|
126
|
+
|
127
|
+
## Expand the text in the cards
|
128
|
+
if options[:replace]
|
129
|
+
original, replacement = options[:replace].split('==')
|
130
|
+
|
131
|
+
cards.each do |card|
|
132
|
+
card.title.gsub!(/#{original}/, replacement)
|
133
|
+
card.description.gsub!(/#{original}/, replacement)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
trello_ids = _get_ids(user, options)
|
138
|
+
|
139
|
+
# Sort the cards by title and then reverse them, this way the first card title
|
140
|
+
# alphabetically is added last, but then shows up in the UI first.
|
141
|
+
cards.sort_by!(&:title)
|
142
|
+
cards.reverse!
|
143
|
+
|
144
|
+
cards.each do |card|
|
145
|
+
Trello::Card.create(
|
146
|
+
list_id: trello_ids.list,
|
147
|
+
name: card.title,
|
148
|
+
desc: card.description,
|
149
|
+
due: card.due_date
|
150
|
+
)
|
151
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trello-bulk-card-creator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Wilson
|
8
|
+
autorequire:
|
9
|
+
bindir: "."
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-trello
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.0
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- dwilson@unixdaemon.net
|
36
|
+
executables:
|
37
|
+
- trello-bulk
|
38
|
+
extensions: []
|
39
|
+
extra_rdoc_files: []
|
40
|
+
files:
|
41
|
+
- "./trello-bulk"
|
42
|
+
homepage: https://github.com/deanwilson/trello-scripts/tree/master/trello-bulk
|
43
|
+
licenses:
|
44
|
+
- GPL-2.0
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.7.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: A trello bulk card creator.
|
66
|
+
test_files: []
|