3llo 1.0.0.pre.rc.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -0
- data/.rubocop.yml +113 -0
- data/3llo.gemspec +9 -9
- data/CHANGELOG.md +2 -0
- data/Gemfile +3 -3
- data/Rakefile +2 -2
- data/bin/3llo +4 -4
- data/lib/3llo.rb +14 -14
- data/lib/3llo/api.rb +6 -6
- data/lib/3llo/api/board.rb +13 -29
- data/lib/3llo/api/card.rb +79 -102
- data/lib/3llo/api/checklist.rb +26 -48
- data/lib/3llo/api/list.rb +12 -23
- data/lib/3llo/api/token.rb +2 -2
- data/lib/3llo/api/user.rb +8 -32
- data/lib/3llo/application.rb +32 -22
- data/lib/3llo/command.rb +43 -14
- data/lib/3llo/command/board.rb +6 -6
- data/lib/3llo/command/card.rb +55 -53
- data/lib/3llo/command/card/assign.rb +3 -3
- data/lib/3llo/command/card/edit.rb +33 -0
- data/lib/3llo/command/card/move.rb +3 -3
- data/lib/3llo/command/card/self_assign.rb +2 -2
- data/lib/3llo/command/list.rb +9 -9
- data/lib/3llo/controller.rb +10 -11
- data/lib/3llo/entities.rb +1 -1
- data/lib/3llo/interface.rb +3 -2
- data/lib/3llo/registry.rb +3 -4
- data/lib/3llo/remote_server.rb +97 -0
- data/lib/3llo/utils.rb +10 -0
- data/lib/3llo/version.rb +1 -1
- data/lib/3llo/view.rb +11 -11
- data/lib/3llo/view/board/list.rb +2 -2
- data/lib/3llo/view/card/help.rb +1 -1
- metadata +21 -6
- data/lib/3llo/http/client.rb +0 -95
- data/lib/3llo/http/request_error.rb +0 -18
data/lib/3llo/api/checklist.rb
CHANGED
@@ -4,20 +4,14 @@ module Tr3llo
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def create(card_id, data)
|
7
|
-
|
7
|
+
req_path = Utils.build_req_path("/cards/#{card_id}/checklists")
|
8
8
|
|
9
|
-
client.post(
|
9
|
+
client.post(req_path, {}, data)
|
10
10
|
end
|
11
11
|
|
12
12
|
def get(checklist_id)
|
13
|
-
|
14
|
-
|
15
|
-
client.get(
|
16
|
-
"/checklists/#{checklist_id}",
|
17
|
-
key: api_key,
|
18
|
-
token: api_token
|
19
|
-
)
|
20
|
-
)
|
13
|
+
req_path = Utils.build_req_path("/checklists/#{checklist_id}")
|
14
|
+
payload = client.get(req_path, {})
|
21
15
|
|
22
16
|
checklist_id, checklist_name = payload.fetch_values("id", "name")
|
23
17
|
checklist_shortcut = Entities.make_shortcut(:checklist, checklist_id)
|
@@ -31,24 +25,20 @@ module Tr3llo
|
|
31
25
|
end
|
32
26
|
|
33
27
|
def update(checklist_id, data)
|
34
|
-
|
28
|
+
req_path = Utils.build_req_path("/checklists/#{checklist_id}")
|
35
29
|
|
36
|
-
client.put(
|
30
|
+
client.put(req_path, {}, data)
|
37
31
|
end
|
38
32
|
|
39
33
|
def delete(checklist_id)
|
40
|
-
|
34
|
+
req_path = Utils.build_req_path("/checklists/#{checklist_id}")
|
35
|
+
|
36
|
+
client.delete(req_path, {}, {})
|
41
37
|
end
|
42
38
|
|
43
39
|
def list_by_card_id(card_id)
|
44
|
-
|
45
|
-
|
46
|
-
client.get(
|
47
|
-
"/cards/#{card_id}/checklists",
|
48
|
-
key: api_key,
|
49
|
-
token: api_token
|
50
|
-
)
|
51
|
-
)
|
40
|
+
req_path = Utils.build_req_path("/cards/#{card_id}/checklists")
|
41
|
+
payload = client.get(req_path, {})
|
52
42
|
|
53
43
|
payload.map do |checklist_payload|
|
54
44
|
checklist_id, checklist_name = checklist_payload.fetch_values("id", "name")
|
@@ -56,8 +46,8 @@ module Tr3llo
|
|
56
46
|
|
57
47
|
items =
|
58
48
|
checklist_payload
|
59
|
-
|
60
|
-
|
49
|
+
.fetch("checkItems", [])
|
50
|
+
.map do |item_payload|
|
61
51
|
item_id, item_name, item_state = item_payload.fetch_values("id", "name", "state")
|
62
52
|
item_shortcut = Entities.make_shortcut(:check_item, item_id)
|
63
53
|
|
@@ -74,14 +64,8 @@ module Tr3llo
|
|
74
64
|
end
|
75
65
|
|
76
66
|
def get_item(card_id, item_id)
|
77
|
-
|
78
|
-
|
79
|
-
client.get(
|
80
|
-
"/cards/#{card_id}/checkItem/#{item_id}",
|
81
|
-
key: api_key,
|
82
|
-
token: api_token
|
83
|
-
)
|
84
|
-
)
|
67
|
+
req_path = Utils.build_req_path("/cards/#{card_id}/checkItem/#{item_id}")
|
68
|
+
item_payload = client.get(req_path, {})
|
85
69
|
|
86
70
|
item_id, item_name, item_state = item_payload.fetch_values("id", "name", "state")
|
87
71
|
item_shortcut = Entities.make_shortcut(:check_item, item_id)
|
@@ -90,35 +74,29 @@ module Tr3llo
|
|
90
74
|
end
|
91
75
|
|
92
76
|
def create_item(checklist_id, name)
|
93
|
-
|
94
|
-
|
95
|
-
key: api_key,
|
96
|
-
token: api_token,
|
77
|
+
req_path = Utils.build_req_path("/checklists/#{checklist_id}/checkItems")
|
78
|
+
payload = {
|
97
79
|
name: name,
|
98
80
|
pos: "bottom",
|
99
|
-
state: false
|
100
|
-
|
81
|
+
state: "false"
|
82
|
+
}
|
83
|
+
|
84
|
+
client.post(req_path, {}, payload)
|
101
85
|
end
|
102
86
|
|
103
87
|
def update_item(card_id, check_item_id, data)
|
104
|
-
|
88
|
+
req_path = Utils.build_req_path("/cards/#{card_id}/checkItem/#{check_item_id}")
|
105
89
|
|
106
|
-
client.put(
|
90
|
+
client.put(req_path, {}, data)
|
107
91
|
end
|
108
92
|
|
109
93
|
def delete_item(card_id, item_id)
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
94
|
+
req_path = Utils.build_req_path("/cards/#{card_id}/checkItem/#{item_id}")
|
114
95
|
|
115
|
-
|
116
|
-
Application.fetch_configuration!().api_key
|
96
|
+
client.delete(req_path, {}, {})
|
117
97
|
end
|
118
98
|
|
119
|
-
|
120
|
-
Application.fetch_configuration!().api_token
|
121
|
-
end
|
99
|
+
private
|
122
100
|
|
123
101
|
def client
|
124
102
|
Application.fetch_client!()
|
data/lib/3llo/api/list.rb
CHANGED
@@ -4,26 +4,23 @@ module Tr3llo
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def find_all_by_board(board_id)
|
7
|
-
|
8
|
-
|
7
|
+
req_path =
|
8
|
+
Utils.build_req_path(
|
9
9
|
"/boards/#{board_id}/lists",
|
10
|
-
list
|
11
|
-
key: api_key,
|
12
|
-
token: api_token
|
10
|
+
{"list" => "true"}
|
13
11
|
)
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
|
13
|
+
client
|
14
|
+
.get(req_path, {})
|
15
|
+
.map do |list_payload|
|
16
|
+
make_struct(list_payload)
|
17
|
+
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def archive_cards(list_id)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
key: api_key,
|
24
|
-
token: api_token
|
25
|
-
)
|
26
|
-
)
|
21
|
+
req_path = Utils.build_req_path("/lists/#{list_id}/archiveAllCards")
|
22
|
+
|
23
|
+
client.post(req_path, {}, {})
|
27
24
|
end
|
28
25
|
|
29
26
|
private
|
@@ -38,14 +35,6 @@ module Tr3llo
|
|
38
35
|
def client
|
39
36
|
Application.fetch_client!()
|
40
37
|
end
|
41
|
-
|
42
|
-
def api_key
|
43
|
-
Application.fetch_configuration!().api_key
|
44
|
-
end
|
45
|
-
|
46
|
-
def api_token
|
47
|
-
Application.fetch_configuration!().api_token
|
48
|
-
end
|
49
38
|
end
|
50
39
|
end
|
51
40
|
end
|
data/lib/3llo/api/token.rb
CHANGED
data/lib/3llo/api/user.rb
CHANGED
@@ -4,31 +4,19 @@ module Tr3llo
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def find(user_id)
|
7
|
-
|
7
|
+
client = Application.fetch_client!()
|
8
|
+
req_path = Utils.build_req_path("/members/#{user_id}")
|
8
9
|
|
9
|
-
make_struct(
|
10
|
-
JSON.parse(
|
11
|
-
client.get(
|
12
|
-
url,
|
13
|
-
key: key,
|
14
|
-
token: token
|
15
|
-
)
|
16
|
-
)
|
17
|
-
)
|
10
|
+
make_struct(client.get(req_path, {}))
|
18
11
|
end
|
19
12
|
|
20
13
|
def find_all_by_board(board_id)
|
21
|
-
|
14
|
+
client = Application.fetch_client!()
|
15
|
+
req_path = Utils.build_req_path("/board/#{board_id}/members")
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
key: key,
|
27
|
-
token: token
|
28
|
-
)
|
29
|
-
).map do |user_payload|
|
30
|
-
make_struct(user_payload)
|
31
|
-
end
|
17
|
+
client
|
18
|
+
.get(req_path, {})
|
19
|
+
.map { |user_payload| make_struct(user_payload) }
|
32
20
|
end
|
33
21
|
|
34
22
|
private
|
@@ -39,18 +27,6 @@ module Tr3llo
|
|
39
27
|
|
40
28
|
Entities::User.new(id, shortcut, username)
|
41
29
|
end
|
42
|
-
|
43
|
-
def key
|
44
|
-
Application.fetch_configuration!().api_key
|
45
|
-
end
|
46
|
-
|
47
|
-
def token
|
48
|
-
Application.fetch_configuration!().api_token
|
49
|
-
end
|
50
|
-
|
51
|
-
def client
|
52
|
-
Application.fetch_client!()
|
53
|
-
end
|
54
30
|
end
|
55
31
|
end
|
56
32
|
end
|
data/lib/3llo/application.rb
CHANGED
@@ -2,10 +2,10 @@ module Tr3llo
|
|
2
2
|
module Application
|
3
3
|
extend self
|
4
4
|
|
5
|
-
DEFAULT_CONFIG_FILE_PATH = "~/.3llo.config.json"
|
5
|
+
DEFAULT_CONFIG_FILE_PATH = "~/.3llo.config.json".freeze
|
6
6
|
|
7
7
|
def start(args)
|
8
|
-
$
|
8
|
+
$application = Container.new()
|
9
9
|
|
10
10
|
interface = register_interface!()
|
11
11
|
option_parser = build_option_parser()
|
@@ -13,12 +13,12 @@ module Tr3llo
|
|
13
13
|
|
14
14
|
options = parse_cli_args!(option_parser, args)
|
15
15
|
|
16
|
-
if options.
|
16
|
+
if options.has_key?(:help)
|
17
17
|
execute_help!(option_parser, interface)
|
18
18
|
exit
|
19
19
|
end
|
20
20
|
|
21
|
-
if options.
|
21
|
+
if options.has_key?(:configure)
|
22
22
|
execute_configure!(interface)
|
23
23
|
exit
|
24
24
|
end
|
@@ -28,7 +28,7 @@ module Tr3llo
|
|
28
28
|
|
29
29
|
print_help!(interface)
|
30
30
|
|
31
|
-
load_configuration!(config_file
|
31
|
+
load_configuration!(config_file)
|
32
32
|
register_registry!()
|
33
33
|
|
34
34
|
load_user!(interface)
|
@@ -64,7 +64,7 @@ module Tr3llo
|
|
64
64
|
parser.parse!(args, into: options)
|
65
65
|
|
66
66
|
options
|
67
|
-
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption
|
67
|
+
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption
|
68
68
|
{}
|
69
69
|
end
|
70
70
|
|
@@ -85,19 +85,21 @@ module Tr3llo
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def register_api_client!()
|
88
|
-
|
88
|
+
remote_server = Tr3llo::RemoteServer.new("https://api.trello.com/1")
|
89
|
+
|
90
|
+
$application.register(:api_client, remote_server)
|
89
91
|
end
|
90
92
|
|
91
93
|
def register_interface!()
|
92
94
|
prompt = TTY::Prompt.new()
|
93
|
-
$
|
95
|
+
$application.register(:interface, Tr3llo::Interface.new(prompt, $stdout))
|
94
96
|
end
|
95
97
|
|
96
|
-
def load_configuration!(config_file
|
98
|
+
def load_configuration!(config_file)
|
97
99
|
config_path = File.expand_path(config_file)
|
98
100
|
|
99
101
|
config =
|
100
|
-
if File.
|
102
|
+
if File.exist?(config_path)
|
101
103
|
JSON.load(File.read(config_path))
|
102
104
|
else
|
103
105
|
{}
|
@@ -110,17 +112,25 @@ module Tr3llo
|
|
110
112
|
|
111
113
|
configuration.finalize!()
|
112
114
|
|
113
|
-
$
|
115
|
+
$application.register(:configuration, configuration)
|
114
116
|
rescue KeyError => exception
|
115
117
|
command_string = "3llo --configure"
|
116
|
-
|
118
|
+
|
119
|
+
abort(
|
120
|
+
Utils.paint(
|
121
|
+
"#{exception.key.inspect} has not been configured. " \
|
122
|
+
"Please run #{command_string.inspect} to set up configuration.",
|
123
|
+
"red"
|
124
|
+
)
|
125
|
+
)
|
117
126
|
end
|
118
127
|
|
119
128
|
def get_config_entry(config, key, env_key)
|
120
129
|
config.fetch(key) do
|
121
130
|
if ENV.has_key?(env_key)
|
122
131
|
Utils.deprecate!(
|
123
|
-
"Setting #{env_key.inspect} as an environment variable is deprecated.
|
132
|
+
"Setting #{env_key.inspect} as an environment variable is deprecated. " \
|
133
|
+
"It will be removed in the future versions of 3llo. Please use config file instead."
|
124
134
|
)
|
125
135
|
|
126
136
|
ENV.fetch(env_key)
|
@@ -131,37 +141,37 @@ module Tr3llo
|
|
131
141
|
end
|
132
142
|
|
133
143
|
def register_registry!()
|
134
|
-
$
|
144
|
+
$application.register(:registry, Tr3llo::Registry.new)
|
135
145
|
end
|
136
146
|
|
137
147
|
def register_board!(board)
|
138
|
-
$
|
148
|
+
$application.register(:board, board)
|
139
149
|
end
|
140
150
|
|
141
151
|
def fetch_board!()
|
142
|
-
$
|
152
|
+
$application.resolve(:board)
|
143
153
|
rescue ::Container::KeyNotFoundError
|
144
154
|
raise BoardNotSelectedError
|
145
155
|
end
|
146
156
|
|
147
157
|
def fetch_user!()
|
148
|
-
$
|
158
|
+
$application.resolve(:user)
|
149
159
|
end
|
150
160
|
|
151
161
|
def fetch_configuration!()
|
152
|
-
$
|
162
|
+
$application.resolve(:configuration)
|
153
163
|
end
|
154
164
|
|
155
165
|
def fetch_interface!()
|
156
|
-
$
|
166
|
+
$application.resolve(:interface)
|
157
167
|
end
|
158
168
|
|
159
169
|
def fetch_client!()
|
160
|
-
$
|
170
|
+
$application.resolve(:api_client)
|
161
171
|
end
|
162
172
|
|
163
173
|
def fetch_registry!()
|
164
|
-
$
|
174
|
+
$application.resolve(:registry)
|
165
175
|
end
|
166
176
|
|
167
177
|
def load_user!(interface)
|
@@ -172,7 +182,7 @@ module Tr3llo
|
|
172
182
|
interface.puts("You're logged in as #{decorated_username}")
|
173
183
|
end
|
174
184
|
|
175
|
-
$
|
185
|
+
$application.register(:user, user)
|
176
186
|
end
|
177
187
|
end
|
178
188
|
end
|
data/lib/3llo/command.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "3llo/command/board"
|
2
|
+
require "3llo/command/card"
|
3
|
+
require "3llo/command/list"
|
4
|
+
require "3llo/command/help"
|
5
|
+
require "3llo/command/exit"
|
6
|
+
require "3llo/command/invalid"
|
7
7
|
|
8
8
|
module Tr3llo
|
9
9
|
module Command
|
@@ -13,35 +13,64 @@ module Tr3llo
|
|
13
13
|
build_command(command_buffer)
|
14
14
|
end
|
15
15
|
|
16
|
+
def generate_suggestions(buffer, command_buffer)
|
17
|
+
commands = {
|
18
|
+
"board" => ["list", "select"],
|
19
|
+
"list" => %w[list cards archive-cards],
|
20
|
+
"card" => %w[
|
21
|
+
list show add edit archive list-mine move
|
22
|
+
comment comments self-assign assign
|
23
|
+
add-checklist edit-checklist remove-checklist
|
24
|
+
add-item edit-item remote-item check-item uncheck-item
|
25
|
+
],
|
26
|
+
"help" => [],
|
27
|
+
"exit" => []
|
28
|
+
}
|
29
|
+
|
30
|
+
command, _subcommand, _args = parse_command(command_buffer)
|
31
|
+
|
32
|
+
if commands.has_key?(command)
|
33
|
+
subcommands = commands.fetch(command)
|
34
|
+
|
35
|
+
subcommands
|
36
|
+
.grep(/^#{Regexp.escape(buffer)}/)
|
37
|
+
.reject { |suggestion| suggestion == buffer }
|
38
|
+
else
|
39
|
+
commands.keys.grep(/^#{Regexp.escape(buffer)}/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
16
43
|
private
|
17
44
|
|
18
45
|
def build_command(command_string)
|
19
46
|
command, subcommand, *args = parse_command(command_string)
|
20
47
|
|
21
48
|
case command
|
22
|
-
when
|
49
|
+
when "board"
|
23
50
|
Command::Board.execute(subcommand, args)
|
24
|
-
when
|
51
|
+
when "card"
|
25
52
|
Command::Card.execute(subcommand, args)
|
26
|
-
when
|
53
|
+
when "list"
|
27
54
|
Command::List.execute(subcommand, args)
|
28
|
-
when
|
55
|
+
when "help"
|
29
56
|
Command::Help.execute()
|
30
|
-
when
|
57
|
+
when "exit"
|
31
58
|
Command::Exit.execute()
|
32
59
|
else
|
33
60
|
if command
|
34
|
-
raise InvalidCommandError.new(
|
61
|
+
raise InvalidCommandError.new(
|
62
|
+
"#{command.inspect} is not a valid command. Run #{"help".inspect} to display the document."
|
63
|
+
)
|
35
64
|
else
|
36
65
|
raise InvalidCommandError.new("command is missing")
|
37
66
|
end
|
38
67
|
end
|
39
|
-
rescue InvalidCommandError => exception
|
68
|
+
rescue InvalidCommandError, RemoteServer::RequestError => exception
|
40
69
|
Command::Invalid.execute(exception.message)
|
41
70
|
end
|
42
71
|
|
43
72
|
def parse_command(command_string)
|
44
|
-
command_string.strip.split(
|
73
|
+
command_string.strip.split(" ").map(&:strip)
|
45
74
|
end
|
46
75
|
end
|
47
76
|
end
|