hipchat_searcher 0.0.1 → 0.0.2

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: 2006db1fe811be9753fc96fb820a59263d92168d
4
- data.tar.gz: 262e28b8397dead9223a35b50bb3b9df4edf872e
3
+ metadata.gz: 69cc10fd7c58d30a07200b217825b20c7b445a0b
4
+ data.tar.gz: 4dc3f4a9387f9111ee4fb06362a750ad8e1ef00e
5
5
  SHA512:
6
- metadata.gz: 5df17c395a593f1397b68b89b7265b29c16bcc37735dff21241f543de4ba3cca1f1e3ce191ca89610bca0d97de23a9413cc619361ba10dbf9c5e3aed523ad982
7
- data.tar.gz: 3eab7cf6cecdbe9c0ebabcb793b522eae83328a6912ee50fc49eb63c397205cb02dc3a7ea9c7d17624cf6c85d164b8464f7b2cda1896ea2eec777f1eb10e7f24
6
+ metadata.gz: 5118535bdbe1af759eb832d8bae11f94bc4f156110aab3086a0cf58440dcdef605fa3ab8629c1fbcbb0528962a125fb658e166d95863fd5467e97d40b3ec8982
7
+ data.tar.gz: f5dbf4a436b03cbcc865d22e01ee7dbd030da587b75a0ab499bca5ab38b78a17b42b727b4983434e9ed722f5d4955d8156c7d63bb5b7a9825677bb6dd8c74750
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # 0.0.2
2
+ ### Feature
3
+ * Enable to search Regexp on ignorecase.
4
+ * When specify -u option, It becomes searchable in the specified user.
5
+ * Specify multiple room name for using -r option.
6
+
7
+ ### Bugfix
8
+ * Specify -r option for japanese room name.
9
+
10
+ # 0.0.1
11
+ * Initial release on 2014-06-22.
data/README.md CHANGED
@@ -13,8 +13,8 @@ You will be able to search hipchat log more easily.
13
13
 
14
14
  ## Prepare
15
15
 
16
- * `hitchat_searcher` requires access token on [hipchat](https://www.hipchat.com/). so you visit [hipchat](https://www.hipchat.com/). login and get access token.
17
- * if you get access token, execute command like this.
16
+ * `hitchat_searcher` requires access token on [hipchat](https://www.hipchat.com/). so you visit [hipchat](https://www.hipchat.com/), login and get access token.
17
+ * If you get access token, execute command like this.
18
18
 
19
19
  ```
20
20
  echo {access_token} > ~/.hps
@@ -22,25 +22,33 @@ echo {access_token} > ~/.hps
22
22
 
23
23
  ## Usage
24
24
 
25
- * Search word in all room
25
+ `hipchat_searcher` search for a regular expression the words that you specify.
26
+
27
+ * Search the words in all room
26
28
 
27
29
  ```
28
30
  hps word
29
31
  ```
30
32
 
31
- * Search word in specified room
33
+ * Search the words in specified room
32
34
 
33
35
  ```
34
36
  hps word -r room-name
35
37
  ```
36
38
 
37
- * Search word since target date
39
+ * Search the words that specified user talks
40
+
41
+ ```
42
+ hps word -u user-name
43
+ ```
44
+
45
+ * Search the words since target date
38
46
 
39
47
  ```
40
48
  hps word -d 2014-01-01
41
49
  ```
42
50
 
43
- * Search word in archived room
51
+ * Search the words in archived room
44
52
 
45
53
  ```
46
54
  hps word -a
data/bin/hps CHANGED
@@ -1,10 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require 'hipchat_searcher'
4
- require 'optparse'
4
+ require 'slop'
5
+
6
+ hash = Slop.parse(help: true) do
7
+ banner 'Usage: hps [searchword] [options]'
8
+
9
+ HipchatSearcher::Options.with_value.each do |opt|
10
+ on *opt
11
+ end
12
+
13
+ HipchatSearcher::Options.with_boolean.each do |opt|
14
+ on *opt
15
+ end
16
+
17
+ on '-v', '--version', 'Print the version' do
18
+ puts HipchatSearcher::VERSION
19
+ exit 0
20
+ end
21
+ end.to_hash
5
22
 
6
- pattern = ARGV.shift
7
- hash = ARGV.getopts(HipchatSearcher::Options.short_names, *HipchatSearcher::Options.long_names)
8
23
  options = HipchatSearcher::Options.new(hash)
9
- command = HipchatSearcher::Command.new(pattern, options)
10
- command.run
24
+
25
+ # run command
26
+ HipchatSearcher::Command.run(ARGV.shift, options)
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "hipchat"
21
21
  spec.add_dependency "colorize"
22
22
  spec.add_dependency "hashie"
23
+ spec.add_dependency "slop"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.6"
25
26
  spec.add_development_dependency "rake"
@@ -6,12 +6,20 @@ module HipchatSearcher
6
6
  @config = Config.new
7
7
  end
8
8
 
9
+ def self.run(pattern, options)
10
+ new(pattern, options).run
11
+ end
12
+
9
13
  def run
14
+ all_room = Room.new(@config.token, @options.room_options).all_room
15
+
10
16
  rooms = if @options.room?
11
- [@options.room]
17
+ room_names = @options.room.split(',')
18
+ all_room.select do |r|
19
+ room_names.include?(r.name)
20
+ end
12
21
  else
13
- room = Room.new(@config.token, @options.room_options)
14
- room.room
22
+ all_room
15
23
  end
16
24
 
17
25
  message = Message.new(@config.token, @options.message_options)
@@ -2,22 +2,6 @@ require 'hashie/mash'
2
2
 
3
3
  module HipchatSearcher
4
4
  class Options < Hashie::Mash
5
- def archived
6
- self['a'] || self['archived']
7
- end
8
-
9
- def archived?
10
- !!self['a'] || !!self['archived']
11
- end
12
-
13
- def date
14
- self['d'] || self['date']
15
- end
16
-
17
- def date?
18
- !!self['d'] || !!self['date']
19
- end
20
-
21
5
  def message_options
22
6
  date? ? { date: date } : {}
23
7
  end
@@ -26,33 +10,26 @@ module HipchatSearcher
26
10
  archived? ? { 'include-archived' => true } : {}
27
11
  end
28
12
 
29
- def room
30
- self['r'] || self['room']
31
- end
32
-
33
- def room?
34
- !!self['r'] || !!self['room']
35
- end
36
-
37
- def user
38
- self['u'] || self['user']
39
- end
40
-
41
- def user?
42
- !!self['u'] || !!self['user']
43
- end
44
-
45
13
  def search_options
46
14
  user? ? { user: user } : {}
47
15
  end
48
16
 
49
17
  class << self
50
- def short_names
51
- 'a:d:h:r:u'
18
+
19
+ # [shortname, longname, description]
20
+ def with_value
21
+ [
22
+ ['r=', 'room=', 'Search only the log of the room that you specified'],
23
+ ['u=', 'user=', 'Search only the log that specified user talk'],
24
+ ['d=', 'date=', 'Search the log since specified date'],
25
+ ]
52
26
  end
53
27
 
54
- def long_names
55
- ['room' 'user', 'date', 'archived', 'help']
28
+ # [shortname, longname, description]
29
+ def with_boolean
30
+ [
31
+ ['a', 'archived', 'Include in the search of the room that have been archived']
32
+ ]
56
33
  end
57
34
  end
58
35
  end
@@ -32,7 +32,7 @@ module HipchatSearcher
32
32
  end
33
33
  end
34
34
 
35
- def room
35
+ def all_room
36
36
  result = Result.new(get_all_room)
37
37
  result.rooms
38
38
  end
@@ -12,12 +12,29 @@ module HipchatSearcher
12
12
  new(result, options).search(pattern)
13
13
  end
14
14
 
15
+ def contents(pattern, item)
16
+ date = date(item)
17
+ message = message(pattern, item)
18
+
19
+ "%s\n%s\n\n" % [date, message]
20
+ end
21
+
22
+ def puts_search_result(pattern, item)
23
+ contents = contents(pattern, item)
24
+ if option_user?
25
+ if @options[:user] == user_name(item)
26
+ puts_contents(contents)
27
+ end
28
+ else
29
+ puts_contents(contents)
30
+ end
31
+ end
32
+
15
33
  def search(pattern)
16
- pattern = Regexp.new(pattern)
34
+ pattern = Regexp.new(pattern, Regexp::IGNORECASE)
17
35
 
18
36
  @result.items.each do |item|
19
37
  if pattern =~ item.message
20
- @print_room ? nil : puts_room
21
38
  puts_search_result(pattern, item)
22
39
  end
23
40
  end
@@ -25,24 +42,45 @@ module HipchatSearcher
25
42
  nil
26
43
  end
27
44
 
28
- def room
29
- @result.room
45
+ private
46
+
47
+ def date(item)
48
+ " Date: #{item.date}"
49
+ end
50
+
51
+ def message(pattern, item)
52
+ msg = item.message.gsub(pattern) do |matched|
53
+ matched.colorize(:red)
54
+ end
55
+
56
+ name = user_name(item)
57
+ " @#{name}" + ': ' + msg
58
+ end
59
+
60
+ def option_user?
61
+ !!@options[:user]
62
+ end
63
+
64
+ def print_room?
65
+ !!@print_room
30
66
  end
31
67
 
32
68
  def puts_room
33
69
  @print_room = true
34
- puts room
70
+ puts room.underline
35
71
  end
36
72
 
37
- def puts_search_result(pattern, item)
38
- msg = item.message.gsub(pattern) do |matched|
39
- matched.underline
40
- end
73
+ def puts_contents(contents)
74
+ print_room? ? nil : puts_room
75
+ puts contents
76
+ end
77
+
78
+ def room
79
+ @result.room
80
+ end
41
81
 
42
- date = " Date: #{item.date}"
43
- name = item.from.mention_name rescue item.from
44
- msg = " @#{name}" + ': ' + msg
45
- puts "%s\n%s\n\n" % [date, msg]
82
+ def user_name(item)
83
+ item.from.mention_name rescue item.from
46
84
  end
47
85
  end
48
86
  end
@@ -1,3 +1,3 @@
1
1
  module HipchatSearcher
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -17,9 +17,9 @@ describe HipchatSearcher::Searcher do
17
17
  r
18
18
  end
19
19
  let(:search_result) do
20
- "Joestars" + "\n" + \
20
+ "\e[4;39;49mJoestars\e[0m" + "\n" + \
21
21
  " Date: 2014-05-30T01:38:16.741565+00:00" + "\n" + \
22
- " @jotaro: \e[4;39;49myare\e[0m\e[4;39;49myare\e[0m daze" + "\n" + \
22
+ " @jotaro: \e[0;31;49myare\e[0m\e[0;31;49myare\e[0m daze" + "\n" + \
23
23
  "\n"
24
24
  end
25
25
 
@@ -41,12 +41,12 @@ describe HipchatSearcher::Searcher do
41
41
  r
42
42
  end
43
43
  let(:search_result) do
44
- "Joestars" + "\n" + \
44
+ "\e[4;39;49mJoestars\e[0m" + "\n" + \
45
45
  " Date: 2014-05-30T01:38:16.741565+00:00" + "\n" + \
46
- " @jotaro: yareyare da\e[4;39;49mze\e[0m" + "\n" \
46
+ " @jotaro: yareyare da\e[0;31;49mze\e[0m" + "\n" \
47
47
  "\n" + \
48
48
  " Date: 2014-06-09T11:29:10.209014+00:00" + "\n" + \
49
- " @polnareff: a... arinomama ima okotta koto wo hanasu \e[4;39;49mze\e[0m" + "\n" + \
49
+ " @polnareff: a... arinomama ima okotta koto wo hanasu \e[0;31;49mze\e[0m" + "\n" + \
50
50
  "\n"
51
51
  end
52
52
 
@@ -65,7 +65,7 @@ describe HipchatSearcher::Searcher do
65
65
  let(:response) { File.read(File.join('spec', 'data', 'item-list.json')) }
66
66
 
67
67
  it { should be_nil }
68
-
68
+ p
69
69
  it 'should no output to stdout' do
70
70
  expect do
71
71
  subject
@@ -90,7 +90,7 @@ describe HipchatSearcher::Searcher do
90
90
 
91
91
  describe '#puts_search_result' do
92
92
  context 'when only person in room' do
93
- subject { searcher(double(:result)).puts_search_result(pattern, item) }
93
+ subject { searcher(double(:result, room: 'Joestars')).puts_search_result(pattern, item) }
94
94
 
95
95
  let(:pattern) { Regexp.new('yare') }
96
96
  let(:item) do
@@ -100,11 +100,13 @@ describe HipchatSearcher::Searcher do
100
100
  end
101
101
 
102
102
  let(:search_result) do
103
+ "\e[4;39;49mJoestars\e[0m" + "\n" + \
103
104
  " Date: 2014-05-30T01:38:16.741565+00:00" + "\n" + \
104
- " @jotaro: \e[4;39;49myare\e[0m\e[4;39;49myare\e[0m daze" + "\n\n"
105
+ " @jotaro: \e[0;31;49myare\e[0m\e[0;31;49myare\e[0m daze" + "\n" + \
106
+ "\n"
105
107
  end
106
108
 
107
- it 'should print string of search result' do
109
+ it 'should print message of search result' do
108
110
  expect do
109
111
  subject
110
112
  end.to output(search_result).to_stdout
@@ -112,7 +114,7 @@ describe HipchatSearcher::Searcher do
112
114
  end
113
115
 
114
116
  context 'when person and bot in room' do
115
- subject { searcher(double(:result)).puts_search_result(pattern, item) }
117
+ subject { searcher(double(:result, room: 'Joestars')).puts_search_result(pattern, item) }
116
118
 
117
119
  let(:pattern) { Regexp.new('mgi166') }
118
120
  let(:item) do
@@ -122,15 +124,74 @@ describe HipchatSearcher::Searcher do
122
124
  end
123
125
 
124
126
  let(:search_result) do
127
+ "\e[4;39;49mJoestars\e[0m" + "\n" + \
125
128
  ' Date: 2014-06-17T08:14:48.305590+00:00' + "\n" + \
126
- " @GitHub: \e[4;39;49mmgi166\e[0m commented on pull request 118 ..." + "\n\n"
129
+ " @GitHub: \e[0;31;49mmgi166\e[0m commented on pull request 118 ..." + "\n\n"
130
+ end
131
+
132
+ it 'should print message of search result' do
133
+ expect do
134
+ subject
135
+ end.to output(search_result).to_stdout
136
+ end
137
+ end
138
+
139
+ context "when user options specified but the user don't speak this message" do
140
+ subject { described_class.new(double(:result, room: 'Joestars'), user: 'jotaro').puts_search_result(pattern, item) }
141
+
142
+ let(:pattern) { 'ze' }
143
+ let(:item) do
144
+ src = File.read(File.join('spec', 'data', 'item-list.json'))
145
+ hash = JSON.parse(src)
146
+ ::Hashie::Mash.new(hash).items.last
147
+ end
148
+
149
+ it 'should not print message' do
150
+ expect do
151
+ subject
152
+ end.to output('').to_stdout
153
+ end
154
+ end
155
+
156
+ context "when user options specified and the user speak this message" do
157
+ subject { described_class.new(double(:result, room: 'Joestars'), user: 'jotaro').puts_search_result(pattern, item) }
158
+
159
+ let(:pattern) { 'ze' }
160
+ let(:item) do
161
+ src = File.read(File.join('spec', 'data', 'item-list.json'))
162
+ hash = JSON.parse(src)
163
+ ::Hashie::Mash.new(hash).items.first
164
+ end
165
+
166
+ let(:search_result) do
167
+ "\e[4;39;49mJoestars\e[0m" + "\n" + \
168
+ " Date: 2014-05-30T01:38:16.741565+00:00" + "\n" + \
169
+ " @jotaro: yareyare da\e[0;31;49mze\e[0m" + "\n" \
170
+ "\n"
127
171
  end
128
172
 
129
- it 'should print string of search result' do
173
+ it 'should print message for specified user' do
130
174
  expect do
131
175
  subject
132
176
  end.to output(search_result).to_stdout
133
177
  end
134
178
  end
135
179
  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
136
197
  end
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.1
4
+ version: 0.0.2
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-22 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hipchat
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: slop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +132,7 @@ extra_rdoc_files: []
118
132
  files:
119
133
  - ".gitignore"
120
134
  - ".travis.yml"
135
+ - CHANGELOG.md
121
136
  - Gemfile
122
137
  - LICENSE.txt
123
138
  - README.md
@@ -137,7 +152,6 @@ files:
137
152
  - spec/data/item-list.json
138
153
  - spec/data/room-list.txt
139
154
  - spec/hipchat_searcher_spec.rb
140
- - spec/lib/hipchat_searcher/options_spec.rb
141
155
  - spec/lib/hipchat_searcher/result_spec.rb
142
156
  - spec/lib/hipchat_searcher/searcher_spec.rb
143
157
  - spec/spec_helper.rb
@@ -170,7 +184,6 @@ test_files:
170
184
  - spec/data/item-list.json
171
185
  - spec/data/room-list.txt
172
186
  - spec/hipchat_searcher_spec.rb
173
- - spec/lib/hipchat_searcher/options_spec.rb
174
187
  - spec/lib/hipchat_searcher/result_spec.rb
175
188
  - spec/lib/hipchat_searcher/searcher_spec.rb
176
189
  - spec/spec_helper.rb
@@ -1,112 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe HipchatSearcher::Options do
4
- describe '#message_options' do
5
- context 'when self has "archived" key' do
6
- subject { described_class.new(hash).message_options }
7
- let(:hash) { {'d' => '2014-06-01' } }
8
-
9
- it 'should return hash include key "include-archived"' do
10
- should == { :date => '2014-06-01' }
11
- end
12
- end
13
-
14
- context "when self don't have 'archived' key" do
15
- subject { described_class.new(hash).message_options }
16
- let(:hash) { {'room' => 'room-name' } }
17
-
18
- it 'should return empty hash' do
19
- should be_empty
20
- end
21
- end
22
- end
23
-
24
- describe '#room_options' do
25
- context 'when self has "archived" key' do
26
- subject { described_class.new(hash).room_options }
27
- let(:hash) { {'archived' => true } }
28
-
29
- it 'should return hash include key "include-archived"' do
30
- should == {"include-archived" => true}
31
- end
32
- end
33
-
34
- context "when self don't have 'archived' key" do
35
- subject { described_class.new(hash).room_options }
36
- let(:hash) { {'d' => '2014-06-01' } }
37
-
38
- it 'should return empty hash' do
39
- should be_empty
40
- end
41
- end
42
- end
43
-
44
- describe '#room?' do
45
- context 'given hash has a "room" key as argument' do
46
- subject { described_class.new(hash).room? }
47
- let(:hash) { {'room' => 'room-name' } }
48
-
49
- it { should be_truthy }
50
- end
51
-
52
- context 'given hash has a "r" key as argument' do
53
- subject { described_class.new(hash).room? }
54
- let(:hash) { {'r' => 'room-name' } }
55
-
56
- it { should be_truthy }
57
- end
58
-
59
- context 'given hash have any other keys as argument' do
60
- subject { described_class.new(hash).room? }
61
- let(:hash) { {'other' => 'xxxx' } }
62
-
63
- it { should be_falsey }
64
- end
65
- end
66
-
67
- describe '#user?' do
68
- context 'given hash has a "user" key as argument' do
69
- subject { described_class.new(hash).user? }
70
- let(:hash) { {'user' => 'jotaro kujo' } }
71
-
72
- it { should be_truthy }
73
- end
74
-
75
- context 'given hash has a "u" key as argument' do
76
- subject { described_class.new(hash).user? }
77
- let(:hash) { {'u' => 'jojo' } }
78
-
79
- it { should be_truthy }
80
- end
81
-
82
- context 'given hash have any other keys as argument' do
83
- subject { described_class.new(hash).user? }
84
- let(:hash) { {'other' => 'xxxx' } }
85
-
86
- it { should be_falsey }
87
- end
88
- end
89
-
90
- describe '#date?' do
91
- context 'given hash has a "date" key as argument' do
92
- subject { described_class.new(hash).date? }
93
- let(:hash) { {'date' => '2014-06-1' } }
94
-
95
- it { should be_truthy }
96
- end
97
-
98
- context 'given hash has a "u" key as argument' do
99
- subject { described_class.new(hash).date? }
100
- let(:hash) { {'d' => '2014-06-1' } }
101
-
102
- it { should be_truthy }
103
- end
104
-
105
- context 'given hash have any other keys as argument' do
106
- subject { described_class.new(hash).date? }
107
- let(:hash) { {'other' => 'xxxx' } }
108
-
109
- it { should be_falsey }
110
- end
111
- end
112
- end