slack_trello 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c412d076e38c5e27813959ae64e1db1c0daeb607
4
- data.tar.gz: e714b20fe5e54749f90f046b84cf76b5fa272b51
3
+ metadata.gz: 26f2990100c4de1e0af8d6b3636450be18c240ce
4
+ data.tar.gz: d9666f4d7cdff344148a142767525ed002379469
5
5
  SHA512:
6
- metadata.gz: 173e23b8b2c3f2384dbad5cef280f64c99a69bc81645510f38b071952528290424bc32c2696f119065fecacac42e4e99bad9b49c3f645da0c1e40d9784a4726d
7
- data.tar.gz: 53b536445db574c7352d456a1c258c8a2fbc3f221a2608c499e58521e81c2d1d4571480c68336595b1bbdab0c565458e956321cb43606f834b8a1e0d058b1171
6
+ metadata.gz: b1c6b60e941556fe2f58db30341857a0371ce1a6492646dc4db57fd8b483da463731a893123aaf653e5fad147c2f9e76165452eca019ca7ecf7ce80ff18175dd
7
+ data.tar.gz: 446fbd9e29a3704095b75ea9c00986a91cbfadacf1722ee9fe5ad71273a3db7d1050c457f5387b88cf95dcc7916b547a2dc550fe2f347d3eb0f3b16ee3ed82bb
data/README.md CHANGED
@@ -2,6 +2,84 @@
2
2
 
3
3
  The slack_trello gem makes it easy to parse POST requests sent to a Ruby application by the Slack API. The gem is geared towards making Trello cards based on Slack POST requests, but the core modules and classes are generic and can be repourposed for other tasks as well.
4
4
 
5
+ The Slack [slash commands](https://api.slack.com/slash-commands) send POST requests like this:
6
+
7
+ ```ruby
8
+ {
9
+ "token" => "gIkuvaNzQIHg97ATvDxqgjtO",
10
+ "team_id" => "T0001",
11
+ "team_domain" => "example",
12
+ "channel_id" => "C2147483705",
13
+ "channel_name" => "test",
14
+ "user_id" => "U2147483697",
15
+ "user_name" => "Steve",
16
+ "command" => "/some_command",
17
+ "text" => "(some_arg another_arg) some stuff blah"
18
+ }
19
+ ```
20
+
21
+ The slack_trello gem parses these POST params and makes Trello cards.
22
+
23
+ ### Work Command
24
+
25
+ Example usage of this command in Slack (assume the command is run in the #pandas channel):
26
+
27
+ ```
28
+ /work Do some important stuff
29
+ ```
30
+
31
+ This will create a Trello card in the From Chat list of the Pandas Backlog Trello board. The code can be invoked as follows:
32
+
33
+ ```ruby
34
+ SlackTrello::Commands::Work.new(params, ENV["SLACK_WEBHOOK_URL"]).run
35
+ ```
36
+
37
+ ### Retro Command
38
+
39
+ Example usage of this command in Slack (assume the command is run in the #pandas channel):
40
+
41
+ ```
42
+ /retro (questions) Why are we building that feature?
43
+ ```
44
+
45
+ This will create a Trello card in the Questions list of the Pandas Retro Trello board. The code can be invoked as follows:
46
+
47
+ ```ruby
48
+ SlackTrello::Commands::Retro.new(params, ENV["SLACK_WEBHOOK_URL"]).run
49
+ ```
50
+
51
+ ### Card Command
52
+
53
+ Example usage of this command in Slack (this command can run in any channel and function the same):
54
+
55
+ ```
56
+ /card (pandaland on_deck) Build a cool cmap
57
+ ```
58
+
59
+ This will create a Trello card in the On Deck list of the Pandaland Trello board. The code can be invoked as follows:
60
+
61
+ ```ruby
62
+ SlackTrello::Commands::Card.new(params, ENV["SLACK_WEBHOOK_URL"]).run
63
+ ```
64
+
65
+ ### CopyCards Command
66
+
67
+ Example usage of this command in Slack (this command can run in any channel and function the same):
68
+
69
+ ```
70
+ /copy_cards (recurring_engineering pandas pandaland on_deck)
71
+ ```
72
+
73
+ This will copy all the cards from the the Pandas list of the Recurring Engineering Trello board to the On Deck list of the Pandaland Trello board. The code can be invoked as follows:
74
+
75
+ ```ruby
76
+ SlackTrello::Commands::CopyCards.new(params, ENV["SLACK_WEBHOOK_URL"]).run
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ The [slack-responder](https://github.com/medivo/slack-responder) Rails application includes the slack_trello gem and demonstrates how a Rails application that responds to Slack POST requests can be set up. Cloning the slack-responder application is the easiest way to get up-and-running with the slack_trello gem.
82
+
5
83
  ## Installation
6
84
 
7
85
  Add this line to your application's Gemfile:
@@ -18,7 +96,3 @@ Or install it yourself as:
18
96
 
19
97
  $ gem install slack_trello
20
98
 
21
- ## Usage
22
-
23
- The [slack-responder](https://github.com/medivo/slack-responder) Rails application includes the slack_trello gem and demonstrates how a Rails application that responds to Slack POST requests can be set up. Cloning the slack-responder application is the easiest way to get up-and-running with the slack_trello gem.
24
-
data/lib/slack_trello.rb CHANGED
@@ -1,19 +1,18 @@
1
+ require 'ostruct'
2
+
1
3
  require "active_support/core_ext/string"
2
4
  require "slack-notifier"
3
5
 
4
6
  require "slack_trello/version"
5
- require "slack_trello/trello_lookup"
6
- require "slack_trello/text_parser"
7
- require "slack_trello/response_parser"
8
7
 
9
- require "slack_trello/create_trello_card"
10
- require "slack_trello/copy_cards"
11
- require "slack_trello/speaker"
8
+ def require_all(pattern)
9
+ root = File.expand_path("../", File.dirname(__FILE__))
10
+ Dir.glob("#{root}/#{pattern}/**/*.rb").sort.each { |path| require path }
11
+ end
12
12
 
13
- require "slack_trello/copy_cards_command"
14
- require "slack_trello/create_card_command"
15
- require "slack_trello/work_command"
16
- require "slack_trello/retro_command"
13
+ require_all("lib/slack_trello/slack_helpers")
14
+ require_all("lib/slack_trello/trello_helpers")
15
+ require_all("lib/slack_trello/commands")
17
16
 
18
17
  module SlackTrello
19
18
  end
@@ -1,11 +1,11 @@
1
- module SlackTrello; class CopyCardsCommand
1
+ module SlackTrello; module Commands; class CopyCards
2
2
 
3
- include TextParser
3
+ include SlackTrello::SlackHelpers::TextParser
4
4
 
5
- attr_reader :parser, :webhook_url
5
+ attr_reader :slack_post_response, :webhook_url
6
6
 
7
- def initialize(args, webhook_url)
8
- @parser = ResponseParser.new(args)
7
+ def initialize(slack_post_args, webhook_url)
8
+ @slack_post_response = OpenStruct.new(slack_post_args)
9
9
  @webhook_url = webhook_url
10
10
  end
11
11
 
@@ -22,7 +22,7 @@ module SlackTrello; class CopyCardsCommand
22
22
 
23
23
  def help_message
24
24
  %{:cry: Invalid format
25
- Your message: #{parser.text}
25
+ Your message: #{slack_post_response.text}
26
26
  Example: /copy_cards (source_board, source_list, destination_board, destination_list)
27
27
  }
28
28
  end
@@ -30,10 +30,10 @@ Example: /copy_cards (source_board, source_list, destination_board, destination_
30
30
  def speaker
31
31
  args = {
32
32
  webhook_url: webhook_url,
33
- channel: parser.channel_name,
34
- username: parser.user_name
33
+ channel: slack_post_response.channel_name,
34
+ username: slack_post_response.user_name
35
35
  }
36
- Speaker.new(args)
36
+ SlackTrello::SlackHelpers::Speaker.new(args)
37
37
  end
38
38
 
39
39
  def card_copier
@@ -63,8 +63,8 @@ Example: /copy_cards (source_board, source_list, destination_board, destination_
63
63
  end
64
64
 
65
65
  def success_message
66
- ":mega: [#{parser.user_name}] has copied all the cards from the #{source_list_name} of the #{source_board_name} to the #{destination_list_name} of the #{destination_board_name}"
66
+ ":mega: [#{slack_post_response.user_name}] has copied all the cards from the #{source_list_name} of the #{source_board_name} to the #{destination_list_name} of the #{destination_board_name}"
67
67
  end
68
68
 
69
- end; end
69
+ end; end; end
70
70
 
@@ -1,11 +1,11 @@
1
- module SlackTrello; class CreateCardCommand
1
+ module SlackTrello; module Commands; class CreateCard
2
2
 
3
- include TextParser
3
+ include SlackTrello::SlackHelpers::TextParser
4
4
 
5
- attr_reader :parser, :webhook_url
5
+ attr_reader :slack_post_response, :webhook_url
6
6
 
7
- def initialize(args, webhook_url)
8
- @parser = ResponseParser.new(args)
7
+ def initialize(slack_post_args, webhook_url)
8
+ @slack_post_response = OpenStruct.new(slack_post_args)
9
9
  @webhook_url = webhook_url
10
10
  end
11
11
 
@@ -33,10 +33,10 @@ For example, Some Board Name => some_board_name
33
33
  def speaker
34
34
  args = {
35
35
  webhook_url: webhook_url,
36
- channel: parser.channel_name,
37
- username: parser.user_name
36
+ channel: slack_post_response.channel_name,
37
+ username: slack_post_response.user_name
38
38
  }
39
- Speaker.new(args)
39
+ SlackTrello::SlackHelpers::Speaker.new(args)
40
40
  end
41
41
 
42
42
  def trello_card_creator
@@ -45,7 +45,7 @@ For example, Some Board Name => some_board_name
45
45
  list_name: trello_list_name,
46
46
  card_name: card_title
47
47
  }
48
- @trello_card_creator ||= CreateTrelloCard.new(args)
48
+ @trello_card_creator ||= SlackTrello::TrelloHelpers::CreateCard.new(args)
49
49
  end
50
50
 
51
51
  def trello_card
@@ -65,16 +65,12 @@ For example, Some Board Name => some_board_name
65
65
  end
66
66
 
67
67
  def success_message
68
- ":mega: [#{parser.user_name}] has created a new trello card: <#{trello_card.short_url}|#{parser.text.strip}>"
68
+ ":mega: [#{slack_post_response.user_name}] has created a new trello card: <#{trello_card.short_url}|#{slack_post_response.text.strip}>"
69
69
  end
70
70
 
71
71
  def card_title
72
72
  text_message
73
73
  end
74
74
 
75
- def text
76
- parser.text
77
- end
78
-
79
- end; end
75
+ end; end; end
80
76
 
@@ -1,11 +1,11 @@
1
- module SlackTrello; class RetroCommand
1
+ module SlackTrello; module Commands; class Retro
2
2
 
3
- include TextParser
3
+ include SlackTrello::SlackHelpers::TextParser
4
4
 
5
- attr_reader :parser, :webhook_url
5
+ attr_reader :slack_post_response, :webhook_url
6
6
 
7
- def initialize(args, webhook_url)
8
- @parser = ResponseParser.new(args)
7
+ def initialize(slack_post_args, webhook_url)
8
+ @slack_post_response = OpenStruct.new(slack_post_args)
9
9
  @webhook_url = webhook_url
10
10
  end
11
11
 
@@ -34,10 +34,10 @@ For example, Some List Name => some_list_name
34
34
  def speaker
35
35
  args = {
36
36
  webhook_url: webhook_url,
37
- channel: parser.channel_name,
38
- username: parser.user_name
37
+ channel: slack_post_response.channel_name,
38
+ username: slack_post_response.user_name
39
39
  }
40
- Speaker.new(args)
40
+ SlackTrello::SlackHelpers::Speaker.new(args)
41
41
  end
42
42
 
43
43
  def trello_card_creator
@@ -46,7 +46,7 @@ For example, Some List Name => some_list_name
46
46
  list_name: trello_list_name,
47
47
  card_name: card_title
48
48
  }
49
- @trello_card_creator ||= CreateTrelloCard.new(args)
49
+ @trello_card_creator ||= SlackTrello::TrelloHelpers::CreateCard.new(args)
50
50
  end
51
51
 
52
52
  def trello_card
@@ -54,7 +54,7 @@ For example, Some List Name => some_list_name
54
54
  end
55
55
 
56
56
  def trello_board_name
57
- "#{parser.channel_name.titleize} Retro"
57
+ "#{slack_post_response.channel_name.titleize} Retro"
58
58
  end
59
59
 
60
60
  def trello_list_name
@@ -66,15 +66,11 @@ For example, Some List Name => some_list_name
66
66
  end
67
67
 
68
68
  def success_message
69
- ":mega: [#{parser.user_name}] has created a new trello card: <#{trello_card.short_url}|#{parser.text.strip}>"
69
+ ":mega: [#{slack_post_response.user_name}] has created a new trello card: <#{trello_card.short_url}|#{slack_post_response.text.strip}>"
70
70
  end
71
71
 
72
72
  def card_title
73
- "#{text_message} -- #{parser.user_name}"
74
- end
75
-
76
- def text
77
- parser.text
73
+ "#{text_message} -- #{slack_post_response.user_name}"
78
74
  end
79
75
 
80
76
  def list_names
@@ -83,5 +79,5 @@ For example, Some List Name => some_list_name
83
79
  end
84
80
  end
85
81
 
86
- end; end
82
+ end; end; end
87
83
 
@@ -1,9 +1,9 @@
1
- module SlackTrello; class WorkCommand
1
+ module SlackTrello; module Commands; class Work
2
2
 
3
- attr_reader :parser, :webhook_url
3
+ attr_reader :slack_post_response, :webhook_url
4
4
 
5
- def initialize(args, webhook_url)
6
- @parser = ResponseParser.new(args)
5
+ def initialize(slack_post_args, webhook_url)
6
+ @slack_post_response = OpenStruct.new(slack_post_args)
7
7
  @webhook_url = webhook_url
8
8
  end
9
9
 
@@ -20,10 +20,10 @@ module SlackTrello; class WorkCommand
20
20
  def speaker
21
21
  args = {
22
22
  webhook_url: webhook_url,
23
- channel: parser.channel_name,
24
- username: parser.user_name
23
+ channel: slack_post_response.channel_name,
24
+ username: slack_post_response.user_name
25
25
  }
26
- Speaker.new(args)
26
+ SlackTrello::SlackHelpers::Speaker.new(args)
27
27
  end
28
28
 
29
29
  def trello_card_creator
@@ -32,7 +32,7 @@ module SlackTrello; class WorkCommand
32
32
  list_name: trello_list_name,
33
33
  card_name: card_title
34
34
  }
35
- @trello_card_creator ||= CreateTrelloCard.new(args)
35
+ @trello_card_creator ||= SlackTrello::TrelloHelpers::CreateCard.new(args)
36
36
  end
37
37
 
38
38
  def trello_card
@@ -40,7 +40,7 @@ module SlackTrello; class WorkCommand
40
40
  end
41
41
 
42
42
  def trello_board_name
43
- "#{parser.channel_name.titleize} Backlog"
43
+ "#{slack_post_response.channel_name.titleize} Backlog"
44
44
  end
45
45
 
46
46
  def trello_list_name
@@ -52,12 +52,12 @@ module SlackTrello; class WorkCommand
52
52
  end
53
53
 
54
54
  def success_message
55
- ":mega: [#{parser.user_name}] has created a new work card: <#{trello_card.short_url}|#{parser.text.strip}>"
55
+ ":mega: [#{slack_post_response.user_name}] has created a new work card: <#{trello_card.short_url}|#{slack_post_response.text.strip}>"
56
56
  end
57
57
 
58
58
  def card_title
59
- "(UNSIZED) #{parser.text.strip} {tag???}"
59
+ "(UNSIZED) #{slack_post_response.text.strip} {tag???}"
60
60
  end
61
61
 
62
- end; end
62
+ end; end; end
63
63
 
@@ -1,4 +1,4 @@
1
- module SlackTrello; class Speaker
1
+ module SlackTrello; module SlackHelpers; class Speaker
2
2
 
3
3
  def initialize(args)
4
4
  @webhook_url = args.fetch(:webhook_url)
@@ -20,4 +20,5 @@ module SlackTrello; class Speaker
20
20
  @channel.start_with?("#") ? @channel : "##{@channel}"
21
21
  end
22
22
 
23
- end; end
23
+ end; end; end
24
+
@@ -1,4 +1,4 @@
1
- module SlackTrello; module TextParser
1
+ module SlackTrello; module SlackHelpers; module TextParser
2
2
 
3
3
  def args
4
4
  return "" unless valid_text_format?
@@ -18,8 +18,6 @@ module SlackTrello; module TextParser
18
18
  args.length
19
19
  end
20
20
 
21
- private
22
-
23
21
  def regex
24
22
  /\((.+?)\)(.+)?/
25
23
  end
@@ -28,6 +26,9 @@ module SlackTrello; module TextParser
28
26
  text.match(regex)
29
27
  end
30
28
 
31
- end; end
29
+ def text
30
+ slack_post_response.text
31
+ end
32
32
 
33
+ end; end; end
33
34
 
@@ -1,4 +1,4 @@
1
- module SlackTrello; class CopyCards
1
+ module SlackTrello; module TrelloHelpers; class CopyCards
2
2
 
3
3
  attr_reader :source_board, :source_list, :destination_board, :destination_list
4
4
 
@@ -11,16 +11,15 @@ module SlackTrello; class CopyCards
11
11
 
12
12
  def run
13
13
  source_cards.each do |source_card|
14
- creator = CreateTrelloCard.new(board_name: destination_board, list_name: destination_list, card_name: source_card.name)
14
+ creator = CreateCard.new(board_name: destination_board, list_name: destination_list, card_name: source_card.name)
15
15
  creator.first_or_create
16
16
  end
17
17
  end
18
18
 
19
19
  def source_cards
20
- l = TrelloLookup.list(source_board, source_list)
20
+ l = Lookup.list(source_board, source_list)
21
21
  l.cards
22
22
  end
23
23
 
24
- end; end
25
-
24
+ end; end; end
26
25
 
@@ -1,4 +1,4 @@
1
- module SlackTrello; class CreateTrelloCard
1
+ module SlackTrello; module TrelloHelpers; class CreateCard
2
2
 
3
3
  attr_reader :board_name, :list_name, :card_name
4
4
 
@@ -9,7 +9,7 @@ module SlackTrello; class CreateTrelloCard
9
9
  end
10
10
 
11
11
  def first_or_create
12
- card = TrelloLookup.card(board_name, list_name, card_name)
12
+ card = Lookup.card(board_name, list_name, card_name)
13
13
  return card if card
14
14
  create_card
15
15
  end
@@ -22,8 +22,8 @@ module SlackTrello; class CreateTrelloCard
22
22
  end
23
23
 
24
24
  def trello_list
25
- TrelloLookup.list(board_name, list_name)
25
+ Lookup.list(board_name, list_name)
26
26
  end
27
27
 
28
- end; end
28
+ end; end; end
29
29
 
@@ -1,4 +1,4 @@
1
- module SlackTrello; class TrelloLookup
1
+ module SlackTrello; module TrelloHelpers; class Lookup
2
2
 
3
3
  class << self
4
4
 
@@ -28,5 +28,5 @@ module SlackTrello; class TrelloLookup
28
28
 
29
29
  end
30
30
 
31
- end; end
31
+ end; end; end
32
32
 
@@ -1,3 +1,3 @@
1
1
  module SlackTrello
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_trello
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Powers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,17 +98,16 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/slack_trello.rb
101
- - lib/slack_trello/copy_cards.rb
102
- - lib/slack_trello/copy_cards_command.rb
103
- - lib/slack_trello/create_card_command.rb
104
- - lib/slack_trello/create_trello_card.rb
105
- - lib/slack_trello/response_parser.rb
106
- - lib/slack_trello/retro_command.rb
107
- - lib/slack_trello/speaker.rb
108
- - lib/slack_trello/text_parser.rb
109
- - lib/slack_trello/trello_lookup.rb
101
+ - lib/slack_trello/commands/copy_cards.rb
102
+ - lib/slack_trello/commands/create_card.rb
103
+ - lib/slack_trello/commands/retro.rb
104
+ - lib/slack_trello/commands/work.rb
105
+ - lib/slack_trello/slack_helpers/speaker.rb
106
+ - lib/slack_trello/slack_helpers/text_parser.rb
107
+ - lib/slack_trello/trello_helpers/copy_cards.rb
108
+ - lib/slack_trello/trello_helpers/create_card.rb
109
+ - lib/slack_trello/trello_helpers/lookup.rb
110
110
  - lib/slack_trello/version.rb
111
- - lib/slack_trello/work_command.rb
112
111
  - slack_trello.gemspec
113
112
  homepage: https://github.com/MrPowers/slack_trello
114
113
  licenses:
@@ -1,14 +0,0 @@
1
- module SlackTrello; class ResponseParser
2
-
3
- attr_reader :args
4
-
5
- def initialize(args)
6
- @args = args
7
- end
8
-
9
- def method_missing(name)
10
- super unless args.has_key?(name.to_s)
11
- args.fetch(name.to_s)
12
- end
13
-
14
- end; end