ruboty-wiki_search 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37665dc5c1be2ac0461c97bc1cb4f56587d3dbcc0c9c5d9e4ba9440795200412
4
- data.tar.gz: 2941fc5df8e2ea69545aa42ff00e106db19c0d5c6aaf44e11aed3ae4a0283395
3
+ metadata.gz: dbd26a93067559b705b8f0e3275a6bba3660c3db65357e46820293c6f23db2cb
4
+ data.tar.gz: fe0a3fd30a8e6ab5d23f02530da853549bbb37af9bed8da8125aaf99495641b5
5
5
  SHA512:
6
- metadata.gz: 91a20f08b4fbc400974a4ccea38ebea0df4270756d095d136c801c8de869ec97a808f41b897895ab4dc2d45e86e6f6824f675b7e52663a5f87d33bd8474715c6
7
- data.tar.gz: 91da49201c6b6dbb1f535f60d9ce337d9ca52485565c69b1ba7191a1be3db0ef5f4a741628de86f928f9948796081bcf2a20b09666492cbae1dd90425ddacef2
6
+ metadata.gz: beaf7bb675f97ddc07ab42a5640e11c6caf1ee89a519d1ffda55c26c4818df39adeb6e899b7c1f58f887651e2f6de6b20a559010218a287dca413c3b5f46910e
7
+ data.tar.gz: 438b1393931195283f15d60820a72d181600bae5756461537a4aac46a7d18b19b24890640e847fa4a7d632b74f8b1170ce17a23ea44aa91fe3493a534e2bc8a8
data/README.md CHANGED
@@ -29,7 +29,8 @@ GitHub wiki repository cloned directory. ex:`/tmp`
29
29
 
30
30
  ```
31
31
  # search
32
- ruboty search <string>
32
+ ruboty search <search_string>
33
+ ruboty search repo:<repository> <search_string>
33
34
 
34
35
  # git clone or pull master branch repository
35
36
  ruboty sync
@@ -12,7 +12,7 @@ module Ruboty
12
12
  on(
13
13
  /search (?<search_string>.+)/,
14
14
  name: 'search',
15
- description: 'search wiki'
15
+ description: 'search wiki | options repo:<repository>'
16
16
  )
17
17
 
18
18
  def sync(message)
@@ -12,9 +12,10 @@ module Ruboty
12
12
  end
13
13
 
14
14
  def search
15
- search_string = message.match_data[:search_string].strip
15
+ search_params = search_params(message.match_data[:search_string].strip)
16
+ message.reply('set search text!') and return unless search_params[:text]
16
17
 
17
- attachments = Ruboty::WikiSearch::GitOperation.search(search_string).each_with_object([]) do |(repo, detail), arr|
18
+ attachments = Ruboty::WikiSearch::GitOperation.search(search_params).each_with_object([]) do |(repo, detail), arr|
18
19
  arr << {
19
20
  color: "##{Digest::MD5.hexdigest(repo)[0..5]}",
20
21
  author_name: repo,
@@ -25,13 +26,27 @@ module Ruboty
25
26
  end
26
27
 
27
28
  message.reply(
28
- "#{attachments.empty? ? 'No ' : ''}wiki search results: #{search_string}",
29
+ "#{attachments.empty? ? 'No ' : ''}wiki search results: #{search_params[:text]}",
29
30
  parse: 'none',
30
31
  attachments: attachments,
31
32
  )
33
+ puts attachments if ENV['DEBUG']
32
34
  rescue => e
33
35
  message.reply("wiki search error! #{e}")
34
36
  end
37
+
38
+ private
39
+
40
+ def search_params(string)
41
+ strings = string.gsub(/ /, ' ').split(' ')
42
+ repo = strings.select {|b| b.start_with?('repo:') }.first&.gsub(/^repo:/, '')
43
+ strings.delete("repo:#{repo}")
44
+
45
+ {
46
+ repo: repo,
47
+ text: strings.first,
48
+ }
49
+ end
35
50
  end
36
51
  end
37
52
  end
@@ -5,17 +5,19 @@ module Ruboty
5
5
  module WikiSearch
6
6
  module GitOperation
7
7
  class << self
8
- def search(string)
8
+ def search(text:, repo:nil)
9
9
  Dir.glob("#{repos_directory}/**/*.md").each_with_object({}) do |file_path, hash|
10
- name = file_path.split('/').last
11
- repo = file_path.split('/')[-3..-2].join('/')
12
- repo_url = "https://#{file_path.split('/')[-4..-2].join('/')}/wiki"
13
-
14
- if name =~ /#{string}/ || !File.readlines(file_path).grep(/#{string}/).empty?
15
- hash[repo] ||= {}
16
- hash[repo][:url] ||= repo_url
17
- hash[repo][:files] ||= []
18
- hash[repo][:files] << name.gsub(/\.md$/, '')
10
+ file_name = file_path.split('/').last
11
+ file_repo = file_path.split('/')[-3..-2].join('/')
12
+ file_repo_url = "https://#{file_path.split('/')[-4..-2].join('/')}/wiki"
13
+
14
+ next if repo && file_repo !~ /#{repo}/
15
+
16
+ if name =~ /#{text}/ || !File.readlines(file_path).grep(/#{text}/).empty?
17
+ hash[file_repo] ||= {}
18
+ hash[file_repo][:url] ||= file_repo_url
19
+ hash[file_repo][:files] ||= []
20
+ hash[file_repo][:files] << file_name.gsub(/\.md$/, '')
19
21
  end
20
22
  end
21
23
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module WikiSearch
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-wiki_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimromi