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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbd26a93067559b705b8f0e3275a6bba3660c3db65357e46820293c6f23db2cb
|
4
|
+
data.tar.gz: fe0a3fd30a8e6ab5d23f02530da853549bbb37af9bed8da8125aaf99495641b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beaf7bb675f97ddc07ab42a5640e11c6caf1ee89a519d1ffda55c26c4818df39adeb6e899b7c1f58f887651e2f6de6b20a559010218a287dca413c3b5f46910e
|
7
|
+
data.tar.gz: 438b1393931195283f15d60820a72d181600bae5756461537a4aac46a7d18b19b24890640e847fa4a7d632b74f8b1170ce17a23ea44aa91fe3493a534e2bc8a8
|
data/README.md
CHANGED
@@ -12,9 +12,10 @@ module Ruboty
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def search
|
15
|
-
|
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(
|
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: #{
|
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(
|
8
|
+
def search(text:, repo:nil)
|
9
9
|
Dir.glob("#{repos_directory}/**/*.md").each_with_object({}) do |file_path, hash|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if
|
15
|
-
|
16
|
-
|
17
|
-
hash[
|
18
|
-
hash[
|
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
|