diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-12-20 10:25:09 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-12-20 10:25:09 +0000 |
commit | fd1811d36434df0d030ad7e35d595f1dd1bca5ea (patch) | |
tree | 8ea9071cee778b5a6de3fb41bb81b26104153213 /app/models | |
parent | 30ea58dabb8ea468c355b3456cf4fc14576a6e07 (diff) | |
parent | febb0b9a8014f5b480ff7baab1d189fce49210a5 (diff) | |
download | gitlab-ce-layout-nav-es-module.tar.gz |
Merge branch 'master' into layout-nav-es-modulelayout-nav-es-module
* master: (21 commits)
Prevent some specs from mangling the gitlab-shell checkout
Line up search dropdown with other nav dropdowns
Fix onion-skin re-entering state
Remove related links in MR widget when empty state
Show inline edit button for issues
Fix tags in the Activity tab not being clickable
Fix shortcut links on help page
Don't link LFS-objects multiple times.
[CE->EE] Fix spec/lib/gitlab/git/gitlab_projects_spec.rb
Tidy up the documentation of Gitlab HA/Gitlab Application
Make sure two except won't overwrite each other
Update axios.md
Remove transitionend event from GL dropdown
Preserve gem path so that we use the same gems
Load commit in batches for pipelines#index
BlobViewer::PackageJson - if private link to homepage
Do not generate links for private NPM modules in blob view
Remove block styling from search dropdown
Fix sidebar height when performance bar enabled
Remove all dropdown animations and set display: none if they're not open
...
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob_viewer/dependency_manager.rb | 13 | ||||
-rw-r--r-- | app/models/blob_viewer/package_json.rb | 18 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 13 | ||||
-rw-r--r-- | app/models/commit.rb | 20 | ||||
-rw-r--r-- | app/models/repository.rb | 12 |
5 files changed, 64 insertions, 12 deletions
diff --git a/app/models/blob_viewer/dependency_manager.rb b/app/models/blob_viewer/dependency_manager.rb index a8d9be945dc..cc4950240af 100644 --- a/app/models/blob_viewer/dependency_manager.rb +++ b/app/models/blob_viewer/dependency_manager.rb @@ -27,10 +27,17 @@ module BlobViewer private - def package_name_from_json(key) - prepare! + def json_data + @json_data ||= begin + prepare! + JSON.parse(blob.data) + rescue + {} + end + end - JSON.parse(blob.data)[key] rescue nil + def package_name_from_json(key) + json_data[key] end def package_name_from_method_call(name) diff --git a/app/models/blob_viewer/package_json.rb b/app/models/blob_viewer/package_json.rb index 09221efb56c..46cd2f04f4d 100644 --- a/app/models/blob_viewer/package_json.rb +++ b/app/models/blob_viewer/package_json.rb @@ -16,7 +16,25 @@ module BlobViewer @package_name ||= package_name_from_json('name') end + def package_type + private? ? 'private package' : super + end + def package_url + private? ? homepage : npm_url + end + + private + + def private? + !!json_data['private'] + end + + def homepage + json_data['homepage'] + end + + def npm_url "https://www.npmjs.com/package/#{package_name}" end end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 28f154581a9..d4690da3be6 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -287,8 +287,12 @@ module Ci Ci::Pipeline.truncate_sha(sha) end + # NOTE: This is loaded lazily and will never be nil, even if the commit + # cannot be found. + # + # Use constructs like: `pipeline.commit.present?` def commit - @commit ||= project.commit_by(oid: sha) + @commit ||= Commit.lazy(project, sha) end def branch? @@ -338,12 +342,9 @@ module Ci end def latest? - return false unless ref - - commit = project.commit(ref) - return false unless commit + return false unless ref && commit.present? - commit.sha == sha + project.commit(ref) == commit end def retried diff --git a/app/models/commit.rb b/app/models/commit.rb index 13c31111134..2be07ca7d3c 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -86,6 +86,20 @@ class Commit def valid_hash?(key) !!(/\A#{COMMIT_SHA_PATTERN}\z/ =~ key) end + + def lazy(project, oid) + BatchLoader.for({ project: project, oid: oid }).batch do |items, loader| + items_by_project = items.group_by { |i| i[:project] } + + items_by_project.each do |project, commit_ids| + oids = commit_ids.map { |i| i[:oid] } + + project.repository.commits_by(oids: oids).each do |commit| + loader.call({ project: commit.project, oid: commit.id }, commit) if commit + end + end + end + end end attr_accessor :raw @@ -103,7 +117,7 @@ class Commit end def ==(other) - (self.class === other) && (raw == other.raw) + other.is_a?(self.class) && raw == other.raw end def self.reference_prefix @@ -224,8 +238,8 @@ class Commit notes.includes(:author) end - def method_missing(m, *args, &block) - @raw.__send__(m, *args, &block) # rubocop:disable GitlabSecurity/PublicSend + def method_missing(method, *args, &block) + @raw.__send__(method, *args, &block) # rubocop:disable GitlabSecurity/PublicSend end def respond_to_missing?(method, include_private = false) diff --git a/app/models/repository.rb b/app/models/repository.rb index 4ec8ec9c8b2..387428d90a6 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -118,6 +118,18 @@ class Repository @commit_cache[oid] = find_commit(oid) end + def commits_by(oids:) + return [] unless oids.present? + + commits = Gitlab::Git::Commit.batch_by_oid(raw_repository, oids) + + if commits.present? + Commit.decorate(commits, @project) + else + [] + end + end + def commits(ref, path: nil, limit: nil, offset: nil, skip_merges: false, after: nil, before: nil) options = { repo: raw_repository, |