Commit 1b5b2eac authored by James Lopez's avatar James Lopez

added missing fields to plan events and updated spec

parent 8f7266cd
class Projects::CycleAnalytics::EventsController < Projects::ApplicationController class Projects::CycleAnalytics::EventsController < Projects::ApplicationController
# TODO: fix authorization
# before_action :authorize_read_cycle_analytics! # before_action :authorize_read_cycle_analytics!
# TODO: refactor +event_hash+
def issue def issue
render_events(events.issue_events) render_events(issues: events.issue_events)
end end
def plan def plan
render_events(events.plan_events) render_events(commits: events.plan_events)
end end
def code def code
render_events(events.code_events) render_events(merge_requests: events.code_events)
end end
def test def test
render_events(events.test_events) render_events(builds: events.test_events)
end end
def review def review
render_events(events.review_events) render_events(merge_requests: events.review_events)
end end
def staging def staging
render_events(events.staging_events) render_events(builds: events.staging_events)
end end
def production def production
render_events(events.production_events) render_events(issues: events.production_events)
end end
private private
def render_events(event_list) def render_events(event_hash)
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: { events: event_list } } format.json { render json: event_hash }
end end
end end
......
...@@ -16,8 +16,13 @@ module Gitlab ...@@ -16,8 +16,13 @@ module Gitlab
def plan_events def plan_events
@fetcher.fetch(stage: :plan).each do |event| @fetcher.fetch(stage: :plan).each do |event|
event['total_time'] = distance_of_time_in_words(event['total_time'].to_f) event['total_time'] = distance_of_time_in_words(event['total_time'].to_f)
commits = event.delete('commits') commit = first_time_reference_commit(event.delete('commits'), event)
event['commit'] = first_time_reference_commit(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
end end
...@@ -56,7 +61,7 @@ module Gitlab ...@@ -56,7 +61,7 @@ module Gitlab
event['author_profile_url'] = Gitlab::LightUrlBuilder.build(entity: :user, id: event['author_username']) 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['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 end
def first_time_reference_commit(commits, event) def first_time_reference_commit(commits, event)
......
...@@ -34,8 +34,7 @@ module Gitlab ...@@ -34,8 +34,7 @@ module Gitlab
{ start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at], { start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at],
end_time_attrs: [issue_metrics_table[:first_added_to_board_at], end_time_attrs: [issue_metrics_table[:first_added_to_board_at],
issue_metrics_table[:first_mentioned_in_commit_at]], issue_metrics_table[:first_mentioned_in_commit_at]],
projections: [mr_diff_table[:st_commits].as('commits'), projections: [mr_diff_table[:st_commits].as('commits')]
issue_metrics_table[:first_mentioned_in_commit_at]]
} }
end end
......
...@@ -23,8 +23,10 @@ module Gitlab ...@@ -23,8 +23,10 @@ module Gitlab
user_url(@id) user_url(@id)
when :user_avatar_url when :user_avatar_url
user_avatar_url user_avatar_url
when :commit_url
commit_url
else else
raise NotImplementedError.new("No URL builder defined for #{object.class}") raise NotImplementedError.new("No URL builder defined for #{object.class}")
end end
end end
...@@ -32,14 +34,22 @@ module Gitlab ...@@ -32,14 +34,22 @@ module Gitlab
def issue_url def issue_url
namespace_project_issue_url({ namespace_project_issue_url({
namespace_id: @project.namespace, namespace_id: @project.namespace,
project_id: @project, project_id: @project,
id: @id id: @id
}.merge!(@opts)) }.merge!(@opts))
end end
def user_avatar_url def user_avatar_url
User.find(@id).avatar_url User.find(@id).avatar_url
end end
def commit_url
namespace_project_commit_url({
namespace_id: @project.namespace,
project_id: @project,
id: @id
}.merge!(@opts))
end
end end
end end
...@@ -4,6 +4,7 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -4,6 +4,7 @@ describe Gitlab::CycleAnalytics::Events do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:from_date) { 10.days.ago } let(:from_date) { 10.days.ago }
let(:user) { create(:user, :admin) } 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) } subject { described_class.new(project: project, from: from_date) }
...@@ -12,8 +13,6 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -12,8 +13,6 @@ describe Gitlab::CycleAnalytics::Events do
end end
describe '#issue_events' do describe '#issue_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
it 'has the total time' do it 'has the total time' do
expect(subject.issue_events.first['total_time']).to eq('2 days') expect(subject.issue_events.first['total_time']).to eq('2 days')
end end
...@@ -44,20 +43,32 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -44,20 +43,32 @@ describe Gitlab::CycleAnalytics::Events do
end end
describe '#plan_events' do 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 it 'has a sha short ID' do
expect(subject.plan_events.first['commit'].message).to eq('commit message') expect(subject.plan_events.first['sha']).not_to be_nil
end end
it 'has the total time' do it 'has the total time' do
expect(subject.plan_events.first['total_time']).to eq('less than a minute') expect(subject.plan_events.first['total_time']).to eq('less than a minute')
end 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 end
describe '#code_events' do describe '#code_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
before do before do
create_commit_referencing_issue(context) create_commit_referencing_issue(context)
end end
...@@ -88,7 +99,6 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -88,7 +99,6 @@ describe Gitlab::CycleAnalytics::Events do
end end
describe '#test_events' do describe '#test_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
let(:merge_request) { MergeRequest.first } let(:merge_request) { MergeRequest.first }
let!(:pipeline) do let!(:pipeline) do
create(:ci_pipeline, create(:ci_pipeline,
...@@ -140,7 +150,6 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -140,7 +150,6 @@ describe Gitlab::CycleAnalytics::Events do
end end
describe '#staging_events' do describe '#staging_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
let(:merge_request) { MergeRequest.first } let(:merge_request) { MergeRequest.first }
let!(:pipeline) do let!(:pipeline) do
create(:ci_pipeline, create(:ci_pipeline,
...@@ -152,6 +161,7 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -152,6 +161,7 @@ describe Gitlab::CycleAnalytics::Events do
before do before do
pipeline.run! pipeline.run!
pipeline.succeed! pipeline.succeed!
merge_merge_requests_closing_issue(context) merge_merge_requests_closing_issue(context)
deploy_master deploy_master
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