gitlab-elasticsearch-git 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -4
- data/.rspec +2 -0
- data/CHANGELOG +6 -0
- data/Gemfile +1 -3
- data/Gemfile.lock +24 -23
- data/README.md +4 -21
- data/lib/elasticsearch/git/model.rb +2 -2
- data/lib/elasticsearch/git/repository.rb +10 -1
- data/lib/elasticsearch/git/version.rb +1 -1
- data/spec/main_spec.rb +68 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/elastic_helper.rb +14 -0
- data/spec/support/seed_helper.rb +25 -0
- data/spec/support/test_repository.rb +11 -0
- metadata +13 -12
- data/test/lib/repository_test.rb +0 -43
- data/test/support/repo_info.rb +0 -3
- data/test/support/repository.rb +0 -9
- data/test/support/seed_helper.rb +0 -6
- data/test/test_helper.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c0282fc661a63a7df2bacfd3e4da215d2c689d0
|
4
|
+
data.tar.gz: 0b3267f71ed82e71bdc3f25b58a594dd2f91aa6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f0fe56d9a2bff37ffccc9f92de92f5494123fa2873f40f34876daca40340fc47f4f9143899bd6c28517da0c278476cd73215509237a3b2ccaebf87075819280
|
7
|
+
data.tar.gz: 6738e1e8628d01b6c1bee9e24632ef4f2914204d1287a9978b62595d12522d10933b4e7e9d00942e1ba3ac9fc6d01fe28e937756f2969683fd0e929dbd89115b
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gitlab-elasticsearch-git (0.0.
|
5
|
-
activemodel (~> 4.2
|
6
|
-
activesupport (~> 4.2
|
7
|
-
charlock_holmes (~> 0.7
|
8
|
-
elasticsearch-api (
|
9
|
-
elasticsearch-model
|
10
|
-
github-linguist (~> 4.7
|
4
|
+
gitlab-elasticsearch-git (0.0.9)
|
5
|
+
activemodel (~> 4.2)
|
6
|
+
activesupport (~> 4.2)
|
7
|
+
charlock_holmes (~> 0.7)
|
8
|
+
elasticsearch-api (~> 1.0)
|
9
|
+
elasticsearch-model (~> 0.1.8)
|
10
|
+
github-linguist (~> 4.7)
|
11
11
|
rugged (~> 0.23.3)
|
12
12
|
|
13
13
|
GEM
|
@@ -56,42 +56,43 @@ GEM
|
|
56
56
|
minitest (5.8.3)
|
57
57
|
multi_json (1.11.2)
|
58
58
|
multipart-post (2.0.0)
|
59
|
-
predicated (0.2.6)
|
60
59
|
pry (0.10.3)
|
61
60
|
coderay (~> 1.1.0)
|
62
61
|
method_source (~> 0.8.1)
|
63
62
|
slop (~> 3.4)
|
64
63
|
rake (10.5.0)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
rspec (3.4.0)
|
65
|
+
rspec-core (~> 3.4.0)
|
66
|
+
rspec-expectations (~> 3.4.0)
|
67
|
+
rspec-mocks (~> 3.4.0)
|
68
|
+
rspec-core (3.4.2)
|
69
|
+
rspec-support (~> 3.4.0)
|
70
|
+
rspec-expectations (3.4.0)
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
+
rspec-support (~> 3.4.0)
|
73
|
+
rspec-mocks (3.4.1)
|
74
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
75
|
+
rspec-support (~> 3.4.0)
|
76
|
+
rspec-support (3.4.1)
|
70
77
|
rugged (0.23.3)
|
71
|
-
sexp_processor (4.6.0)
|
72
78
|
slop (3.6.0)
|
73
79
|
thread_safe (0.3.5)
|
74
80
|
tzinfo (1.2.2)
|
75
81
|
thread_safe (~> 0.1)
|
76
|
-
wrong (0.7.1)
|
77
|
-
diff-lcs (~> 1.2.5)
|
78
|
-
predicated (~> 0.2.6)
|
79
|
-
ruby2ruby (>= 2.0.1)
|
80
|
-
ruby_parser (>= 3.0.1)
|
81
|
-
sexp_processor (>= 4.0)
|
82
82
|
|
83
83
|
PLATFORMS
|
84
84
|
ruby
|
85
85
|
|
86
86
|
DEPENDENCIES
|
87
|
-
bundler
|
88
87
|
charlock_holmes (~> 0.7.3)
|
89
88
|
elasticsearch-api
|
90
89
|
elasticsearch-model
|
91
90
|
github-linguist (~> 4.7.0)
|
92
91
|
gitlab-elasticsearch-git!
|
93
|
-
minitest
|
94
92
|
pry
|
95
93
|
rake
|
94
|
+
rspec
|
96
95
|
rugged
|
97
|
-
|
96
|
+
|
97
|
+
BUNDLED WITH
|
98
|
+
1.10.6
|
data/README.md
CHANGED
@@ -15,23 +15,8 @@ Now indexing text-like documents mo nore 1 mb size
|
|
15
15
|
Add this line to your application's Gemfile:
|
16
16
|
|
17
17
|
``` ruby
|
18
|
-
gem 'elasticsearch-git',
|
18
|
+
gem 'gitlab-elasticsearch-git', require 'elasticsearch-git'
|
19
19
|
|
20
|
-
# or
|
21
|
-
|
22
|
-
gem 'elasticsearch-git', github: 'zzet/elasticsearch-git', ref: 'last_ref'
|
23
|
-
```
|
24
|
-
|
25
|
-
And then execute:
|
26
|
-
|
27
|
-
``` bash
|
28
|
-
$ bundle
|
29
|
-
```
|
30
|
-
|
31
|
-
Or install it yourself as:
|
32
|
-
|
33
|
-
``` bash
|
34
|
-
$ gem install elasticsearch-git
|
35
20
|
```
|
36
21
|
|
37
22
|
## Usage
|
@@ -44,7 +29,9 @@ class Repository
|
|
44
29
|
project.id
|
45
30
|
end
|
46
31
|
|
47
|
-
|
32
|
+
def path_to_repo
|
33
|
+
'/path/to/your/repo'
|
34
|
+
end
|
48
35
|
end
|
49
36
|
|
50
37
|
Repository.__elasticsearch__.create_index! force: true
|
@@ -332,10 +319,6 @@ Project.last.repository.as_indexed_json
|
|
332
319
|
:message=>"first commit\n"}]}
|
333
320
|
```
|
334
321
|
|
335
|
-
## TODO
|
336
|
-
|
337
|
-
* Add Exceptions handlers for indexing (Error connections and timeouts)
|
338
|
-
|
339
322
|
## Contributing
|
340
323
|
|
341
324
|
1. Fork it ( http://github.com/zzet/elasticsearch-git/fork )
|
@@ -15,10 +15,10 @@ module Elasticsearch
|
|
15
15
|
env = if defined?(::Rails)
|
16
16
|
::Rails.env.to_s
|
17
17
|
else
|
18
|
-
|
18
|
+
nil
|
19
19
|
end
|
20
20
|
|
21
|
-
index_name [self.name.downcase, 'index', env].join('-')
|
21
|
+
index_name [self.name.downcase, 'index', env].compact.join('-')
|
22
22
|
|
23
23
|
settings \
|
24
24
|
index: {
|
@@ -5,6 +5,7 @@ require 'elasticsearch/git/model'
|
|
5
5
|
require 'elasticsearch/git/encoder_helper'
|
6
6
|
require 'elasticsearch/git/lite_blob'
|
7
7
|
require 'rugged'
|
8
|
+
require 'open3'
|
8
9
|
|
9
10
|
module Elasticsearch
|
10
11
|
module Git
|
@@ -86,10 +87,16 @@ module Elasticsearch
|
|
86
87
|
|
87
88
|
perform_bulk bulk_operations
|
88
89
|
end
|
90
|
+
|
91
|
+
ObjectSpace.garbage_collect
|
89
92
|
end
|
90
93
|
|
91
94
|
def perform_bulk(bulk_operations)
|
92
|
-
|
95
|
+
bulk_operations.compact!
|
96
|
+
|
97
|
+
return false if bulk_operations.empty?
|
98
|
+
|
99
|
+
client_for_indexing.bulk body: bulk_operations
|
93
100
|
end
|
94
101
|
|
95
102
|
|
@@ -162,6 +169,8 @@ module Elasticsearch
|
|
162
169
|
|
163
170
|
perform_bulk bulk_operations
|
164
171
|
end
|
172
|
+
|
173
|
+
ObjectSpace.garbage_collect
|
165
174
|
end
|
166
175
|
end
|
167
176
|
|
data/spec/main_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TestRepository do
|
4
|
+
before do
|
5
|
+
remove_index(TestRepository.index_name)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "creates an index" do
|
9
|
+
expect(index_exist?(TestRepository.index_name)).to be_falsey
|
10
|
+
|
11
|
+
TestRepository.__elasticsearch__.create_index!
|
12
|
+
|
13
|
+
expect(index_exist?(TestRepository.index_name)).to be_truthy
|
14
|
+
end
|
15
|
+
|
16
|
+
it "indexes all blobs and searches" do
|
17
|
+
repo = TestRepository.new
|
18
|
+
repo.index_blobs
|
19
|
+
|
20
|
+
TestRepository.__elasticsearch__.refresh_index!
|
21
|
+
|
22
|
+
expect(repo.search('def', type: :blob)[:blobs][:total_count]).to eq(4)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "indexes all commits and searches" do
|
26
|
+
repo = TestRepository.new
|
27
|
+
repo.index_commits
|
28
|
+
|
29
|
+
TestRepository.__elasticsearch__.refresh_index!
|
30
|
+
|
31
|
+
expect(repo.search('test', type: :commit)[:commits][:total_count]).to eq(2)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "searches through all types" do
|
35
|
+
repo = TestRepository.new
|
36
|
+
repo.index_commits
|
37
|
+
repo.index_blobs
|
38
|
+
|
39
|
+
TestRepository.__elasticsearch__.refresh_index!
|
40
|
+
|
41
|
+
expect(repo.search('test')[:commits][:total_count]).to eq(2)
|
42
|
+
expect(repo.search('def')[:blobs][:total_count]).to eq(4)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "it indexes specified commits" do
|
46
|
+
repo = TestRepository.new
|
47
|
+
repo.index_commits(
|
48
|
+
from_rev: '40f4a7a617393735a95a0bb67b08385bc1e7c66d',
|
49
|
+
to_rev: '732401c65e924df81435deb12891ef570167d2e2'
|
50
|
+
)
|
51
|
+
|
52
|
+
TestRepository.__elasticsearch__.refresh_index!
|
53
|
+
|
54
|
+
expect(repo.search('empty', type: :commit)[:commits][:total_count]).to eq(1)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "it indexes specified blobs" do
|
58
|
+
repo = TestRepository.new
|
59
|
+
repo.index_blobs(
|
60
|
+
from_rev: '40f4a7a617393735a95a0bb67b08385bc1e7c66d',
|
61
|
+
to_rev: '732401c65e924df81435deb12891ef570167d2e2'
|
62
|
+
)
|
63
|
+
|
64
|
+
TestRepository.__elasticsearch__.refresh_index!
|
65
|
+
|
66
|
+
expect(repo.search('Permission is hereby granted', type: :blob)[:blobs][:total_count]).to eq(1)
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'elasticsearch/git'
|
3
|
+
|
4
|
+
require_relative 'support/seed_helper'
|
5
|
+
require_relative 'support/elastic_helper'
|
6
|
+
require_relative 'support/test_repository'
|
7
|
+
|
8
|
+
SUPPORT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), '../support')
|
9
|
+
TEST_REPO_PATH = File.join(SUPPORT_PATH, 'gitlab-elasticsearch-git-test.git')
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.order = 'random'
|
13
|
+
config.include ElasticHelper
|
14
|
+
config.include SeedHelper
|
15
|
+
config.before(:all) { ensure_seeds }
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ElasticHelper
|
2
|
+
def index_exist?(index_name)
|
3
|
+
out, err, status = Open3.capture3("curl -XGET '#{elastic_url}/#{index_name}/'")
|
4
|
+
!out.include?('index_not_found_exception')
|
5
|
+
end
|
6
|
+
|
7
|
+
def remove_index(index_name)
|
8
|
+
system("curl -XDELETE '#{elastic_url}/#{index_name}/' > /dev/null 2>&1")
|
9
|
+
end
|
10
|
+
|
11
|
+
def elastic_url
|
12
|
+
'http://localhost:9200/'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module SeedHelper
|
4
|
+
GITLAB_URL = "git@gitlab.com:gitlab-org/gitlab-elasticsearch-git-test.git"
|
5
|
+
|
6
|
+
def ensure_seeds
|
7
|
+
if File.exists?(SUPPORT_PATH)
|
8
|
+
FileUtils.rm_r(SUPPORT_PATH)
|
9
|
+
end
|
10
|
+
|
11
|
+
FileUtils.mkdir_p(SUPPORT_PATH)
|
12
|
+
|
13
|
+
create_test_bare_repo
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_test_bare_repo
|
17
|
+
system(git_env, *%W(git clone --bare #{GITLAB_URL}), chdir: SUPPORT_PATH)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Prevent developer git configurations from being persisted to test
|
21
|
+
# repositories
|
22
|
+
def git_env
|
23
|
+
{'GIT_TEMPLATE_DIR' => ''}
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-elasticsearch-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Kumanyaev
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: elasticsearch-model
|
@@ -119,6 +119,7 @@ extensions: []
|
|
119
119
|
extra_rdoc_files: []
|
120
120
|
files:
|
121
121
|
- ".gitignore"
|
122
|
+
- ".rspec"
|
122
123
|
- CHANGELOG
|
123
124
|
- Gemfile
|
124
125
|
- Gemfile.lock
|
@@ -132,11 +133,11 @@ files:
|
|
132
133
|
- lib/elasticsearch/git/model.rb
|
133
134
|
- lib/elasticsearch/git/repository.rb
|
134
135
|
- lib/elasticsearch/git/version.rb
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
-
|
136
|
+
- spec/main_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
- spec/support/elastic_helper.rb
|
139
|
+
- spec/support/seed_helper.rb
|
140
|
+
- spec/support/test_repository.rb
|
140
141
|
homepage: https://gitlab.com/gitlab-org/gitlab-elasticsearch-git
|
141
142
|
licenses:
|
142
143
|
- MIT
|
@@ -162,8 +163,8 @@ signing_key:
|
|
162
163
|
specification_version: 4
|
163
164
|
summary: Elasticsearch integrations for git repositories.
|
164
165
|
test_files:
|
165
|
-
-
|
166
|
-
-
|
167
|
-
-
|
168
|
-
-
|
169
|
-
-
|
166
|
+
- spec/main_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/support/elastic_helper.rb
|
169
|
+
- spec/support/seed_helper.rb
|
170
|
+
- spec/support/test_repository.rb
|
data/test/lib/repository_test.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
|
4
|
-
class RepositoryTest < TestCase
|
5
|
-
def setup
|
6
|
-
@repository = Repository.new
|
7
|
-
@repository.repository_for_indexing(TEST_REPO_PATH)
|
8
|
-
Repository.__elasticsearch__.create_index! force: true
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_index_commits
|
12
|
-
commit_count = @repository.index_commits
|
13
|
-
assert { commit_count == RepoInfo::COMMIT_COUNT }
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_index_commits_after_first_push
|
17
|
-
commit_count = @repository.index_commits(
|
18
|
-
from_rev: "0000000000000000000000000000000000000000",
|
19
|
-
to_rev: @repository.repository_for_indexing.head.target.oid)
|
20
|
-
|
21
|
-
assert { commit_count == RepoInfo::COMMIT_COUNT }
|
22
|
-
end
|
23
|
-
|
24
|
-
#TODO write better assertions
|
25
|
-
def test_index_all_blobs_from_head
|
26
|
-
blob_count = @repository.index_blobs
|
27
|
-
Repository.__elasticsearch__.refresh_index!
|
28
|
-
|
29
|
-
result = @repository.search('def project_name_regex')
|
30
|
-
assert { result[:blobs][:total_count] == 1 }
|
31
|
-
end
|
32
|
-
|
33
|
-
#TODO write better assertions
|
34
|
-
def test_index_blobs_after_first_push
|
35
|
-
commit_count = @repository.index_blobs(
|
36
|
-
from_rev: "0000000000000000000000000000000000000000",
|
37
|
-
to_rev: @repository.repository_for_indexing.head.target.oid)
|
38
|
-
Repository.__elasticsearch__.refresh_index!
|
39
|
-
|
40
|
-
result = @repository.search('def project_name_regex')
|
41
|
-
assert { result[:blobs][:total_count] == 1 }
|
42
|
-
end
|
43
|
-
end
|
data/test/support/repo_info.rb
DELETED
data/test/support/repository.rb
DELETED
data/test/support/seed_helper.rb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
unless File.exists?(TEST_REPO_PATH)
|
2
|
-
puts 'Prepare seeds'
|
3
|
-
FileUtils.mkdir_p(SUPPORT_PATH)
|
4
|
-
system(*%W(git clone --bare https://gitlab.com/gitlab-org/gitlab-test.git), chdir: SUPPORT_PATH)
|
5
|
-
system(*%W(git checkout 5937ac0a7beb003549fc5fd26fc247adbce4a52e), chdir: SUPPORT_PATH)
|
6
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'pry'
|
4
|
-
require 'elasticsearch/git'
|
5
|
-
|
6
|
-
SUPPORT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), '../support')
|
7
|
-
TEST_REPO_PATH = File.join(SUPPORT_PATH, 'gitlab-test.git')
|
8
|
-
|
9
|
-
require_relative 'support/seed_helper'
|
10
|
-
require_relative 'support/repository'
|
11
|
-
require_relative 'support/repo_info'
|
12
|
-
|
13
|
-
Bundler.require
|
14
|
-
|
15
|
-
require 'wrong/adapters/minitest'
|
16
|
-
|
17
|
-
PROJECT_ROOT = File.join(Dir.pwd)
|
18
|
-
|
19
|
-
Wrong.config.color
|
20
|
-
|
21
|
-
Minitest.autorun
|
22
|
-
|
23
|
-
class TestCase < Minitest::Test
|
24
|
-
include Wrong
|
25
|
-
|
26
|
-
def fixtures_path
|
27
|
-
@path ||= File.expand_path(File.join(__FILE__, "../fixtures"))
|
28
|
-
end
|
29
|
-
end
|