diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-07-31 15:23:05 +0200 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-08-01 10:48:46 +0200 |
commit | 67de82cf5fa5a6408621cbf955c730e2825d9c39 (patch) | |
tree | 82b65479cc85b0426d09045d88f6d68d09cdcaf7 /lib | |
parent | e99564568b2fefab8973ce571594aaa888cf8494 (diff) | |
download | gitlab-ce-67de82cf5fa5a6408621cbf955c730e2825d9c39.tar.gz |
Add option to use CommitLanguages RPC
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/commit_service.rb | 7 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index a3bc79109f8..88529ba2c47 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -636,6 +636,33 @@ module Gitlab @attributes.attributes(path) end + def languages(ref = nil) + Gitlab::GitalyClient.migrate(:commit_languages) do |is_enabled| + if is_enabled + gitaly_commit_client.languages(ref) + else + ref ||= rugged.head.target_id + languages = Linguist::Repository.new(rugged, ref).languages + total = languages.map(&:last).sum + + languages = languages.map do |language| + name, share = language + color = Linguist::Language[name].color || "##{Digest::SHA256.hexdigest(name)[0...6]}" + { + value: (share.to_f * 100 / total).round(2), + label: name, + color: color, + highlight: color + } + end + + languages.sort do |x, y| + y[:value] <=> x[:value] + end + end + end + end + def gitaly_repository Gitlab::GitalyClient::Util.repository(@storage, @relative_path) end diff --git a/lib/gitlab/gitaly_client/commit_service.rb b/lib/gitlab/gitaly_client/commit_service.rb index c6e52b530b3..a834781b1f1 100644 --- a/lib/gitlab/gitaly_client/commit_service.rb +++ b/lib/gitlab/gitaly_client/commit_service.rb @@ -118,6 +118,13 @@ module Gitlab consume_commits_response(response) end + def languages(ref = nil) + request = Gitaly::CommitLanguagesRequest.new(repository: @gitaly_repo, revision: ref || '') + response = GitalyClient.call(@repository.storage, :commit_service, :commit_languages, request) + + response.languages.map { |l| { value: l.share.round(2), label: l.name, color: l.color, highlight: l.color } } + end + private def commit_diff_request_params(commit, options = {}) |