hipchat_searcher 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +3 -1
- data/hipchat_searcher.gemspec +1 -1
- data/lib/hipchat_searcher/command.rb +1 -1
- data/lib/hipchat_searcher/options.rb +12 -4
- data/lib/hipchat_searcher/searcher.rb +92 -29
- data/lib/hipchat_searcher/version.rb +1 -1
- data/spec/data/item-list-with-overlap.json +67 -0
- data/spec/hipchat_searcher_spec.rb +1 -1
- data/spec/lib/hipchat_searcher/searcher_spec.rb +269 -58
- data/spec/spec_helper.rb +3 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fd098a01a0e50974e9e94aad6531217212b4f02
|
4
|
+
data.tar.gz: ff849519de62525a531f4705e0f4dcfe4c0c7f39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88be4494c9f37e92b7668dcee89e9b57b106d788bf6b2d50c3ea967c5fb6d21140dff7ad5f9413cf69290677766b404b5c5a0f849e932bf81927a627dd682827
|
7
|
+
data.tar.gz: 2633cdb60c1494e9545048b0cc73031c647f876afa64bce65644c3c20043857752b6448db960ad4f285ed9a3ff042bdc3121dc312d3a37aeb819125a1d37088f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -22,9 +22,11 @@ echo {access_token} > ~/.hps
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
`hipchat_searcher` search for a regular expression the words that you specify.
|
25
|
+
`hipchat_searcher` search for a regular expression the words that you specify.
|
26
|
+
In the specifications of the [hipchat api](https://www.hipchat.com/docs/apiv2/), `hipchat_searcher` search of the upcoming 100 comments.
|
26
27
|
|
27
28
|
* Search the words in all room
|
29
|
+
* But it searches ALL the room that user know, so there may be heavy.
|
28
30
|
|
29
31
|
```
|
30
32
|
hps word
|
data/hipchat_searcher.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["mgi166"]
|
10
10
|
spec.email = ["skskoari@gmail.com"]
|
11
11
|
spec.summary = %q{Search hipchat log on terminal}
|
12
|
-
spec.homepage = ""
|
12
|
+
spec.homepage = "https://github.com/mgi166/hipchat_searcher"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -11,7 +11,12 @@ module HipchatSearcher
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def search_options
|
14
|
-
|
14
|
+
{}.tap do |o|
|
15
|
+
o.merge!(user: user) if user?
|
16
|
+
o.merge!(after_context: after_context) if after_context?
|
17
|
+
o.merge!(before_context: before_context) if before_context?
|
18
|
+
o.merge!(context: context) if context?
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
22
|
class << self
|
@@ -19,9 +24,12 @@ module HipchatSearcher
|
|
19
24
|
# [shortname, longname, description]
|
20
25
|
def with_value
|
21
26
|
[
|
22
|
-
['r=', 'room=',
|
23
|
-
['u=', 'user=',
|
24
|
-
['d=', 'date=',
|
27
|
+
['r=', 'room=', 'Search only the log of the room that you specified'],
|
28
|
+
['u=', 'user=', 'Search only the log that specified user talk'],
|
29
|
+
['d=', 'date=', 'Search the log since specified date'],
|
30
|
+
['A=', 'after_context=', 'Search the log that trails context after each match'],
|
31
|
+
['B=', 'before_context=', 'Search the log that trails context before each match'],
|
32
|
+
['C=', 'context=', 'Search the log that trails context surround each match'],
|
25
33
|
]
|
26
34
|
end
|
27
35
|
|
@@ -2,40 +2,52 @@ require 'colorize'
|
|
2
2
|
|
3
3
|
module HipchatSearcher
|
4
4
|
class Searcher
|
5
|
-
def initialize(result, options={})
|
5
|
+
def initialize(pattern, result, options={})
|
6
6
|
@result = result
|
7
7
|
@options = options
|
8
|
+
@pattern = Regexp.new(pattern, Regexp::IGNORECASE)
|
8
9
|
@print_room = false
|
10
|
+
@print_item = {}
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.search(pattern, result, options)
|
12
|
-
new(result, options).search
|
14
|
+
new(pattern, result, options).search
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
17
|
+
def extended_items(index)
|
18
|
+
items[range(index)].map do |itm|
|
19
|
+
itm.extend(ItemExtention).tap do |i|
|
20
|
+
i.pattern = @pattern
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
18
24
|
|
19
|
-
|
25
|
+
def items
|
26
|
+
@items ||= @result.items
|
20
27
|
end
|
21
28
|
|
22
|
-
def puts_search_result(
|
23
|
-
contents = contents(pattern, item)
|
29
|
+
def puts_search_result(item)
|
24
30
|
if option_user?
|
25
|
-
if @options[:user] ==
|
26
|
-
puts_contents(
|
31
|
+
if @options[:user] == item.mention_name
|
32
|
+
puts_contents(item)
|
27
33
|
end
|
28
34
|
else
|
29
|
-
puts_contents(
|
35
|
+
puts_contents(item)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
def search
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if
|
38
|
-
|
39
|
+
def search
|
40
|
+
items.each_with_index do |item, idx|
|
41
|
+
next unless @pattern =~ item.message
|
42
|
+
|
43
|
+
if option_search?
|
44
|
+
extended_items(idx).each do |itm|
|
45
|
+
puts_search_result(itm)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
ext = item.extend(ItemExtention)
|
49
|
+
ext.pattern = @pattern
|
50
|
+
puts_search_result(ext)
|
39
51
|
end
|
40
52
|
end
|
41
53
|
|
@@ -44,17 +56,20 @@ module HipchatSearcher
|
|
44
56
|
|
45
57
|
private
|
46
58
|
|
47
|
-
def
|
48
|
-
|
59
|
+
def option_after?
|
60
|
+
!!@options[:after_context]
|
49
61
|
end
|
50
62
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
end
|
63
|
+
def option_before?
|
64
|
+
!!@options[:before_context]
|
65
|
+
end
|
55
66
|
|
56
|
-
|
57
|
-
|
67
|
+
def option_context?
|
68
|
+
!!@options[:context]
|
69
|
+
end
|
70
|
+
|
71
|
+
def option_search?
|
72
|
+
option_after? || option_before? || option_context?
|
58
73
|
end
|
59
74
|
|
60
75
|
def option_user?
|
@@ -70,17 +85,65 @@ module HipchatSearcher
|
|
70
85
|
puts room.underline
|
71
86
|
end
|
72
87
|
|
73
|
-
def puts_contents(
|
88
|
+
def puts_contents(item)
|
74
89
|
print_room? ? nil : puts_room
|
75
|
-
puts contents
|
90
|
+
puts item.contents unless printed?(item.id)
|
91
|
+
end
|
92
|
+
|
93
|
+
def range(index)
|
94
|
+
param = []
|
95
|
+
|
96
|
+
case
|
97
|
+
when option_before?
|
98
|
+
_i = index - @options[:before_context].to_i
|
99
|
+
param = _i < 0 ? [0, index] : [_i, index]
|
100
|
+
when option_after?
|
101
|
+
_i = index + @options[:after_context].to_i
|
102
|
+
param = [index, _i]
|
103
|
+
when option_context?
|
104
|
+
_i = index - @options[:context].to_i
|
105
|
+
_j = index + @options[:context].to_i
|
106
|
+
param = _i < 0 ? [0, _j] : [_i, _j]
|
107
|
+
end
|
108
|
+
|
109
|
+
Range.new(*param)
|
76
110
|
end
|
77
111
|
|
78
112
|
def room
|
79
113
|
@result.room
|
80
114
|
end
|
81
115
|
|
82
|
-
def
|
83
|
-
|
116
|
+
def printed?(id)
|
117
|
+
if @print_item.key?(id)
|
118
|
+
true
|
119
|
+
else
|
120
|
+
@print_item[id] = 1
|
121
|
+
false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
module ItemExtention
|
126
|
+
attr_accessor :pattern
|
127
|
+
|
128
|
+
def contents
|
129
|
+
"%s\n%s\n\n" % [_date, _message]
|
130
|
+
end
|
131
|
+
|
132
|
+
def mention_name
|
133
|
+
self.from.mention_name rescue self.from
|
134
|
+
end
|
135
|
+
|
136
|
+
def _date
|
137
|
+
" Date: %s" % self.date
|
138
|
+
end
|
139
|
+
|
140
|
+
def _message
|
141
|
+
msg = self.message.gsub(pattern) do |matched|
|
142
|
+
matched.colorize(:red)
|
143
|
+
end
|
144
|
+
|
145
|
+
" @%s: %s" % [mention_name, msg]
|
146
|
+
end
|
84
147
|
end
|
85
148
|
end
|
86
149
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
{
|
2
|
+
"items": [
|
3
|
+
{
|
4
|
+
"date": "2014-05-30T01:38:16.741565+00:00",
|
5
|
+
"from": {
|
6
|
+
"id": 12345,
|
7
|
+
"links": {"self": "https://api.hipchat.com/v2/user/12345"},
|
8
|
+
"mention_name": "jotaro",
|
9
|
+
"name": "Jotaro Kujo"
|
10
|
+
},
|
11
|
+
"id": "aaaa-bbbb-cccc",
|
12
|
+
"mentions": [],
|
13
|
+
"message": "yareyare daze"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"date": "2014-05-30T01:39:02.186319+00:00",
|
17
|
+
"from": {
|
18
|
+
"id": 23456,
|
19
|
+
"links": {"self": "https://api.hipchat.com/v2/user/23456"},
|
20
|
+
"mention_name": "noriaki",
|
21
|
+
"name": "Noriaki Kakyoin"
|
22
|
+
},
|
23
|
+
"id": "dddd-eeee-ffff",
|
24
|
+
"mentions": [],
|
25
|
+
"message": "rerorero"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"date": "2014-06-09T11:29:10.209014+00:00",
|
29
|
+
"from": {
|
30
|
+
"id": 34567,
|
31
|
+
"links": {"self": "https://api.hipchat.com/v2/user/34567"},
|
32
|
+
"mention_name": "polnareff",
|
33
|
+
"name": "Jean Pierre Polnareff"
|
34
|
+
},
|
35
|
+
"id": "gggg-hhhh-iiii",
|
36
|
+
"mentions": [],
|
37
|
+
"message": "a... arinomama ima okotta koto wo hanasu ze"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"date": "2014-06-10T08:36:09.281643+00:00",
|
41
|
+
"from": {
|
42
|
+
"id": 45678,
|
43
|
+
"links": {"self": "https://api.hipchat.com/v2/user/45678"},
|
44
|
+
"mention_name": "abdul",
|
45
|
+
"name": "mohamed abdul"
|
46
|
+
},
|
47
|
+
"id": "jjjj-kkkk-llll",
|
48
|
+
"mentions": [],
|
49
|
+
"message": "chirp chirp chirp"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"date": "2014-06-11T19:20:47.726182+00:00",
|
53
|
+
"from": {
|
54
|
+
"id": 34567,
|
55
|
+
"links": {"self": "https://api.hipchat.com/v2/user/34567"},
|
56
|
+
"mention_name": "lggy",
|
57
|
+
"name": "lggy"
|
58
|
+
},
|
59
|
+
"id": "mmmm-nnnn-oooo",
|
60
|
+
"mentions": [],
|
61
|
+
"message": "inu zuki no kodomo ha migoroshiniha dekine-ze"
|
62
|
+
}
|
63
|
+
],
|
64
|
+
"links": {"self": "https://api.hipchat.com/v2/room/jojo-part3/history"},
|
65
|
+
"maxResults": 100,
|
66
|
+
"startIndex": 0
|
67
|
+
}
|
@@ -1,20 +1,111 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe HipchatSearcher::Searcher do
|
4
|
-
def searcher(result)
|
5
|
-
described_class.new(result)
|
4
|
+
def searcher(pattern, result, options={})
|
5
|
+
described_class.new(pattern, result, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#items' do
|
9
|
+
subject { searcher(pattern, result).items }
|
10
|
+
|
11
|
+
let(:pattern) { 'hoge' }
|
12
|
+
let(:result) do
|
13
|
+
response = File.read(File.join('spec', 'data', 'item-list.json'))
|
14
|
+
HipchatSearcher::Result.new(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
it { should be_instance_of Array }
|
18
|
+
|
19
|
+
it 'should return array with Hashie::Mash objects' do
|
20
|
+
subject.first.should be_instance_of ::Hashie::Mash
|
21
|
+
subject.last.should be_instance_of ::Hashie::Mash
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#extended_items' do
|
26
|
+
describe 'you speciy :before_context option' do
|
27
|
+
context 'when specify the range is included in the array' do
|
28
|
+
subject { searcher(pattern, result, before_context: '3').extended_items(3) }
|
29
|
+
|
30
|
+
let(:pattern) { 'fuga' }
|
31
|
+
let(:result) { double(:result, items: %w|1 2 3 4 5 6|) }
|
32
|
+
|
33
|
+
it 'should return the array of range to include index you specify' do
|
34
|
+
should == %w|1 2 3 4|
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when specify the range is exluded in the array' do
|
39
|
+
subject { searcher(pattern, result, before_context: '3').extended_items(1) }
|
40
|
+
|
41
|
+
let(:pattern) { 'fuga' }
|
42
|
+
let(:result) { double(:result, items: %w|1 2 3 4 5 6|) }
|
43
|
+
|
44
|
+
it 'should return the array includes range until index from first' do
|
45
|
+
should == %w|1 2|
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'you specify :after_context option' do
|
51
|
+
context 'when specify the range is included in the array' do
|
52
|
+
subject { searcher(pattern, result, after_context: '3').extended_items(1) }
|
53
|
+
|
54
|
+
let(:pattern) { 'fuga' }
|
55
|
+
let(:result) { double(:result, items: %w|1 2 3 4 5 6|) }
|
56
|
+
|
57
|
+
it 'should return the array of range to include index you specify' do
|
58
|
+
should == %w|2 3 4 5|
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when specify the range is exluded in the array' do
|
63
|
+
subject { searcher(pattern, result, after_context: '3').extended_items(4) }
|
64
|
+
|
65
|
+
let(:pattern) { 'fuga' }
|
66
|
+
let(:result) { double(:result, items: %w|1 2 3 4 5 6|) }
|
67
|
+
|
68
|
+
it 'should return the array includes range until the end from index' do
|
69
|
+
should == %w|5 6|
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'you specify :context option' do
|
75
|
+
context 'when specify the range is included in the array' do
|
76
|
+
subject { searcher(pattern, result, context: '2').extended_items(3) }
|
77
|
+
|
78
|
+
let(:pattern) { 'fuga' }
|
79
|
+
let(:result) { double(:result, items: %w|1 2 3 4 5 6|) }
|
80
|
+
|
81
|
+
it 'should return the array of range to surround index you specify' do
|
82
|
+
should == %w|2 3 4 5 6|
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when specify the range is exluded in the array' do
|
87
|
+
subject { searcher(pattern, result, context: '5').extended_items(3) }
|
88
|
+
|
89
|
+
let(:pattern) { 'fuga' }
|
90
|
+
let(:result) { double(:result, items: %w|1 2 3 4 5 6|) }
|
91
|
+
|
92
|
+
it 'should return the array includes range to surround as much as possible' do
|
93
|
+
should == %w|1 2 3 4 5 6|
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
6
97
|
end
|
7
98
|
|
8
99
|
describe '#search' do
|
9
100
|
context 'when matches pattern in messages' do
|
10
|
-
subject { searcher(result).search
|
101
|
+
subject { searcher(pattern, result).search }
|
11
102
|
|
12
103
|
let(:pattern) { 'yare' }
|
13
|
-
let(:response) { File.read(File.join('spec', 'data', 'item-list.json')) }
|
14
104
|
let(:result) do
|
15
|
-
|
16
|
-
|
17
|
-
|
105
|
+
response = File.read(File.join('spec', 'data', 'item-list.json'))
|
106
|
+
HipchatSearcher::Result.new(response).tap do |r|
|
107
|
+
r.room = "Joestars"
|
108
|
+
end
|
18
109
|
end
|
19
110
|
let(:search_result) do
|
20
111
|
"\e[4;39;49mJoestars\e[0m" + "\n" + \
|
@@ -31,14 +122,14 @@ describe HipchatSearcher::Searcher do
|
|
31
122
|
end
|
32
123
|
|
33
124
|
context 'when matches pattern in many messages' do
|
34
|
-
subject { searcher(result).search
|
125
|
+
subject { searcher(pattern, result).search }
|
35
126
|
|
36
127
|
let(:pattern) { 'ze' }
|
37
|
-
let(:response) { File.read(File.join('spec', 'data', 'item-list.json')) }
|
38
128
|
let(:result) do
|
39
|
-
|
40
|
-
|
41
|
-
|
129
|
+
response = File.read(File.join('spec', 'data', 'item-list.json'))
|
130
|
+
HipchatSearcher::Result.new(response).tap do |r|
|
131
|
+
r.room = "Joestars"
|
132
|
+
end
|
42
133
|
end
|
43
134
|
let(:search_result) do
|
44
135
|
"\e[4;39;49mJoestars\e[0m" + "\n" + \
|
@@ -57,15 +148,140 @@ describe HipchatSearcher::Searcher do
|
|
57
148
|
end
|
58
149
|
end
|
59
150
|
|
151
|
+
context 'when search_option --before_context' do
|
152
|
+
subject { searcher(pattern, result, before_context: '1').search }
|
153
|
+
|
154
|
+
let(:pattern) { 'inu' }
|
155
|
+
let(:result) do
|
156
|
+
response = File.read(File.join('spec', 'data', 'item-list-with-overlap.json'))
|
157
|
+
HipchatSearcher::Result.new(response).tap do |r|
|
158
|
+
r.room = "Joestars"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
let(:search_result) do
|
162
|
+
"\e[4;39;49mJoestars\e[0m" + "\n" + \
|
163
|
+
" Date: 2014-06-10T08:36:09.281643+00:00" + "\n" + \
|
164
|
+
" @abdul: chirp chirp chirp" + "\n" + \
|
165
|
+
"\n" + \
|
166
|
+
" Date: 2014-06-11T19:20:47.726182+00:00" + "\n" + \
|
167
|
+
" @lggy: \e[0;31;49minu\e[0m zuki no kodomo ha migoroshiniha dekine-ze" + "\n" + \
|
168
|
+
"\n"
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should print the matched message and after context' do
|
172
|
+
expect do
|
173
|
+
subject
|
174
|
+
end.to output(search_result).to_stdout
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'when search_option --after_context' do
|
179
|
+
subject { searcher(pattern, result, after_context: '1').search }
|
180
|
+
|
181
|
+
let(:pattern) { 'rero' }
|
182
|
+
let(:result) do
|
183
|
+
response = File.read(File.join('spec', 'data', 'item-list-with-overlap.json'))
|
184
|
+
HipchatSearcher::Result.new(response).tap do |r|
|
185
|
+
r.room = "Joestars"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
let(:search_result) do
|
189
|
+
"\e[4;39;49mJoestars\e[0m" + "\n" + \
|
190
|
+
" Date: 2014-05-30T01:39:02.186319+00:00" + "\n" + \
|
191
|
+
" @noriaki: \e[0;31;49mrero\e[0m\e[0;31;49mrero\e[0m" + "\n" + \
|
192
|
+
"\n" + \
|
193
|
+
" Date: 2014-06-09T11:29:10.209014+00:00" + "\n" + \
|
194
|
+
" @polnareff: a... arinomama ima okotta koto wo hanasu ze" + "\n" + \
|
195
|
+
"\n"
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should print the matched message and after context' do
|
199
|
+
expect do
|
200
|
+
subject
|
201
|
+
end.to output(search_result).to_stdout
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'when search_option --context' do
|
206
|
+
subject { searcher(pattern, result, context: '2').search }
|
207
|
+
|
208
|
+
let(:pattern) { 'chirp' }
|
209
|
+
let(:result) do
|
210
|
+
response = File.read(File.join('spec', 'data', 'item-list-with-overlap.json'))
|
211
|
+
HipchatSearcher::Result.new(response).tap do |r|
|
212
|
+
r.room = "Joestars"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
let(:search_result) do
|
216
|
+
"\e[4;39;49mJoestars\e[0m" + "\n" + \
|
217
|
+
" Date: 2014-05-30T01:39:02.186319+00:00" + "\n" + \
|
218
|
+
" @noriaki: rerorero" + "\n" + \
|
219
|
+
"\n" + \
|
220
|
+
" Date: 2014-06-09T11:29:10.209014+00:00" + "\n" + \
|
221
|
+
" @polnareff: a... arinomama ima okotta koto wo hanasu ze" + "\n" + \
|
222
|
+
"\n" + \
|
223
|
+
" Date: 2014-06-10T08:36:09.281643+00:00" + "\n" + \
|
224
|
+
" @abdul: \e[0;31;49mchirp\e[0m \e[0;31;49mchirp\e[0m \e[0;31;49mchirp\e[0m" + "\n" + \
|
225
|
+
"\n" + \
|
226
|
+
" Date: 2014-06-11T19:20:47.726182+00:00" + "\n" + \
|
227
|
+
" @lggy: inu zuki no kodomo ha migoroshiniha dekine-ze" + "\n" + \
|
228
|
+
"\n"
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'should print the matched message and surround context' do
|
232
|
+
expect do
|
233
|
+
subject
|
234
|
+
end.to output(search_result).to_stdout
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context 'when match result overlaped and specify search options' do
|
239
|
+
subject { searcher(pattern, result, after_context: '2').search }
|
240
|
+
|
241
|
+
let(:pattern) { 'ze' }
|
242
|
+
let(:result) do
|
243
|
+
response = File.read(File.join('spec', 'data', 'item-list-with-overlap.json'))
|
244
|
+
HipchatSearcher::Result.new(response).tap do |r|
|
245
|
+
r.room = "Joestars"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
let(:search_result) do
|
249
|
+
"\e[4;39;49mJoestars\e[0m" + "\n" + \
|
250
|
+
" Date: 2014-05-30T01:38:16.741565+00:00" + "\n" + \
|
251
|
+
" @jotaro: yareyare da\e[0;31;49mze\e[0m" + "\n" + \
|
252
|
+
"\n" + \
|
253
|
+
" Date: 2014-05-30T01:39:02.186319+00:00" + "\n" + \
|
254
|
+
" @noriaki: rerorero" + "\n" + \
|
255
|
+
"\n" + \
|
256
|
+
" Date: 2014-06-09T11:29:10.209014+00:00" + "\n" + \
|
257
|
+
" @polnareff: a... arinomama ima okotta koto wo hanasu \e[0;31;49mze\e[0m" + "\n" + \
|
258
|
+
"\n" + \
|
259
|
+
" Date: 2014-06-10T08:36:09.281643+00:00" + "\n" + \
|
260
|
+
" @abdul: chirp chirp chirp" + "\n" + \
|
261
|
+
"\n" + \
|
262
|
+
" Date: 2014-06-11T19:20:47.726182+00:00" + "\n" + \
|
263
|
+
" @lggy: inu zuki no kodomo ha migoroshiniha dekine-\e[0;31;49mze\e[0m" + "\n" + \
|
264
|
+
"\n"
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'should print the matched message without overlap' do
|
268
|
+
expect do
|
269
|
+
subject
|
270
|
+
end.to output(search_result).to_stdout
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
60
274
|
context "when don't match pattern in messages" do
|
61
|
-
subject { searcher(result).search
|
275
|
+
subject { searcher(pattern, result).search }
|
62
276
|
|
63
|
-
let(:pattern)
|
64
|
-
let(:result)
|
65
|
-
|
277
|
+
let(:pattern) { 'abcd' }
|
278
|
+
let(:result) do
|
279
|
+
response = File.read(File.join('spec', 'data', 'item-list.json'))
|
280
|
+
HipchatSearcher::Result.new(response)
|
281
|
+
end
|
66
282
|
|
67
283
|
it { should be_nil }
|
68
|
-
|
284
|
+
|
69
285
|
it 'should no output to stdout' do
|
70
286
|
expect do
|
71
287
|
subject
|
@@ -74,11 +290,13 @@ p
|
|
74
290
|
end
|
75
291
|
|
76
292
|
context "when pattern can't convert regexp" do
|
77
|
-
subject { searcher(result).search
|
293
|
+
subject { searcher(pattern, result).search }
|
78
294
|
|
79
|
-
let(:pattern)
|
80
|
-
let(:result)
|
81
|
-
|
295
|
+
let(:pattern) { nil }
|
296
|
+
let(:result) do
|
297
|
+
response = File.read(File.join('spec', 'data', 'item-list.json'))
|
298
|
+
HipchatSearcher::Result.new(response)
|
299
|
+
end
|
82
300
|
|
83
301
|
it 'should raise exception' do
|
84
302
|
expect do
|
@@ -89,14 +307,24 @@ p
|
|
89
307
|
end
|
90
308
|
|
91
309
|
describe '#puts_search_result' do
|
310
|
+
def extended_items(path, pattern)
|
311
|
+
hash = JSON.parse(File.read(path))
|
312
|
+
items = ::Hashie::Mash.new(hash).items
|
313
|
+
items.map do |itm|
|
314
|
+
itm.extend(HipchatSearcher::Searcher::ItemExtention).tap do |i|
|
315
|
+
i.pattern = Regexp.new(pattern)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
92
320
|
context 'when only person in room' do
|
93
|
-
subject { searcher(
|
321
|
+
subject { searcher(pattern, result).puts_search_result(item) }
|
94
322
|
|
95
|
-
let(:pattern) {
|
323
|
+
let(:pattern) { 'yare' }
|
324
|
+
let(:result) { double(:result, room: 'Joestars') }
|
96
325
|
let(:item) do
|
97
|
-
|
98
|
-
|
99
|
-
::Hashie::Mash.new(hash).items.first
|
326
|
+
path = File.join('spec', 'data', 'item-list.json')
|
327
|
+
extended_items(path, pattern).first
|
100
328
|
end
|
101
329
|
|
102
330
|
let(:search_result) do
|
@@ -114,13 +342,13 @@ p
|
|
114
342
|
end
|
115
343
|
|
116
344
|
context 'when person and bot in room' do
|
117
|
-
subject { searcher(
|
345
|
+
subject { searcher(pattern, result).puts_search_result(item) }
|
118
346
|
|
119
|
-
let(:pattern) {
|
347
|
+
let(:pattern) { 'mgi166' }
|
348
|
+
let(:result) { double(:result, room: 'Joestars') }
|
120
349
|
let(:item) do
|
121
|
-
|
122
|
-
|
123
|
-
::Hashie::Mash.new(hash).items.first
|
350
|
+
path = File.join('spec', 'data', 'item-list-with-bot.json')
|
351
|
+
extended_items(path, pattern).first
|
124
352
|
end
|
125
353
|
|
126
354
|
let(:search_result) do
|
@@ -137,13 +365,13 @@ p
|
|
137
365
|
end
|
138
366
|
|
139
367
|
context "when user options specified but the user don't speak this message" do
|
140
|
-
subject {
|
368
|
+
subject { searcher(pattern, result, user: 'jotaro').puts_search_result(item) }
|
141
369
|
|
142
|
-
let(:pattern)
|
370
|
+
let(:pattern) { 'ze' }
|
371
|
+
let(:result) { double(:result, room: 'Joestars') }
|
143
372
|
let(:item) do
|
144
|
-
|
145
|
-
|
146
|
-
::Hashie::Mash.new(hash).items.last
|
373
|
+
path = File.join('spec', 'data', 'item-list.json')
|
374
|
+
extended_items(path, pattern).last
|
147
375
|
end
|
148
376
|
|
149
377
|
it 'should not print message' do
|
@@ -154,13 +382,13 @@ p
|
|
154
382
|
end
|
155
383
|
|
156
384
|
context "when user options specified and the user speak this message" do
|
157
|
-
subject {
|
385
|
+
subject { searcher(pattern, result, user: 'jotaro').puts_search_result(item) }
|
158
386
|
|
159
|
-
let(:pattern)
|
387
|
+
let(:pattern) { 'ze' }
|
388
|
+
let(:result) { double(:result, room: 'Joestars') }
|
160
389
|
let(:item) do
|
161
|
-
|
162
|
-
|
163
|
-
::Hashie::Mash.new(hash).items.first
|
390
|
+
path = File.join('spec', 'data', 'item-list.json')
|
391
|
+
extended_items(path, pattern).first
|
164
392
|
end
|
165
393
|
|
166
394
|
let(:search_result) do
|
@@ -177,21 +405,4 @@ p
|
|
177
405
|
end
|
178
406
|
end
|
179
407
|
end
|
180
|
-
|
181
|
-
describe '#contents' do
|
182
|
-
subject { searcher(double(:result)).contents(pattern, item) }
|
183
|
-
|
184
|
-
let(:pattern) { 'ze' }
|
185
|
-
let(:item) do
|
186
|
-
src = File.read(File.join('spec', 'data', 'item-list.json'))
|
187
|
-
hash = JSON.parse(src)
|
188
|
-
::Hashie::Mash.new(hash).items.first
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'should return string for search result contents' do
|
192
|
-
should == " Date: 2014-05-30T01:38:16.741565+00:00" + "\n" + \
|
193
|
-
" @jotaro: yareyare da\e[0;31;49mze\e[0m" + "\n" \
|
194
|
-
"\n"
|
195
|
-
end
|
196
|
-
end
|
197
408
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hipchat_searcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mgi166
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hipchat
|
@@ -149,13 +149,14 @@ files:
|
|
149
149
|
- lib/hipchat_searcher/searcher.rb
|
150
150
|
- lib/hipchat_searcher/version.rb
|
151
151
|
- spec/data/item-list-with-bot.json
|
152
|
+
- spec/data/item-list-with-overlap.json
|
152
153
|
- spec/data/item-list.json
|
153
154
|
- spec/data/room-list.txt
|
154
155
|
- spec/hipchat_searcher_spec.rb
|
155
156
|
- spec/lib/hipchat_searcher/result_spec.rb
|
156
157
|
- spec/lib/hipchat_searcher/searcher_spec.rb
|
157
158
|
- spec/spec_helper.rb
|
158
|
-
homepage:
|
159
|
+
homepage: https://github.com/mgi166/hipchat_searcher
|
159
160
|
licenses:
|
160
161
|
- MIT
|
161
162
|
metadata: {}
|
@@ -181,6 +182,7 @@ specification_version: 4
|
|
181
182
|
summary: Search hipchat log on terminal
|
182
183
|
test_files:
|
183
184
|
- spec/data/item-list-with-bot.json
|
185
|
+
- spec/data/item-list-with-overlap.json
|
184
186
|
- spec/data/item-list.json
|
185
187
|
- spec/data/room-list.txt
|
186
188
|
- spec/hipchat_searcher_spec.rb
|