diff options
-rw-r--r-- | app/controllers/projects/cycle_analytics/events_controller.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/events.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/query_config.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/light_url_builder.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/cycle_analytics/events_spec.rb | 28 |
5 files changed, 55 insertions, 28 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index 49c7303dccc..86ed01b9ea4 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -1,40 +1,43 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationController + # TODO: fix authorization # before_action :authorize_read_cycle_analytics! + # TODO: refactor +event_hash+ + def issue - render_events(events.issue_events) + render_events(issues: events.issue_events) end def plan - render_events(events.plan_events) + render_events(commits: events.plan_events) end def code - render_events(events.code_events) + render_events(merge_requests: events.code_events) end def test - render_events(events.test_events) + render_events(builds: events.test_events) end def review - render_events(events.review_events) + render_events(merge_requests: events.review_events) end def staging - render_events(events.staging_events) + render_events(builds: events.staging_events) end def production - render_events(events.production_events) + render_events(issues: events.production_events) end private - def render_events(event_list) + def render_events(event_hash) respond_to do |format| format.html - format.json { render json: { events: event_list } } + format.json { render json: event_hash } end end diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index 66b30250c0f..88aff762b43 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -16,8 +16,13 @@ module Gitlab def plan_events @fetcher.fetch(stage: :plan).each do |event| event['total_time'] = distance_of_time_in_words(event['total_time'].to_f) - commits = event.delete('commits') - event['commit'] = first_time_reference_commit(commits, event) + commit = first_time_reference_commit(event.delete('commits'), event) + event['title'] = commit.title + event['url'] = Gitlab::LightUrlBuilder.build(entity: :commit_url, project: @project, id: commit.id) + event['sha'] = commit.short_id + event['author_name'] = commit.author.name + event['author_profile_url'] = Gitlab::LightUrlBuilder.build(entity: :user, id: commit.author.username) + event['author_avatar_url'] = Gitlab::LightUrlBuilder.build(entity: :user_avatar_url, id: commit.author.id) end end @@ -56,7 +61,7 @@ module Gitlab event['author_profile_url'] = Gitlab::LightUrlBuilder.build(entity: :user, id: event['author_username']) event['author_avatar_url'] = Gitlab::LightUrlBuilder.build(entity: :user_avatar_url, id: event['author_id']) - event.except('author_id', 'author_username') + event.except!('author_id', 'author_username') end def first_time_reference_commit(commits, event) diff --git a/lib/gitlab/cycle_analytics/query_config.rb b/lib/gitlab/cycle_analytics/query_config.rb index ae3dd43a81b..a544dbbf556 100644 --- a/lib/gitlab/cycle_analytics/query_config.rb +++ b/lib/gitlab/cycle_analytics/query_config.rb @@ -34,8 +34,7 @@ module Gitlab { start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at], end_time_attrs: [issue_metrics_table[:first_added_to_board_at], issue_metrics_table[:first_mentioned_in_commit_at]], - projections: [mr_diff_table[:st_commits].as('commits'), - issue_metrics_table[:first_mentioned_in_commit_at]] + projections: [mr_diff_table[:st_commits].as('commits')] } end diff --git a/lib/gitlab/light_url_builder.rb b/lib/gitlab/light_url_builder.rb index 9b5d28e731f..3cbb53241f2 100644 --- a/lib/gitlab/light_url_builder.rb +++ b/lib/gitlab/light_url_builder.rb @@ -23,8 +23,10 @@ module Gitlab user_url(@id) when :user_avatar_url user_avatar_url + when :commit_url + commit_url else - raise NotImplementedError.new("No URL builder defined for #{object.class}") + raise NotImplementedError.new("No URL builder defined for #{object.class}") end end @@ -32,14 +34,22 @@ module Gitlab def issue_url namespace_project_issue_url({ - namespace_id: @project.namespace, - project_id: @project, - id: @id - }.merge!(@opts)) + namespace_id: @project.namespace, + project_id: @project, + id: @id + }.merge!(@opts)) end def user_avatar_url User.find(@id).avatar_url end + + def commit_url + namespace_project_commit_url({ + namespace_id: @project.namespace, + project_id: @project, + id: @id + }.merge!(@opts)) + end end end diff --git a/spec/lib/gitlab/cycle_analytics/events_spec.rb b/spec/lib/gitlab/cycle_analytics/events_spec.rb index e4535f467ec..80a66693a37 100644 --- a/spec/lib/gitlab/cycle_analytics/events_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/events_spec.rb @@ -4,6 +4,7 @@ describe Gitlab::CycleAnalytics::Events do let(:project) { create(:project) } let(:from_date) { 10.days.ago } let(:user) { create(:user, :admin) } + let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } subject { described_class.new(project: project, from: from_date) } @@ -12,8 +13,6 @@ describe Gitlab::CycleAnalytics::Events do end describe '#issue_events' do - let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } - it 'has the total time' do expect(subject.issue_events.first['total_time']).to eq('2 days') end @@ -44,20 +43,32 @@ describe Gitlab::CycleAnalytics::Events do end describe '#plan_events' do - let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } + it 'has a title' do + expect(subject.plan_events.first['title']).not_to be_nil + end - it 'has the first referenced commit' do - expect(subject.plan_events.first['commit'].message).to eq('commit message') + it 'has a sha short ID' do + expect(subject.plan_events.first['sha']).not_to be_nil end it 'has the total time' do expect(subject.plan_events.first['total_time']).to eq('less than a minute') end + + it "has the author's URL" do + expect(subject.plan_events.first['author_profile_url']).not_to be_nil + end + + it "has the author's avatar URL" do + expect(subject.plan_events.first['author_avatar_url']).not_to be_nil + end + + it "has the author's name" do + expect(subject.plan_events.first['author_name']).not_to be_nil + end end describe '#code_events' do - let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } - before do create_commit_referencing_issue(context) end @@ -88,7 +99,6 @@ describe Gitlab::CycleAnalytics::Events do end describe '#test_events' do - let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let(:merge_request) { MergeRequest.first } let!(:pipeline) do create(:ci_pipeline, @@ -140,7 +150,6 @@ describe Gitlab::CycleAnalytics::Events do end describe '#staging_events' do - let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let(:merge_request) { MergeRequest.first } let!(:pipeline) do create(:ci_pipeline, @@ -152,6 +161,7 @@ describe Gitlab::CycleAnalytics::Events do before do pipeline.run! pipeline.succeed! + merge_merge_requests_closing_issue(context) deploy_master end |