Commit 26b7b28a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'fix_build_count_in_pipeline_success_maild' into 'master'

Fix job count in pipeline success mail

Closes #30483

See merge request gitlab-org/gitlab-ce!15827
parents cfb8d001 7edbc0f8
...@@ -228,6 +228,10 @@ module Ci ...@@ -228,6 +228,10 @@ module Ci
statuses.select(:stage).distinct.count statuses.select(:stage).distinct.count
end end
def total_size
statuses.count(:id)
end
def stages_names def stages_names
statuses.order(:stage_idx).distinct statuses.order(:stage_idx).distinct
.pluck(:stage, :stage_idx).map(&:first) .pluck(:stage, :stage_idx).map(&:first)
......
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
API API
%tr %tr
%td{ colspan: 2, style: "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#333333;font-size:15px;font-weight:300;line-height:1.4;padding:15px 5px;text-align:center;" } %td{ colspan: 2, style: "font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#333333;font-size:15px;font-weight:300;line-height:1.4;padding:15px 5px;text-align:center;" }
- job_count = @pipeline.statuses.latest.size - job_count = @pipeline.total_size
- stage_count = @pipeline.stages_count - stage_count = @pipeline.stages_count
successfully completed successfully completed
#{job_count} #{'job'.pluralize(job_count)} #{job_count} #{'job'.pluralize(job_count)}
......
...@@ -22,11 +22,11 @@ Committed by: <%= commit.committer_name %> ...@@ -22,11 +22,11 @@ Committed by: <%= commit.committer_name %>
<% end -%> <% end -%>
<% end -%> <% end -%>
<% build_count = @pipeline.statuses.latest.size -%> <% job_count = @pipeline.total_size -%>
<% stage_count = @pipeline.stages_count -%> <% stage_count = @pipeline.stages_count -%>
<% if @pipeline.user -%> <% if @pipeline.user -%>
Pipeline #<%= @pipeline.id %> ( <%= pipeline_url(@pipeline) %> ) triggered by <%= @pipeline.user.name %> ( <%= user_url(@pipeline.user) %> ) Pipeline #<%= @pipeline.id %> ( <%= pipeline_url(@pipeline) %> ) triggered by <%= @pipeline.user.name %> ( <%= user_url(@pipeline.user) %> )
<% else -%> <% else -%>
Pipeline #<%= @pipeline.id %> ( <%= pipeline_url(@pipeline) %> ) triggered by API Pipeline #<%= @pipeline.id %> ( <%= pipeline_url(@pipeline) %> ) triggered by API
<% end -%> <% end -%>
successfully completed <%= build_count %> <%= 'build'.pluralize(build_count) %> in <%= stage_count %> <%= 'stage'.pluralize(stage_count) %>. successfully completed <%= job_count %> <%= 'job'.pluralize(job_count) %> in <%= stage_count %> <%= 'stage'.pluralize(stage_count) %>.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
.well-segment.pipeline-info .well-segment.pipeline-info
.icon-container .icon-container
= icon('clock-o') = icon('clock-o')
= pluralize @pipeline.statuses.count(:id), "job" = pluralize @pipeline.total_size, "job"
- if @pipeline.ref - if @pipeline.ref
from from
= link_to @pipeline.ref, project_ref_path(@project, @pipeline.ref), class: "ref-name" = link_to @pipeline.ref, project_ref_path(@project, @pipeline.ref), class: "ref-name"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
%li.js-builds-tab-link %li.js-builds-tab-link
= link_to builds_project_pipeline_path(@project, @pipeline), data: {target: 'div#js-tab-builds', action: 'builds', toggle: 'tab' }, class: 'builds-tab' do = link_to builds_project_pipeline_path(@project, @pipeline), data: {target: 'div#js-tab-builds', action: 'builds', toggle: 'tab' }, class: 'builds-tab' do
Jobs Jobs
%span.badge.js-builds-counter= pipeline.statuses.count %span.badge.js-builds-counter= pipeline.total_size
- if failed_builds.present? - if failed_builds.present?
%li.js-failures-tab-link %li.js-failures-tab-link
= link_to failures_project_pipeline_path(@project, @pipeline), data: {target: 'div#js-tab-failures', action: 'failures', toggle: 'tab' }, class: 'failures-tab' do = link_to failures_project_pipeline_path(@project, @pipeline), data: {target: 'div#js-tab-failures', action: 'failures', toggle: 'tab' }, class: 'failures-tab' do
......
---
title: fix build count in pipeline success mail
merge_request: 15827
author: Christiaan Van den Poel
type: fixed
...@@ -152,7 +152,7 @@ describe 'Pipeline', :js do ...@@ -152,7 +152,7 @@ describe 'Pipeline', :js do
end end
it 'shows counter in Jobs tab' do it 'shows counter in Jobs tab' do
expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s) expect(page.find('.js-builds-counter').text).to eq(pipeline.total_size.to_s)
end end
it 'shows Pipeline tab as active' do it 'shows Pipeline tab as active' do
...@@ -248,7 +248,7 @@ describe 'Pipeline', :js do ...@@ -248,7 +248,7 @@ describe 'Pipeline', :js do
end end
it 'shows counter in Jobs tab' do it 'shows counter in Jobs tab' do
expect(page.find('.js-builds-counter').text).to eq(pipeline.statuses.count.to_s) expect(page.find('.js-builds-counter').text).to eq(pipeline.total_size.to_s)
end end
it 'shows Jobs tab as active' do it 'shows Jobs tab as active' do
......
...@@ -1530,4 +1530,16 @@ describe Ci::Pipeline, :mailer do ...@@ -1530,4 +1530,16 @@ describe Ci::Pipeline, :mailer do
expect(query_count).to eq(1) expect(query_count).to eq(1)
end end
end end
describe '#total_size' do
let!(:build_job1) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
let!(:build_job2) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
let!(:test_job_failed_and_retried) { create(:ci_build, :failed, :retried, pipeline: pipeline, stage_idx: 1) }
let!(:second_test_job) { create(:ci_build, pipeline: pipeline, stage_idx: 1) }
let!(:deploy_job) { create(:ci_build, pipeline: pipeline, stage_idx: 2) }
it 'returns all jobs (including failed and retried)' do
expect(pipeline.total_size).to eq(5)
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment