ruboty-wiki_search 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6dc74c701462c6d88d517a34865138084efde665913f138afb0bd775ac4f0f72
4
+ data.tar.gz: b079b7d009e64c1a23745069b4579d4b4798d26aab47afbb170a3d01cd87fbe1
5
+ SHA512:
6
+ metadata.gz: c2150731bc03628fe0a1d52ccc29443437d02bd488d3a3e88b89382a4165ce48427de73360a1b5c5d001e3f7f631fe3aa43ae5d3982ed7d0e3c20e74f140f3c1
7
+ data.tar.gz: 10f09c609484cad620a3ecb2eaaa65c47dfd33eb032fd600c5cdc9ad3ca67989e10a0c9b56ef8cbacb723ffd4b0d54f439330bf76c699160e19df5b0183f1f84
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.env
11
+ /repos/*
12
+ !/repos/.gitkeep
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hiromi19860101@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 kimromi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Ruboty::WikiSearch
2
+
3
+ GitHub wiki search for Ruboty.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-wiki_search'
11
+ ```
12
+
13
+ ## Environment
14
+
15
+ ### `RUBOTY_WIKI_SEARCH_REPOS`
16
+
17
+ GitHub wiki clone url. ex:`https://github.com/kimromi/ruboty-wiki_search.wiki.git`
18
+
19
+ In case of private repository or GitHub Enterprise:
20
+ `https://[token]:x-oauth-basic@git.enterprise.domain/organization/repository.wiki.git`
21
+
22
+ able to specify multiple repositories, separated by commas.
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ # search
28
+ search wiki <string>
29
+ ```
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruboty/wiki_search'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'dotenv'
10
+ Dotenv.load
11
+
12
+ require 'ruboty'
13
+ Ruboty::CommandBuilder.new(ARGV).build.call
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require 'ruboty/wiki_search/actions/wiki_search'
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class WikiSearch < Base
6
+ on(
7
+ /wiki sync/,
8
+ name: 'sync',
9
+ description: 'git clone or git pull wiki repository'
10
+ )
11
+
12
+ on(
13
+ /wiki search (?<search_string>.+)/,
14
+ name: 'search',
15
+ description: 'search wiki'
16
+ )
17
+
18
+ def sync(message)
19
+ action(message).sync
20
+ end
21
+
22
+ def search(message)
23
+ action(message).search
24
+ end
25
+
26
+ private
27
+
28
+ def action(message)
29
+ Ruboty::WikiSearch::Actions::WikiSearch.new(message)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'digest/md5'
2
+
3
+ module Ruboty
4
+ module WikiSearch
5
+ module Actions
6
+ class WikiSearch < Ruboty::Actions::Base
7
+ def sync
8
+ Ruboty::WikiSearch::GitOperation.sync!
9
+ message.reply('wiki repository synced.')
10
+ rescue => e
11
+ message.reply("wiki repository sync error! #{e}")
12
+ end
13
+
14
+ def search
15
+ search_string = message.match_data[:search_string].strip
16
+
17
+ attachments = Ruboty::WikiSearch::GitOperation.search(search_string).each_with_object([]) do |(repo, detail), arr|
18
+ arr << {
19
+ color: "##{Digest::MD5.hexdigest(repo)[0..5]}",
20
+ author_name: repo,
21
+ author_link: detail[:url],
22
+ text: detail[:files].map {|f| "<#{detail[:url]}/#{f}}|#{f}>" }.join("\n"),
23
+ mrkdwn_in: %w(text),
24
+ }
25
+ end
26
+
27
+ message.reply(
28
+ "#{attachments.empty? ? 'No ' : ''}wiki search results: #{search_string}",
29
+ attachments: attachments
30
+ )
31
+ rescue => e
32
+ message.reply("wiki search error! #{e}")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,58 @@
1
+ require 'uri'
2
+ require 'git'
3
+
4
+ module Ruboty
5
+ module WikiSearch
6
+ module GitOperation
7
+ class << self
8
+ def search(string)
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$/, '')
19
+ end
20
+ end
21
+ end
22
+
23
+ def sync!
24
+ repo_urls.each do |url|
25
+ u = URI.parse(url)
26
+ if cloned?(u)
27
+ git = Git.open(sync_directory(u))
28
+ git.checkout('master')
29
+ git.pull
30
+ else
31
+ Git.clone(url, sync_directory(u))
32
+ end
33
+ end
34
+ end
35
+
36
+ def repo_urls
37
+ ENV['RUBOTY_WIKI_SEARCH_REPOS'].split(',')
38
+ end
39
+
40
+ def repos_directory
41
+ File.realpath("#{__dir__}/../../../repos")
42
+ end
43
+
44
+ def sync_directory(uri)
45
+ "#{repos_directory}/#{uri.host}#{uri.path.gsub(/\.wiki\.git$/, '')}"
46
+ end
47
+
48
+ def cloned?(uri)
49
+ dir = sync_directory(uri)
50
+ Dir.exist?(dir) && Git.open(dir)
51
+ rescue ArgumentError
52
+ FileUtils.rm_rf(dir)
53
+ false
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module WikiSearch
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'ruboty'
2
+ require 'ruboty/wiki_search/version'
3
+ require 'ruboty/wiki_search/git_operation'
4
+ require 'ruboty/handlers/wiki_search'
data/repos/.gitkeep ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/wiki_search/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ruboty-wiki_search'
7
+ spec.version = Ruboty::WikiSearch::VERSION
8
+ spec.authors = %w(kimromi)
9
+ spec.email = %w(kimromi4@gmail.com)
10
+
11
+ spec.summary = %q{GitHub wiki search for Ruboty}
12
+ spec.description = %q{GitHub wiki search for Ruboty}
13
+ spec.homepage = 'https://github.com/kimromi/ruboty-wiki_search'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'ruboty'
24
+ spec.add_dependency 'git'
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'dotenv'
28
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-wiki_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kimromi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: GitHub wiki search for Ruboty
84
+ email:
85
+ - kimromi4@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/ruboty/handlers/wiki_search.rb
99
+ - lib/ruboty/wiki_search.rb
100
+ - lib/ruboty/wiki_search/actions/wiki_search.rb
101
+ - lib/ruboty/wiki_search/git_operation.rb
102
+ - lib/ruboty/wiki_search/version.rb
103
+ - repos/.gitkeep
104
+ - ruboty-wiki_search.gemspec
105
+ homepage: https://github.com/kimromi/ruboty-wiki_search
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: GitHub wiki search for Ruboty
129
+ test_files: []