move a method to pass rubocop limit: Class xxx has too many lines[101/100]
Signed-off-by: Li Yuanchao lyc163mail@163.com --- lib/git_mirror.rb | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 5f7fa6b..fef4aca 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -9,6 +9,8 @@ require 'json' # gem install PriorityQueue require 'priority_queue' require 'English' +require 'elasticsearch' +require_relative 'constants.rb'
# worker threads class GitMirror @@ -84,6 +86,7 @@ class MirrorMain @git_info = {} @defaults = {} @git_queue = Queue.new + @es_client = Elasticsearch::Client.new(url: "http://#%7BES_HOST%7D:#%7BES_PORT%7D") load_fork_info connection = Bunny.new('amqp://172.17.0.1:5672') connection.start @@ -108,16 +111,6 @@ class MirrorMain @defaults[project] = YAML.safe_load(File.open(defaults_file)) end
- def load_repo_file(repodir, project, fork_name) - git_repo = "#{project}/#{fork_name}" - @git_info[git_repo] = YAML.safe_load(File.open(repodir)) - @git_info[git_repo]['git_repo'] = git_repo - @git_info[git_repo].merge!(@defaults[project]) if @defaults[project] - fork_stat_init(git_repo) - @priority_queue.push git_repo, @priority - @priority += 1 - end - def traverse_repodir(repodir) if File.directory? repodir load_defaults(repodir) @@ -194,6 +187,17 @@ end
# main thread class MirrorMain + def load_repo_file(repodir, project, fork_name) + git_repo = "#{project}/#{fork_name}" + @git_info[git_repo] = YAML.safe_load(File.open(repodir)) + @git_info[git_repo]['git_repo'] = git_repo + @git_info[git_repo].merge!(@defaults[project]) if @defaults[project] + es_repo_update(git_repo, @git_info[git_repo]) + fork_stat_init(git_repo) + @priority_queue.push git_repo, @priority + @priority += 1 + end + def compare_refs(cur_refs, old_refs) new_refs = { heads: {} } cur_refs[:heads].each do |ref, commit_id| @@ -246,4 +250,12 @@ class MirrorMain load_repo_file(repo_dir, File.dirname(file), File.basename(file)) if File.file?(repo_dir) end end + + def es_repo_update(git_repo, repo_info) + body = { + "doc": repo_info, + "doc_as_upsert": true + } + @es_client.update(index: 'repo', type: '_doc', id: git_repo, body: body) + end end
- def es_repo_update(git_repo, repo_info)
- body = {
"doc": repo_info,
"doc_as_upsert": true
- }
- @es_client.update(index: 'repo', type: '_doc', id: git_repo, body: body)
you can also use compass-ci/lib/es_client.rb to create/update a doc in ES like :
es = ESClient.new(index: 'repo') es.put_source_by_id(git_repo, body) - if source exists, will update source - if source does exists, will create a new source
Thanks, Weitao
- end
end
2.23.0