lita-ticket_notifier 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lita/handlers/ticket_notifier.rb +79 -3
- data/lita-ticket_notifier.gemspec +1 -1
- data/spec/fixtures/ticket.json +36 -0
- data/spec/lita/handlers/ticket_notifier_spec.rb +27 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ef0097fd60259595d434f46c56fc3a82897175e
|
4
|
+
data.tar.gz: 24dcad7c5cf32e2a461619f40c31b6d8ceb3d109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f94660522b3ed69e3e30014cd1a1c6b413c749f20253b91332a5b9c0a208517ae42f8e54b970c594034ff8fe4ff934fcda1fa8a68a6ca852bdc98a6db75c1a1
|
7
|
+
data.tar.gz: 05015b761b5f134d8e577aea6cffa1c3790e8e192496b44b1595a2c8c9032baa0799a33222576dccbe18d054e9dd7b80f037074987011f4194e5b0283d79bef3
|
@@ -1,17 +1,93 @@
|
|
1
1
|
module Lita
|
2
2
|
module Handlers
|
3
3
|
class TicketNotifier < Handler
|
4
|
+
attr_accessor :ticket_json, :ticket_object
|
4
5
|
http.post "/ticket_notification", :ticket_notification
|
5
6
|
|
7
|
+
route(/ticket notify start/i, :add_ticket_notification, command: true,
|
8
|
+
help: { "ticket notify start" => "Lita will notify you of Lighthouse tickets." }
|
9
|
+
)
|
10
|
+
|
11
|
+
route(/ticket notify stop/i, :remove_ticket_notification, command: true,
|
12
|
+
help: { "ticket notify stop" => "Lita will stop notifying you of Lighthouse tickets." }
|
13
|
+
)
|
14
|
+
|
6
15
|
def ticket_notification(request, response)
|
7
|
-
|
16
|
+
self.ticket_json ||= JSON.parse(request.body.read)
|
17
|
+
user_names.each do |user_name|
|
18
|
+
send_message_to_user(user_name, ticket_message)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_ticket_notification(response)
|
23
|
+
redis.lpush("ticket_users", response.user.name)
|
24
|
+
response.reply_privately "You will now get notified of ticket updates."
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove_ticket_notification(response)
|
28
|
+
redis.lrem("ticket_users", 0, response.user.name)
|
29
|
+
response.reply_privately "You will no longer receive ticket update notifications."
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def send_message_to_user(user_name, messaage)
|
35
|
+
robot.send_message(source_from_name(user_name), message)
|
8
36
|
end
|
9
37
|
|
10
|
-
def
|
11
|
-
Lita::Source.new({
|
38
|
+
def source_from_name(name)
|
39
|
+
Lita::Source.new({ user: Lita::User.find_by_name(name) })
|
40
|
+
end
|
41
|
+
|
42
|
+
def user_names
|
43
|
+
redis.lrange("ticket_users", 0, -1)
|
44
|
+
end
|
45
|
+
|
46
|
+
def ticket
|
47
|
+
self.ticket_object ||= OpenStruct.new(hash_attributes)
|
48
|
+
end
|
49
|
+
|
50
|
+
def hash_attributes
|
51
|
+
# listing this all out to document the attributes
|
52
|
+
h = ticket_json['version']
|
53
|
+
hash_attributes = {
|
54
|
+
assigned_user_id: h['assigned_user_id'],
|
55
|
+
assigned_user_name: h['assigned_user_name'],
|
56
|
+
attachments_count: h['attachments_count'],
|
57
|
+
body: h['body'],
|
58
|
+
body_html: h['body_html'],
|
59
|
+
closed: h['closed'],
|
60
|
+
created_at: h['created_at'],
|
61
|
+
creator_id: h['creator_id'],
|
62
|
+
creator_name: h['creator_name'],
|
63
|
+
diffable_attributes_hash: h['diffable_attributes'],
|
64
|
+
importance: h['importance'],
|
65
|
+
importance_name: h['importance_name'],
|
66
|
+
milestone_id: h['milestone_id'],
|
67
|
+
milestone_order: h['milestone_order'],
|
68
|
+
number: h['number'],
|
69
|
+
permalink: h['permalink'],
|
70
|
+
priority: h['priority'],
|
71
|
+
project_id: h['project_id'],
|
72
|
+
spam: h['spam'],
|
73
|
+
state: h['state'],
|
74
|
+
tag: h['tag'],
|
75
|
+
title: h['title'],
|
76
|
+
updated_at: h['updated_at'],
|
77
|
+
url: h['url'],
|
78
|
+
user_id: h['user_id'],
|
79
|
+
user_name: h['user_name'],
|
80
|
+
version: h['version'],
|
81
|
+
watchers_ids: h['watchers_ids']
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def ticket_message
|
86
|
+
"Ticket: #{ticket.title}\nState:#{ticket.state}\nImportance:#{ticket.importance_name}\nTags:#{ticket.tag}\n#{ticket.url}"
|
12
87
|
end
|
13
88
|
end
|
14
89
|
|
15
90
|
Lita.register_handler(TicketNotifier)
|
16
91
|
end
|
17
92
|
end
|
93
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-ticket_notifier"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.14"
|
4
4
|
spec.authors = ["Michael van den Beuken", "Ruben Estevez", "Jordan Babe", "Mathieu Gilbert", "Ryan Jones", "Darko Dosenovic"]
|
5
5
|
spec.email = ["michael.beuken@gmail.com", "ruben.a.estevez@gmail.com", "jorbabe@gmail.com", "mathieu.gilbert@ama.ab.ca", "ryan.michael.jones@gmail.com", "darko.dosenovic@ama.ab.ca"]
|
6
6
|
spec.description = %q{Notify users about new tickets coming in.}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"version": {
|
3
|
+
"assigned_user_id": null,
|
4
|
+
"attachments_count": 0,
|
5
|
+
"body": "",
|
6
|
+
"body_html": "",
|
7
|
+
"closed": true,
|
8
|
+
"created_at": "2014-08-06T22:55:30Z",
|
9
|
+
"creator_id": 240273,
|
10
|
+
"creator_name": "Mathieu Gilbert",
|
11
|
+
"diffable_attributes": {
|
12
|
+
"state": "resolved"
|
13
|
+
},
|
14
|
+
"importance": 3,
|
15
|
+
"importance_name": "Low",
|
16
|
+
"milestone_id": null,
|
17
|
+
"milestone_order": 9999,
|
18
|
+
"number": 4146,
|
19
|
+
"permalink": "test-ticket",
|
20
|
+
"priority": 3,
|
21
|
+
"project_id": 66073,
|
22
|
+
"spam": false,
|
23
|
+
"state": "review",
|
24
|
+
"tag": "dev",
|
25
|
+
"title": "test ticket",
|
26
|
+
"updated_at": "2014-08-06T22:55:32Z",
|
27
|
+
"url": "http://waffles.lighthouseapp.com/projects/1/tickets/200",
|
28
|
+
"user_id": 240273,
|
29
|
+
"user_name": "Mathieu Gilbert",
|
30
|
+
"version": 3,
|
31
|
+
"watchers_ids": [
|
32
|
+
240273,
|
33
|
+
216682
|
34
|
+
]
|
35
|
+
}
|
36
|
+
}
|
@@ -1,5 +1,32 @@
|
|
1
1
|
require "spec_helper"
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
describe Lita::Handlers::TicketNotifier, lita_handler: true do
|
5
|
+
let(:payload) { File.read(File.join('spec', 'fixtures', 'ticket.json')) }
|
6
|
+
let(:request) { OpenStruct.new({ body: OpenStruct.new({ read: payload }) }) }
|
7
|
+
let(:teddy) { Lita::User.create(123, name: "Teddy Ruxbin") }
|
8
|
+
let(:batman) { Lita::User.create(567, name: "The Batman") }
|
9
|
+
let(:ticket_messsage) { "Ticket: test ticket\nState:review\nImportance:Low\nTags:dev\nhttp://waffles.lighthouseapp.com/projects/1/tickets/200" }
|
4
10
|
|
11
|
+
it { routes_command("ticket notify start").to(:add_ticket_notification) }
|
12
|
+
it { routes_command("ticket notify stop").to(:remove_ticket_notification) }
|
13
|
+
it { routes_http(:post, "/ticket_notification").to(:ticket_notification) }
|
14
|
+
|
15
|
+
it "notifies correct users about tickets" do
|
16
|
+
expect(subject).to receive(:send_message_to_user).with(user.name, ticket_messsage)
|
17
|
+
expect(subject).to receive(:send_message_to_user).with(teddy.name, ticket_messsage)
|
18
|
+
expect(subject).to_not receive(:send_message_to_user).with(batman.name, ticket_messsage)
|
19
|
+
|
20
|
+
send_command("ticket notify start")
|
21
|
+
send_command("ticket notify start", as: teddy)
|
22
|
+
send_command("ticket notify start", as: batman)
|
23
|
+
send_command("ticket notify stop", as: batman)
|
24
|
+
|
25
|
+
subject.ticket_notification(request, nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "doesn't send notifications to nobody" do
|
29
|
+
expect(subject).to_not receive(:send_message_to_user)
|
30
|
+
subject.ticket_notification(request, nil)
|
31
|
+
end
|
5
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-ticket_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van den Beuken
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2014-08-
|
16
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: lita
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/lita/handlers/ticket_notifier.rb
|
107
107
|
- lita-ticket_notifier.gemspec
|
108
108
|
- locales/en.yml
|
109
|
+
- spec/fixtures/ticket.json
|
109
110
|
- spec/lita/handlers/ticket_notifier_spec.rb
|
110
111
|
- spec/spec_helper.rb
|
111
112
|
homepage: https://github.com/amaabca/lita-ticket_notifier
|
@@ -134,5 +135,6 @@ signing_key:
|
|
134
135
|
specification_version: 4
|
135
136
|
summary: Users can opt-in/out from Lighthouse new ticket notifications.
|
136
137
|
test_files:
|
138
|
+
- spec/fixtures/ticket.json
|
137
139
|
- spec/lita/handlers/ticket_notifier_spec.rb
|
138
140
|
- spec/spec_helper.rb
|