elasticsearch-git 0.0.4 → 0.0.5
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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG +8 -0
- data/Gemfile +3 -3
- data/README.md +14 -2
- data/Rakefile +9 -0
- data/elasticsearch-git.gemspec +5 -5
- data/lib/elasticsearch/git/lite_blob.rb +1 -1
- data/lib/elasticsearch/git/model.rb +20 -2
- data/lib/elasticsearch/git/repository.rb +102 -112
- data/lib/elasticsearch/git/version.rb +1 -1
- data/test/lib/repository_test.rb +43 -0
- data/test/test_helper.rb +8 -0
- metadata +18 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55b0b79e7075658c15389e9fdd70fd50b0eb5af7
|
4
|
+
data.tar.gz: 46d05c192da782afe7303f0c85fc398ee13389ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d24b71254c1dce1e27c2f0a574aa49299eb451fd145524a6bc2e37ea06ab5f16b19cafd361a3d4a9f28149d88491dd0820bb52189cb6dd29d53f5d67ef4b70
|
7
|
+
data.tar.gz: 674709e3e2f99fca958a3854aebdebf3e8280126ea896ff07fb76be1176e9710b634f786aeb3a6010a3b361f1523cae07d0d360537d9a5d0697ae910c5914b33
|
data/.gitignore
CHANGED
data/CHANGELOG
ADDED
data/Gemfile
CHANGED
@@ -5,13 +5,13 @@ gemspec
|
|
5
5
|
|
6
6
|
gem 'elasticsearch-model', github: 'elasticsearch/elasticsearch-rails'
|
7
7
|
gem 'elasticsearch-api', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
|
8
|
-
gem 'rugged'
|
8
|
+
gem 'rugged'
|
9
9
|
gem 'bundler'
|
10
10
|
gem 'rake'
|
11
11
|
gem 'pry'
|
12
12
|
gem 'charlock_holmes', '~> 0.6.9'
|
13
13
|
gem 'gitlab-linguist', '~> 3.0.0'
|
14
14
|
gem 'minitest'
|
15
|
-
gem 'activesupport', '> 4.0.0'
|
16
|
-
gem 'activemodel', '> 4.0.0'
|
15
|
+
#gem 'activesupport', '> 4.0.0'
|
16
|
+
#gem 'activemodel', '> 4.0.0'
|
17
17
|
gem 'wrong'
|
data/README.md
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
# Elasticsearch::Git
|
2
2
|
|
3
|
-
[Elasticsearch](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model) integrations for git repositories
|
3
|
+
[Elasticsearch](https://github.com/elasticsearch/elasticsearch-rails/tree/master/elasticsearch-model) integrations for git repositories.
|
4
|
+
|
5
|
+
## NOTE
|
6
|
+
|
7
|
+
Now indexing text-like documents mo nore 1 mb size
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
8
12
|
|
9
13
|
``` ruby
|
10
|
-
gem 'elasticsearch-git'
|
14
|
+
gem 'elasticsearch-git', '~> 0.0.5'
|
15
|
+
|
16
|
+
# or
|
17
|
+
|
18
|
+
gem 'elasticsearch-git', github: 'zzet/elasticsearch-git', ref: 'last_ref'
|
11
19
|
```
|
12
20
|
|
13
21
|
And then execute:
|
@@ -53,6 +61,8 @@ Repository.search("query")
|
|
53
61
|
|
54
62
|
## Integration with Gitlab
|
55
63
|
|
64
|
+
[Sample (In Undev Gitlab fork)](https://github.com/zzet/gitlabhq/blob/master/app/elastic/repositories_search.rb)
|
65
|
+
|
56
66
|
``` ruby
|
57
67
|
# app/elastic/repositories_search.rb
|
58
68
|
module RepositoriesSearch
|
@@ -61,6 +71,8 @@ module RepositoriesSearch
|
|
61
71
|
included do
|
62
72
|
include Elasticsearch::Git::Repository
|
63
73
|
|
74
|
+
self.__elasticsearch__.client = Elasticsearch::Client.new host: Gitlab.config.elasticsearch.host, port: Gitlab.config.elasticsearch.port
|
75
|
+
|
64
76
|
def repository_id
|
65
77
|
project.id
|
66
78
|
end
|
data/Rakefile
CHANGED
data/elasticsearch-git.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'elasticsearch/git/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "elasticsearch-git"
|
8
8
|
spec.version = Elasticsearch::Git::VERSION
|
9
|
-
spec.authors = ["Andrey Kumanyaev"]
|
10
|
-
spec.email = ["me@zzet.org"]
|
9
|
+
spec.authors = ["Andrey Kumanyaev", "Evgeniy Sokovikov"]
|
10
|
+
spec.email = ["me@zzet.org", "skv-headless@yandex.ru"]
|
11
11
|
spec.summary = %q{Elasticsearch integrations for git repositories.}
|
12
12
|
spec.description = %q{Elasticsearch integrations for indexing git repositories.}
|
13
13
|
spec.homepage = "https://github.com/zzet/elasticsearch-git"
|
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'elasticsearch-model'
|
22
22
|
spec.add_runtime_dependency 'elasticsearch-api', '> 0.4.0'
|
23
|
-
spec.add_runtime_dependency 'rugged', '~> 0.
|
23
|
+
spec.add_runtime_dependency 'rugged', '~> 0.21.0'
|
24
24
|
spec.add_runtime_dependency 'charlock_holmes', '~> 0.6.9'
|
25
25
|
spec.add_runtime_dependency 'gitlab-linguist', '> 2.9.0'
|
26
|
-
spec.add_runtime_dependency 'activemodel', '~> 4.
|
27
|
-
spec.add_runtime_dependency 'activesupport', '~> 4.
|
26
|
+
spec.add_runtime_dependency 'activemodel', '~> 4.1.0'
|
27
|
+
spec.add_runtime_dependency 'activesupport', '~> 4.1.0'
|
28
28
|
end
|
@@ -29,6 +29,11 @@ module Elasticsearch
|
|
29
29
|
tokenizer: 'human_tokenizer',
|
30
30
|
filter: %w(lowercase asciifolding human_ngrams)
|
31
31
|
},
|
32
|
+
path_analyzer: {
|
33
|
+
type: 'custom',
|
34
|
+
tokenizer: 'path_tokenizer',
|
35
|
+
filter: %w(lowercase asciifolding path_ngrams)
|
36
|
+
},
|
32
37
|
sha_analyzer: {
|
33
38
|
type: 'custom',
|
34
39
|
tokenizer: 'sha_tokenizer',
|
@@ -37,7 +42,7 @@ module Elasticsearch
|
|
37
42
|
code_analyzer: {
|
38
43
|
type: 'custom',
|
39
44
|
tokenizer: 'standard',
|
40
|
-
filter: %w(lowercase asciifolding)
|
45
|
+
filter: %w(lowercase asciifolding code_stemmer)
|
41
46
|
}
|
42
47
|
},
|
43
48
|
tokenizer: {
|
@@ -52,7 +57,11 @@ module Elasticsearch
|
|
52
57
|
min_gram: 1,
|
53
58
|
max_gram: 20,
|
54
59
|
token_chars: %w(letter digit)
|
55
|
-
}
|
60
|
+
},
|
61
|
+
path_tokenizer: {
|
62
|
+
type: 'path_hierarchy',
|
63
|
+
reverse: true
|
64
|
+
},
|
56
65
|
},
|
57
66
|
filter: {
|
58
67
|
human_ngrams: {
|
@@ -64,6 +73,15 @@ module Elasticsearch
|
|
64
73
|
type: "edgeNGram",
|
65
74
|
min_gram: 8,
|
66
75
|
max_gram: 40
|
76
|
+
},
|
77
|
+
path_ngrams: {
|
78
|
+
type: "edgeNGram",
|
79
|
+
min_gram: 3,
|
80
|
+
max_gram: 15
|
81
|
+
},
|
82
|
+
code_stemmer: {
|
83
|
+
type: "stemmer",
|
84
|
+
name: "minimal_english"
|
67
85
|
}
|
68
86
|
}
|
69
87
|
}
|
@@ -21,7 +21,7 @@ module Elasticsearch
|
|
21
21
|
indexes :rid, type: :string, index: :not_analyzed
|
22
22
|
indexes :oid, type: :string, index_options: 'offsets', search_analyzer: :code_analyzer, index_analyzer: :code_analyzer
|
23
23
|
indexes :commit_sha, type: :string, index_options: 'offsets', search_analyzer: :code_analyzer, index_analyzer: :code_analyzer
|
24
|
-
indexes :path, type: :string,
|
24
|
+
indexes :path, type: :string, search_analyzer: :path_analyzer, index_analyzer: :path_analyzer
|
25
25
|
indexes :content, type: :string, index_options: 'offsets', search_analyzer: :code_analyzer, index_analyzer: :code_analyzer
|
26
26
|
indexes :language, type: :string, index: :not_analyzed
|
27
27
|
end
|
@@ -61,73 +61,24 @@ module Elasticsearch
|
|
61
61
|
# }
|
62
62
|
#
|
63
63
|
# For search from blobs use type 'blob'
|
64
|
-
def index_blobs(from_rev: nil, to_rev:
|
64
|
+
def index_blobs(from_rev: nil, to_rev: repository_for_indexing.last_commit.oid)
|
65
|
+
from, to = parse_revs(from_rev, to_rev)
|
65
66
|
|
66
|
-
|
67
|
-
begin
|
68
|
-
if to_rev != "0000000000000000000000000000000000000000"
|
69
|
-
raise unless repository_for_indexing.lookup(to_rev).type == :commit
|
70
|
-
end
|
71
|
-
rescue
|
72
|
-
raise ArgumentError, "'to_rev': '#{to_rev}' is a incorrect commit sha."
|
73
|
-
end
|
74
|
-
else
|
75
|
-
to_rev = repository_for_indexing.head.target
|
76
|
-
end
|
77
|
-
|
78
|
-
target_sha = to_rev
|
79
|
-
|
80
|
-
if from_rev.present?
|
81
|
-
begin
|
82
|
-
if from_rev != "0000000000000000000000000000000000000000"
|
83
|
-
raise unless repository_for_indexing.lookup(from_rev).type == :commit
|
84
|
-
end
|
85
|
-
rescue
|
86
|
-
raise ArgumentError, "'from_rev': '#{from_rev}' is a incorrect commit sha."
|
87
|
-
end
|
88
|
-
|
89
|
-
diff = repository_for_indexing.diff(from_rev, to_rev)
|
90
|
-
|
91
|
-
diff.deltas.reverse.each_with_index do |delta, step|
|
92
|
-
if delta.status == :deleted
|
93
|
-
b = LiteBlob.new(repository_for_indexing, delta.old_file)
|
94
|
-
delete_from_index_blob(b)
|
95
|
-
else
|
96
|
-
b = LiteBlob.new(repository_for_indexing, delta.new_file)
|
97
|
-
index_blob(b, target_sha)
|
98
|
-
end
|
67
|
+
diff = repository_for_indexing.diff(from, to)
|
99
68
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
recurse_blobs_index(repository_for_indexing.lookup(target_sha).tree, target_sha)
|
69
|
+
diff.deltas.reverse.each_with_index do |delta, step|
|
70
|
+
if delta.status == :deleted
|
71
|
+
next if delta.old_file[:mode].to_s(8) == "160000"
|
72
|
+
b = LiteBlob.new(repository_for_indexing, delta.old_file)
|
73
|
+
delete_from_index_blob(b)
|
106
74
|
else
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
# Run GC every 100 blobs
|
112
|
-
ObjectSpace.garbage_collect if step % 100 == 0
|
113
|
-
end
|
75
|
+
next if delta.new_file[:mode].to_s(8) == "160000"
|
76
|
+
b = LiteBlob.new(repository_for_indexing, delta.new_file)
|
77
|
+
index_blob(b, to)
|
114
78
|
end
|
115
|
-
end
|
116
|
-
end
|
117
79
|
|
118
|
-
|
119
|
-
|
120
|
-
tree.each_blob do |blob|
|
121
|
-
blob[:path] = path + blob[:name]
|
122
|
-
b = LiteBlob.new(repository_for_indexing, blob)
|
123
|
-
index_blob(b, target_sha)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Run GC every recurse step
|
127
|
-
ObjectSpace.garbage_collect
|
128
|
-
|
129
|
-
tree.each_tree do |nested_tree|
|
130
|
-
recurse_blobs_index(repository_for_indexing.lookup(nested_tree[:oid]), target_sha, "#{path}#{nested_tree[:name]}/")
|
80
|
+
# Run GC every 100 blobs
|
81
|
+
ObjectSpace.garbage_collect if step % 100 == 0
|
131
82
|
end
|
132
83
|
end
|
133
84
|
|
@@ -205,46 +156,23 @@ module Elasticsearch
|
|
205
156
|
# }
|
206
157
|
#
|
207
158
|
# For search from commits use type 'commit'
|
208
|
-
def index_commits(from_rev: nil, to_rev:
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
# If to_rev correct
|
213
|
-
begin
|
214
|
-
raise unless repository_for_indexing.lookup(to_rev).type == :commit
|
215
|
-
rescue
|
216
|
-
raise ArgumentError, "'to_rev': '#{to_rev}' is a incorrect commit sha."
|
217
|
-
end
|
159
|
+
def index_commits(from_rev: nil, to_rev: repository_for_indexing.last_commit.oid)
|
160
|
+
from, to = parse_revs(from_rev, to_rev)
|
161
|
+
range = [from, to].reject(&:nil?).join('..')
|
162
|
+
out, err, status = Open3.capture3("git log #{range} --format=\"%H\"", chdir: repository_for_indexing.path)
|
218
163
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
end
|
223
|
-
rescue
|
224
|
-
raise ArgumentError, "'from_rev': '#{from_rev}' is a incorrect commit sha."
|
225
|
-
end
|
164
|
+
if status.success? && err.blank?
|
165
|
+
#TODO use rugged walker!!!
|
166
|
+
commit_oids = out.split("\n")
|
226
167
|
|
227
|
-
|
228
|
-
# Find merge_base and reindex diff
|
229
|
-
if from_rev == "0000000000000000000000000000000000000000" && to_rev != repository_for_indexing.head.target
|
230
|
-
from_rev = repository_for_indexing.merge_base(to_rev, repository_for_indexing.head.target)
|
231
|
-
end
|
232
|
-
|
233
|
-
walker = Rugged::Walker.new(repository_for_indexing)
|
234
|
-
walker.push(to_rev)
|
235
|
-
|
236
|
-
if from_rev.present? && from_rev != "0000000000000000000000000000000000000000"
|
237
|
-
walker.hide(from_rev)
|
238
|
-
end
|
239
|
-
|
240
|
-
commits = walker.map { |c| c.oid }
|
241
|
-
walker.reset
|
242
|
-
|
243
|
-
commits.each_with_index do |commit, step|
|
168
|
+
commit_oids.each_with_index do |commit, step|
|
244
169
|
index_commit(repository_for_indexing.lookup(commit))
|
245
170
|
ObjectSpace.garbage_collect if step % 100 == 0
|
246
171
|
end
|
172
|
+
return commit_oids.count
|
247
173
|
end
|
174
|
+
|
175
|
+
0
|
248
176
|
end
|
249
177
|
|
250
178
|
def index_commit(commit)
|
@@ -276,6 +204,24 @@ module Elasticsearch
|
|
276
204
|
end
|
277
205
|
end
|
278
206
|
|
207
|
+
def parse_revs(from_rev, to_rev)
|
208
|
+
from = if index_new_branch?(from_rev)
|
209
|
+
if to_rev == repository_for_indexing.last_commit.oid
|
210
|
+
nil
|
211
|
+
else
|
212
|
+
merge_base(to_rev)
|
213
|
+
end
|
214
|
+
else
|
215
|
+
from_rev
|
216
|
+
end
|
217
|
+
|
218
|
+
return from, to_rev
|
219
|
+
end
|
220
|
+
|
221
|
+
def index_new_branch?(from)
|
222
|
+
from == '0000000000000000000000000000000000000000'
|
223
|
+
end
|
224
|
+
|
279
225
|
# Representation of repository as indexed json
|
280
226
|
# Attention: It can be very very very huge hash
|
281
227
|
def as_indexed_json(options = {})
|
@@ -289,7 +235,7 @@ module Elasticsearch
|
|
289
235
|
def index_blobs_array
|
290
236
|
result = []
|
291
237
|
|
292
|
-
target_sha = repository_for_indexing.head.target
|
238
|
+
target_sha = repository_for_indexing.head.target.oid
|
293
239
|
|
294
240
|
if repository_for_indexing.bare?
|
295
241
|
tree = repository_for_indexing.lookup(target_sha).tree
|
@@ -322,11 +268,11 @@ module Elasticsearch
|
|
322
268
|
result.push(
|
323
269
|
{
|
324
270
|
type: 'blob',
|
325
|
-
id: "#{repository_for_indexing.head.target}_#{path}#{blob[:name]}",
|
271
|
+
id: "#{repository_for_indexing.head.target.oid}_#{path}#{blob[:name]}",
|
326
272
|
rid: repository_id,
|
327
273
|
oid: b.id,
|
328
274
|
content: b.data,
|
329
|
-
commit_sha: repository_for_indexing.head.target
|
275
|
+
commit_sha: repository_for_indexing.head.target.oid
|
330
276
|
}
|
331
277
|
) if b.text?
|
332
278
|
end
|
@@ -376,6 +322,11 @@ module Elasticsearch
|
|
376
322
|
@repository_id
|
377
323
|
end
|
378
324
|
|
325
|
+
# For Overwrite
|
326
|
+
def self.repositories_count
|
327
|
+
10
|
328
|
+
end
|
329
|
+
|
379
330
|
unless defined?(path_to_repo)
|
380
331
|
def path_to_repo
|
381
332
|
if @path_to_repo.blank?
|
@@ -416,6 +367,13 @@ module Elasticsearch
|
|
416
367
|
def logger
|
417
368
|
@logger ||= Logger.new(STDOUT)
|
418
369
|
end
|
370
|
+
|
371
|
+
private
|
372
|
+
|
373
|
+
def merge_base(to_rev)
|
374
|
+
head_sha = repository_for_indexing.last_commit.oid
|
375
|
+
repository_for_indexing.merge_base(to_rev, head_sha)
|
376
|
+
end
|
419
377
|
end
|
420
378
|
|
421
379
|
module ClassMethods
|
@@ -440,7 +398,8 @@ module Elasticsearch
|
|
440
398
|
commitRepositoryFaset: {
|
441
399
|
terms: {
|
442
400
|
field: "commit.rid",
|
443
|
-
|
401
|
+
all_terms: true,
|
402
|
+
size: repositories_count
|
444
403
|
}
|
445
404
|
}
|
446
405
|
},
|
@@ -462,6 +421,19 @@ module Elasticsearch
|
|
462
421
|
}
|
463
422
|
end
|
464
423
|
|
424
|
+
if options[:highlight]
|
425
|
+
es_fields = fields.map { |field| field.split('^').first }.inject({}) do |memo, field|
|
426
|
+
memo[field.to_sym] = {}
|
427
|
+
memo
|
428
|
+
end
|
429
|
+
|
430
|
+
query_hash[:highlight] = {
|
431
|
+
pre_tags: ["gitlabelasticsearch→"],
|
432
|
+
post_tags: ["←gitlabelasticsearch"],
|
433
|
+
fields: es_fields
|
434
|
+
}
|
435
|
+
end
|
436
|
+
|
465
437
|
options[:order] = :default if options[:order].blank?
|
466
438
|
order = case options[:order].to_sym
|
467
439
|
when :recently_indexed
|
@@ -474,14 +446,10 @@ module Elasticsearch
|
|
474
446
|
|
475
447
|
query_hash[:sort] = order.blank? ? [:_score] : [order, :_score]
|
476
448
|
|
477
|
-
if options[:highlight]
|
478
|
-
#query_hash[:highlight] = { fields: options[:in].inject({}) { |a, o| a[o.to_sym] = {} } }
|
479
|
-
end
|
480
|
-
|
481
449
|
res = self.__elasticsearch__.search(query_hash)
|
482
450
|
{
|
483
451
|
results: res.results,
|
484
|
-
total_count: res.
|
452
|
+
total_count: res.size,
|
485
453
|
repositories: res.response["facets"]["commitRepositoryFaset"]["terms"]
|
486
454
|
}
|
487
455
|
end
|
@@ -496,7 +464,7 @@ module Elasticsearch
|
|
496
464
|
match: {
|
497
465
|
'blob.content' => {
|
498
466
|
query: "#{query}",
|
499
|
-
operator: :
|
467
|
+
operator: :and
|
500
468
|
}
|
501
469
|
}
|
502
470
|
}
|
@@ -506,13 +474,15 @@ module Elasticsearch
|
|
506
474
|
languageFacet: {
|
507
475
|
terms: {
|
508
476
|
field: :language,
|
509
|
-
|
477
|
+
all_terms: true,
|
478
|
+
size: 20
|
510
479
|
}
|
511
480
|
},
|
512
481
|
blobRepositoryFaset: {
|
513
482
|
terms: {
|
514
483
|
field: :rid,
|
515
|
-
|
484
|
+
all_terms: true,
|
485
|
+
size: repositories_count
|
516
486
|
}
|
517
487
|
}
|
518
488
|
},
|
@@ -552,8 +522,8 @@ module Elasticsearch
|
|
552
522
|
|
553
523
|
if options[:highlight]
|
554
524
|
query_hash[:highlight] = {
|
555
|
-
pre_tags: [""],
|
556
|
-
post_tags: [""],
|
525
|
+
pre_tags: ["gitlabelasticsearch→"],
|
526
|
+
post_tags: ["←gitlabelasticsearch"],
|
557
527
|
fields: {
|
558
528
|
"blob.content" => {},
|
559
529
|
"type" => "fvh",
|
@@ -566,11 +536,31 @@ module Elasticsearch
|
|
566
536
|
|
567
537
|
{
|
568
538
|
results: res.results,
|
569
|
-
total_count: res.
|
539
|
+
total_count: res.size,
|
570
540
|
languages: res.response["facets"]["languageFacet"]["terms"],
|
571
541
|
repositories: res.response["facets"]["blobRepositoryFaset"]["terms"]
|
572
542
|
}
|
573
543
|
end
|
544
|
+
|
545
|
+
def search_file_names(query, page: 1, per: 20, options: {})
|
546
|
+
query_hash = {
|
547
|
+
fields: ['blob.path'],
|
548
|
+
query: {
|
549
|
+
fuzzy: {
|
550
|
+
"repository.blob.path" => { value: query }
|
551
|
+
},
|
552
|
+
},
|
553
|
+
filter: {
|
554
|
+
term: {
|
555
|
+
"repository.blob.rid" => [options[:repository_id]].flatten
|
556
|
+
}
|
557
|
+
},
|
558
|
+
size: per,
|
559
|
+
from: per * (page - 1)
|
560
|
+
}
|
561
|
+
|
562
|
+
self.__elasticsearch__.search(query_hash)
|
563
|
+
end
|
574
564
|
end
|
575
565
|
end
|
576
566
|
end
|
@@ -0,0 +1,43 @@
|
|
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/test_helper.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require 'bundler/setup'
|
3
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, 'testme.git')
|
8
|
+
|
9
|
+
require_relative 'support/seed_helper'
|
10
|
+
require_relative 'support/repository'
|
11
|
+
require_relative 'support/repo_info'
|
4
12
|
|
5
13
|
Bundler.require
|
6
14
|
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Kumanyaev
|
8
|
+
- Evgeniy Sokovikov
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-09-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: elasticsearch-model
|
@@ -44,14 +45,14 @@ dependencies:
|
|
44
45
|
requirements:
|
45
46
|
- - ~>
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
48
|
+
version: 0.21.0
|
48
49
|
type: :runtime
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - ~>
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
55
|
+
version: 0.21.0
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: charlock_holmes
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,36 +87,38 @@ dependencies:
|
|
86
87
|
requirements:
|
87
88
|
- - ~>
|
88
89
|
- !ruby/object:Gem::Version
|
89
|
-
version: 4.
|
90
|
+
version: 4.1.0
|
90
91
|
type: :runtime
|
91
92
|
prerelease: false
|
92
93
|
version_requirements: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
95
|
- - ~>
|
95
96
|
- !ruby/object:Gem::Version
|
96
|
-
version: 4.
|
97
|
+
version: 4.1.0
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
99
|
name: activesupport
|
99
100
|
requirement: !ruby/object:Gem::Requirement
|
100
101
|
requirements:
|
101
102
|
- - ~>
|
102
103
|
- !ruby/object:Gem::Version
|
103
|
-
version: 4.
|
104
|
+
version: 4.1.0
|
104
105
|
type: :runtime
|
105
106
|
prerelease: false
|
106
107
|
version_requirements: !ruby/object:Gem::Requirement
|
107
108
|
requirements:
|
108
109
|
- - ~>
|
109
110
|
- !ruby/object:Gem::Version
|
110
|
-
version: 4.
|
111
|
+
version: 4.1.0
|
111
112
|
description: Elasticsearch integrations for indexing git repositories.
|
112
113
|
email:
|
113
114
|
- me@zzet.org
|
115
|
+
- skv-headless@yandex.ru
|
114
116
|
executables: []
|
115
117
|
extensions: []
|
116
118
|
extra_rdoc_files: []
|
117
119
|
files:
|
118
120
|
- .gitignore
|
121
|
+
- CHANGELOG
|
119
122
|
- Gemfile
|
120
123
|
- LICENSE.txt
|
121
124
|
- README.md
|
@@ -127,6 +130,9 @@ files:
|
|
127
130
|
- lib/elasticsearch/git/model.rb
|
128
131
|
- lib/elasticsearch/git/repository.rb
|
129
132
|
- lib/elasticsearch/git/version.rb
|
133
|
+
- test/lib/repository_test.rb
|
134
|
+
- test/support/repository.rb
|
135
|
+
- test/support/seed_helper.rb
|
130
136
|
- test/test_helper.rb
|
131
137
|
homepage: https://github.com/zzet/elasticsearch-git
|
132
138
|
licenses:
|
@@ -148,9 +154,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
154
|
version: '0'
|
149
155
|
requirements: []
|
150
156
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.0.
|
157
|
+
rubygems_version: 2.0.14
|
152
158
|
signing_key:
|
153
159
|
specification_version: 4
|
154
160
|
summary: Elasticsearch integrations for git repositories.
|
155
161
|
test_files:
|
162
|
+
- test/lib/repository_test.rb
|
163
|
+
- test/support/repository.rb
|
164
|
+
- test/support/seed_helper.rb
|
156
165
|
- test/test_helper.rb
|