diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-30 15:08:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-30 15:08:09 +0000 |
commit | 538fff823de57d1ba5317961aa43091de9dc007f (patch) | |
tree | c741665b338cc0d51ce5f73f5671e5eee8e69349 /app | |
parent | 3692e9f8a23386c627942ca2a9edd8c00af7e904 (diff) | |
download | gitlab-ce-538fff823de57d1ba5317961aa43091de9dc007f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/boards/components/issue_card_inner.vue | 9 | ||||
-rw-r--r-- | app/controllers/projects/commits_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/ci_status_helper.rb | 15 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 19 | ||||
-rw-r--r-- | app/models/commit.rb | 38 | ||||
-rw-r--r-- | app/models/commit_collection.rb | 28 | ||||
-rw-r--r-- | app/models/commit_with_pipeline.rb | 38 | ||||
-rw-r--r-- | app/presenters/commit_presenter.rb | 8 | ||||
-rw-r--r-- | app/serializers/commit_entity.rb | 4 | ||||
-rw-r--r-- | app/services/search/snippet_service.rb | 4 | ||||
-rw-r--r-- | app/views/projects/commits/_commit.html.haml | 5 | ||||
-rw-r--r-- | app/views/shared/projects/_project.html.haml | 2 |
13 files changed, 108 insertions, 66 deletions
diff --git a/app/assets/javascripts/boards/components/issue_card_inner.vue b/app/assets/javascripts/boards/components/issue_card_inner.vue index 7f554c99669..2acd92069ca 100644 --- a/app/assets/javascripts/boards/components/issue_card_inner.vue +++ b/app/assets/javascripts/boards/components/issue_card_inner.vue @@ -104,6 +104,13 @@ export default { helpLink() { return boardsStore.scopedLabels.helpLink; }, + validIssueWeight() { + if (_.isNumber(this.issue.weight)) { + return this.issue.weight >= 0; + } + + return false; + }, }, methods: { isIndexLessThanlimit(index) { @@ -212,7 +219,7 @@ export default { <issue-due-date v-if="issue.dueDate" :date="issue.dueDate" /> <issue-time-estimate v-if="issue.timeEstimate" :estimate="issue.timeEstimate" /> <issue-card-weight - v-if="issue.weight" + v-if="validIssueWeight" :weight="issue.weight" @click="filterByWeight(issue.weight)" /> diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 76705b4410c..3007b5f1518 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -72,7 +72,7 @@ class Projects::CommitsController < Projects::ApplicationController @repository.commits(@ref, path: @path, limit: @limit, offset: @offset) end - @commits = @commits.with_pipeline_status + @commits = @commits.with_latest_pipeline(@ref) @commits = set_commits_for_rendering(@commits) end diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 2f73fccabcf..7ddff9c1893 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -82,7 +82,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo # Get commits from repository # or from cache if already merged @commits = - set_commits_for_rendering(@merge_request.commits.with_pipeline_status) + set_commits_for_rendering(@merge_request.commits.with_latest_pipeline) render json: { html: view_to_html_string('projects/merge_requests/_commits') } end diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 144df676304..1f34a483071 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -64,7 +64,7 @@ module CiStatusHelper def ci_icon_for_status(status, size: 16) if detailed_status?(status) - return sprite_icon(status.icon) + return sprite_icon(status.icon, size: size) end icon_name = @@ -96,23 +96,29 @@ module CiStatusHelper sprite_icon(icon_name, size: size) end + def ci_icon_class_for_status(status) + group = detailed_status?(status) ? status.group : status.dasherize + + "ci-status-icon-#{group}" + end + def pipeline_status_cache_key(pipeline_status) "pipeline-status/#{pipeline_status.sha}-#{pipeline_status.status}" end - def render_commit_status(commit, ref: nil, tooltip_placement: 'left') + def render_commit_status(commit, status, ref: nil, tooltip_placement: 'left') project = commit.project path = pipelines_project_commit_path(project, commit, ref: ref) render_status_with_link( - commit.status(ref), + status, path, tooltip_placement: tooltip_placement, icon_size: 24) end def render_status_with_link(status, path = nil, type: _('pipeline'), tooltip_placement: 'left', cssclass: '', container: 'body', icon_size: 16) - klass = "ci-status-link ci-status-icon-#{status.dasherize} d-inline-flex #{cssclass}" + klass = "ci-status-link #{ci_icon_class_for_status(status)} d-inline-flex #{cssclass}" title = "#{type.titleize}: #{ci_label_for_status(status)}" data = { toggle: 'tooltip', placement: tooltip_placement, container: container } @@ -127,6 +133,7 @@ module CiStatusHelper def detailed_status?(status) status.respond_to?(:text) && + status.respond_to?(:group) && status.respond_to?(:label) && status.respond_to?(:icon) end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index b22a87e7cef..9a96429d3a9 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -281,16 +281,16 @@ module Ci end end - # Returns a Hash containing the latest pipeline status for every given + # Returns a Hash containing the latest pipeline for every given # commit. # - # The keys of this Hash are the commit SHAs, the values the statuses. + # The keys of this Hash are the commit SHAs, the values the pipelines. # - # commits - The list of commit SHAs to get the status for. + # commits - The list of commit SHAs to get the pipelines for. # ref - The ref to scope the data to (e.g. "master"). If the ref is not - # given we simply get the latest status for the commits, regardless - # of what refs their pipelines belong to. - def self.latest_status_per_commit(commits, ref = nil) + # given we simply get the latest pipelines for the commits, regardless + # of what refs the pipelines belong to. + def self.latest_pipeline_per_commit(commits, ref = nil) p1 = arel_table p2 = arel_table.alias @@ -304,15 +304,14 @@ module Ci cond = cond.and(p1[:ref].eq(p2[:ref])) if ref join = p1.join(p2, Arel::Nodes::OuterJoin).on(cond) - relation = select(:sha, :status) - .where(sha: commits) + relation = where(sha: commits) .where(p2[:id].eq(nil)) .joins(join.join_sources) relation = relation.where(ref: ref) if ref - relation.each_with_object({}) do |row, hash| - hash[row[:sha]] = row[:status] + relation.each_with_object({}) do |pipeline, hash| + hash[pipeline.sha] = pipeline end end diff --git a/app/models/commit.rb b/app/models/commit.rb index a442f607fbf..60a60f191d6 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -119,10 +119,22 @@ class Commit @raw = raw_commit @project = project - @statuses = {} @gpg_commit = Gitlab::Gpg::Commit.new(self) if project end + delegate \ + :pipelines, + :last_pipeline, + :latest_pipeline, + :latest_pipeline_for_project, + :set_latest_pipeline_for_ref, + :status, + to: :with_pipeline + + def with_pipeline + @with_pipeline ||= CommitWithPipeline.new(self) + end + def id raw.id end @@ -301,30 +313,6 @@ class Commit ) end - def pipelines - project.ci_pipelines.where(sha: sha) - end - - def last_pipeline - strong_memoize(:last_pipeline) do - pipelines.last - end - end - - def status(ref = nil) - return @statuses[ref] if @statuses.key?(ref) - - @statuses[ref] = status_for_project(ref, project) - end - - def status_for_project(ref, pipeline_project) - pipeline_project.ci_pipelines.latest_status_per_commit(id, ref)[id] - end - - def set_status_for_ref(ref, status) - @statuses[ref] = status - end - def signature return @signature if defined?(@signature) diff --git a/app/models/commit_collection.rb b/app/models/commit_collection.rb index e8df46e1cc3..6b303c52283 100644 --- a/app/models/commit_collection.rb +++ b/app/models/commit_collection.rb @@ -34,6 +34,20 @@ class CommitCollection end end + # Returns the collection with the latest pipeline for every commit pre-set. + # + # Setting the pipeline for each commit ahead of time removes the need for running + # a query for every commit we're displaying. + def with_latest_pipeline(ref = nil) + pipelines = project.ci_pipelines.latest_pipeline_per_commit(map(&:id), ref) + + each do |commit| + commit.set_latest_pipeline_for_ref(ref, pipelines[commit.id]) + end + + self + end + def unenriched commits.reject(&:gitaly_commit?) end @@ -65,20 +79,6 @@ class CommitCollection self end - # Sets the pipeline status for every commit. - # - # Setting this status ahead of time removes the need for running a query for - # every commit we're displaying. - def with_pipeline_status - statuses = project.ci_pipelines.latest_status_per_commit(map(&:id), ref) - - each do |commit| - commit.set_status_for_ref(ref, statuses[commit.id]) - end - - self - end - def respond_to_missing?(message, inc_private = false) commits.respond_to?(message, inc_private) end diff --git a/app/models/commit_with_pipeline.rb b/app/models/commit_with_pipeline.rb new file mode 100644 index 00000000000..f382ae8f55a --- /dev/null +++ b/app/models/commit_with_pipeline.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class CommitWithPipeline < SimpleDelegator + include Presentable + + def initialize(commit) + @latest_pipelines = {} + super(commit) + end + + def pipelines + project.ci_pipelines.where(sha: sha) + end + + def last_pipeline + strong_memoize(:last_pipeline) do + pipelines.last + end + end + + def latest_pipeline(ref = nil) + @latest_pipelines.fetch(ref) do |ref| + @latest_pipelines[ref] = latest_pipeline_for_project(ref, project) + end + end + + def latest_pipeline_for_project(ref, pipeline_project) + pipeline_project.ci_pipelines.latest_pipeline_per_commit(id, ref)[id] + end + + def set_latest_pipeline_for_ref(ref, pipeline) + @latest_pipelines[ref] = pipeline + end + + def status(ref = nil) + latest_pipeline(ref)&.status + end +end diff --git a/app/presenters/commit_presenter.rb b/app/presenters/commit_presenter.rb index fc9853733c1..f5b1e45c0e9 100644 --- a/app/presenters/commit_presenter.rb +++ b/app/presenters/commit_presenter.rb @@ -6,11 +6,15 @@ class CommitPresenter < Gitlab::View::Presenter::Delegated presents :commit def status_for(ref) - can?(current_user, :read_commit_status, commit.project) && commit.status(ref) + return unless can?(current_user, :read_commit_status, commit.project) + + commit.latest_pipeline(ref)&.detailed_status(current_user) end def any_pipelines? - can?(current_user, :read_pipeline, commit.project) && commit.pipelines.any? + return false unless can?(current_user, :read_pipeline, commit.project) + + commit.pipelines.any? end def web_url diff --git a/app/serializers/commit_entity.rb b/app/serializers/commit_entity.rb index a94e32478ce..ae3f1c6bbf5 100644 --- a/app/serializers/commit_entity.rb +++ b/app/serializers/commit_entity.rb @@ -35,8 +35,8 @@ class CommitEntity < API::Entities::Commit pipeline_project = options[:pipeline_project] || commit.project next unless pipeline_ref && pipeline_project - status = commit.status_for_project(pipeline_ref, pipeline_project) - next unless status + pipeline = commit.latest_pipeline_for_project(pipeline_ref, pipeline_project) + next unless pipeline&.status pipelines_project_commit_path(pipeline_project, commit.id, ref: pipeline_ref) end diff --git a/app/services/search/snippet_service.rb b/app/services/search/snippet_service.rb index 7c6c6878400..3c8847d3c18 100644 --- a/app/services/search/snippet_service.rb +++ b/app/services/search/snippet_service.rb @@ -9,9 +9,7 @@ module Search end def execute - snippets = SnippetsFinder.new(current_user).execute - - Gitlab::SnippetSearchResults.new(snippets, params[:search]) + Gitlab::SnippetSearchResults.new(current_user, params[:search]) end def scope diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 2c78e74be2f..0f913d11be1 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -6,7 +6,8 @@ - merge_request = local_assigns.fetch(:merge_request, nil) - project = local_assigns.fetch(:project) { merge_request&.project } - ref = local_assigns.fetch(:ref) { merge_request&.source_branch } -- commit_status = commit.present(current_user: current_user).status_for(ref) +- commit = commit.present(current_user: current_user) +- commit_status = commit.status_for(ref) - link = commit_path(project, commit, merge_request: merge_request) @@ -48,7 +49,7 @@ = render partial: 'projects/commit/ajax_signature', locals: { commit: commit } - if commit_status - = render_commit_status(commit, ref: ref) + = render_commit_status(commit, commit_status, ref: ref) .js-commit-pipeline-status{ data: { endpoint: pipelines_project_commit_path(project, commit.id, ref: ref) } } diff --git a/app/views/shared/projects/_project.html.haml b/app/views/shared/projects/_project.html.haml index bcce7cb52fb..5432607f82f 100644 --- a/app/views/shared/projects/_project.html.haml +++ b/app/views/shared/projects/_project.html.haml @@ -63,7 +63,7 @@ - if pipeline_status && can?(current_user, :read_cross_project) && project.pipeline_status.has_status? && can?(current_user, :read_build, project) - pipeline_path = pipelines_project_commit_path(project.pipeline_status.project, project.pipeline_status.sha, ref: project.pipeline_status.ref) %span.icon-wrapper.pipeline-status - = render 'ci/status/icon', status: project.commit.last_pipeline.detailed_status(current_user), tooltip_placement: 'top', path: pipeline_path + = render 'ci/status/icon', status: project.last_pipeline.detailed_status(current_user), tooltip_placement: 'top', path: pipeline_path - if project.archived %span.d-flex.icon-wrapper.badge.badge-warning archived |