lita-trello-lists 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/.gitignore +17 -0
- data/Gemfile +3 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/lita-trello-lists.rb +12 -0
- data/lib/lita/handlers/trello_lists.rb +139 -0
- data/lita-trello-lists.gemspec +24 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/trello_lists_spec.rb +48 -0
- data/spec/spec_helper.rb +6 -0
- data/templates/.gitkeep +0 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5589affaa09d28ead829b122e3a4acef7ee1b31
|
4
|
+
data.tar.gz: daa551cfd3916ab97f3c766fee20e939e9f5db2a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e44ab14419499e9a1a48dd279f88e8575d6b2c08953b058c4e2bc09e62dfdd882b2ad16de119371d42076c80d938e8624febbe6fe0afe791982f833f6d0b2c60
|
7
|
+
data.tar.gz: f042a9f7f9b94d2154c0c2d3c588b727b7a8bd2cae89ad07879bdc7c91199d99f0176691dc7da4097b618a92f42f1fa6fb0abbdda91b3f19d4bd04d7168089ef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# lita-trello-lists
|
2
|
+
|
3
|
+
This is a Lita handler for displaying your Trello lists through Lita.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add lita-trello-lists to your Lita instance's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "lita-trello-lists"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
You will need to set at least one configuration variable:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
lita.handlers.trello_lists.boards = ['123456', 'abcsfgf']
|
19
|
+
```
|
20
|
+
|
21
|
+
You can find the ID of one of your boards through its URL.
|
22
|
+
|
23
|
+
Additionally, if your boards are private, you will need to supply your Trello API key and a token. You can find out how to get these things through the [Trello API documentation](https://trello.com/docs/).
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
lita.handlers.trello_lists.key = "2345n32b42oijkn3b24j34jn34"
|
27
|
+
lita.handlers.trello_lists.token = "sahfiu23kjriuejknr239r0ofiwjben023ork2inw"
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Say you have a board names "Engineering" and a list in it called "In Progress". The following are all equivalent:
|
33
|
+
|
34
|
+
```
|
35
|
+
> @robot trello list in progress
|
36
|
+
> @robot trello list progress in engineering
|
37
|
+
> @robot trello list in progress in eng
|
38
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require "lita/handlers/trello_lists"
|
8
|
+
|
9
|
+
Lita::Handlers::TrelloLists.template_root File.expand_path(
|
10
|
+
File.join("..", "..", "templates"),
|
11
|
+
__FILE__
|
12
|
+
)
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class TrelloLists < Handler
|
4
|
+
config :key, type: String, required: false
|
5
|
+
config :token, type: String, required: false
|
6
|
+
config :boards, type: Array, required: true
|
7
|
+
|
8
|
+
TRELLO_API_URL = "https://api.trello.com/1"
|
9
|
+
|
10
|
+
route(/^trello list (.*)$/, :list_summary, command: true, help: {
|
11
|
+
"trello list LIST NAME" => "Show a summary of the cards in a certain list on Trello."
|
12
|
+
})
|
13
|
+
|
14
|
+
route(/^trello list (.+) in (.+)?$/, :list_summary, command: true, help: {
|
15
|
+
"trello list LIST NAME in BOARD NAME" => "Show a summary of the cards in a list on a specific board on Trello."
|
16
|
+
})
|
17
|
+
|
18
|
+
def list_summary(message)
|
19
|
+
list_name_fragment = message.matches[0][0]
|
20
|
+
board_name_fragment = message.matches[0][1]
|
21
|
+
|
22
|
+
board_name = find_board_from_fragment(board_name_fragment)
|
23
|
+
list_name = find_list_from_fragment(list_name_fragment, board_name)
|
24
|
+
|
25
|
+
if board_name_fragment && board_name.nil?
|
26
|
+
message.reply("We couldn't find a board from the name \"#{board_name}\".")
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
if list_name.nil?
|
31
|
+
message.reply("We couldn't find a list from the name \"#{list_name}\".")
|
32
|
+
return
|
33
|
+
end
|
34
|
+
|
35
|
+
if board_name.nil? && list_exists_in_multiple_boards?(list_name)
|
36
|
+
response = "The list \"#{list_name}\" appears in multiple Trello boards. Try this:\n"
|
37
|
+
response += "> everbot trello list #{list_name_fragment} in BOARD NAME"
|
38
|
+
message.reply(response)
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
response = "**Cards in #{list_name}:** \n"
|
43
|
+
response += get_cards_for(list_name, board_name).map do |card|
|
44
|
+
members = card[:members].map { |m| " #{m}\n" }
|
45
|
+
[
|
46
|
+
"- _#{card[:name]}_",
|
47
|
+
" Assigned To:",
|
48
|
+
card[:members].map { |m| " #{m}" }
|
49
|
+
].flatten.join("\n")
|
50
|
+
end.join("\n\n")
|
51
|
+
message.reply(response)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_cards_for(list, board)
|
55
|
+
possible_lists = board ? lists_in_board(board) : lists_in_all_boards
|
56
|
+
list_id = possible_lists.select { |l| l["name"] == list }.first["id"]
|
57
|
+
|
58
|
+
cards = trello_get("/lists/#{list_id}", cards: "open")["cards"]
|
59
|
+
cards.map do |card|
|
60
|
+
{
|
61
|
+
members: card["idMembers"].map { |id| trello_get("/members/#{id}")["fullName"] },
|
62
|
+
name: card["name"],
|
63
|
+
url: card["shortUrl"]
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def list_exists_in_multiple_boards?(fragment)
|
69
|
+
list_name = best_match_in_array(fragment, all_list_names)
|
70
|
+
all_list_names.select { |name| name == list_name }.count > 1
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_list_from_fragment(fragment, board)
|
74
|
+
list_names = if board
|
75
|
+
lists_in_board(board).map { |list| list["name"] }
|
76
|
+
else
|
77
|
+
all_list_names
|
78
|
+
end
|
79
|
+
|
80
|
+
best_match_in_array(fragment, list_names)
|
81
|
+
end
|
82
|
+
|
83
|
+
def find_board_from_fragment(fragment)
|
84
|
+
best_match_in_array(fragment, all_board_names)
|
85
|
+
end
|
86
|
+
|
87
|
+
def best_match_in_array(fragment, collection)
|
88
|
+
findings = collection.map do |thing|
|
89
|
+
match = thing[/#{fragment}/i]
|
90
|
+
|
91
|
+
length_of_match = match ? match.length : 0
|
92
|
+
|
93
|
+
[length_of_match, thing]
|
94
|
+
end.to_h
|
95
|
+
|
96
|
+
findings[findings.keys.sort.last] unless findings.keys.all?(&:zero?)
|
97
|
+
end
|
98
|
+
|
99
|
+
def lists_in_all_boards
|
100
|
+
boards.map { |board| board["lists"] }.flatten
|
101
|
+
end
|
102
|
+
|
103
|
+
def lists_in_board(board_name)
|
104
|
+
boards.select { |board| board["name"] == board_name }.first["lists"]
|
105
|
+
end
|
106
|
+
|
107
|
+
def all_board_names
|
108
|
+
boards.map { |board| board["name"] }
|
109
|
+
end
|
110
|
+
|
111
|
+
def all_list_names
|
112
|
+
boards.map do |board|
|
113
|
+
board["lists"].map { |list| list["name"] }
|
114
|
+
end.flatten
|
115
|
+
end
|
116
|
+
|
117
|
+
def boards
|
118
|
+
if @cached_data.nil? || (Time.now.sec - @last_access.sec) >= 5
|
119
|
+
@cached_data = config.boards.map do |board_id|
|
120
|
+
trello_get("/boards/#{board_id}", lists: "open")
|
121
|
+
end
|
122
|
+
@last_access = Time.now
|
123
|
+
end
|
124
|
+
@cached_data
|
125
|
+
end
|
126
|
+
|
127
|
+
def trello_get(url, params={})
|
128
|
+
params.merge!({
|
129
|
+
key: config.key,
|
130
|
+
token: config.token
|
131
|
+
})
|
132
|
+
|
133
|
+
MultiJson.load(http.get(TRELLO_API_URL + url, params).body)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
Lita.register_handler(TrelloLists)
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-trello-lists"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["Taylor Lapeyre"]
|
5
|
+
spec.email = ["taylorlapeyre@gmail.com"]
|
6
|
+
spec.description = "Display your Trello lists through Lita."
|
7
|
+
spec.summary = "Display your Trello lists through Lita."
|
8
|
+
spec.homepage = "https://github.com/taylorlapeyre/lita-trello-lists"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", ">= 4.3"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "pry-byebug"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rack-test"
|
23
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
24
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::TrelloLists, lita_handler: true do
|
4
|
+
before do
|
5
|
+
# Trello's "welcome" boards
|
6
|
+
Lita.config.handlers.trello_lists.boards = ["bKbdmCKB", "9dnaRkNt", "VVPQBpZE"]
|
7
|
+
end
|
8
|
+
|
9
|
+
it { is_expected.to route_command("trello list Basics").to(:list_summary) }
|
10
|
+
it { is_expected.to route_command("trello list Basics Things").to(:list_summary) }
|
11
|
+
it { is_expected.to route_command("trello list Basics in Welcome Board").to(:list_summary) }
|
12
|
+
|
13
|
+
it "responds with a summary when given a list name" do
|
14
|
+
send_command "trello list Basics"
|
15
|
+
expect(replies).to_not be_empty
|
16
|
+
expect(replies.last).to match /Welcome to Trello/
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can list the cards of a list in a specific board" do
|
20
|
+
send_command "trello list Getting Started in How to Use Trello for Android"
|
21
|
+
expect(replies).to_not be_empty
|
22
|
+
expect(replies.last).to match /Tap on a card/
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can find a list with a partial string match" do
|
26
|
+
send_command "trello list interm"
|
27
|
+
expect(replies).to_not be_empty
|
28
|
+
expect(replies.last).to match /Intermediate/
|
29
|
+
end
|
30
|
+
|
31
|
+
it "responds with a helpful message when the list is in multiple boards" do
|
32
|
+
send_command "trello list Getting Started"
|
33
|
+
expect(replies).to_not be_empty
|
34
|
+
expect(replies.last).to match /appears in multiple Trello boards/
|
35
|
+
end
|
36
|
+
|
37
|
+
it "responds with a helpful message when the list isn't found" do
|
38
|
+
send_command "trello list foobar"
|
39
|
+
expect(replies).to_not be_empty
|
40
|
+
expect(replies.last).to match /We couldn't find a list/
|
41
|
+
end
|
42
|
+
|
43
|
+
it "responds with a helpful message when the board isn't found" do
|
44
|
+
send_command "trello list Basics in Foobar"
|
45
|
+
expect(replies).to_not be_empty
|
46
|
+
expect(replies.last).to match /We couldn't find a board/
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require "lita-trello-lists"
|
2
|
+
require "lita/rspec"
|
3
|
+
|
4
|
+
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
5
|
+
# was generated with Lita 4, the compatibility mode should be left disabled.
|
6
|
+
Lita.version_3_compatibility_mode = false
|
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-trello-lists
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taylor Lapeyre
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
description: Display your Trello lists through Lita.
|
98
|
+
email:
|
99
|
+
- taylorlapeyre@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- lib/lita-trello-lists.rb
|
109
|
+
- lib/lita/handlers/trello_lists.rb
|
110
|
+
- lita-trello-lists.gemspec
|
111
|
+
- locales/en.yml
|
112
|
+
- spec/lita/handlers/trello_lists_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- templates/.gitkeep
|
115
|
+
homepage: https://github.com/taylorlapeyre/lita-trello-lists
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata:
|
119
|
+
lita_plugin_type: handler
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.4.5
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Display your Trello lists through Lita.
|
140
|
+
test_files:
|
141
|
+
- spec/lita/handlers/trello_lists_spec.rb
|
142
|
+
- spec/spec_helper.rb
|