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
# 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
......
......@@ -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)
......
......@@ -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
......
......@@ -23,6 +23,8 @@ 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}")
end
......@@ -41,5 +43,13 @@ module Gitlab
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
......@@ -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
describe '#code_events' do
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
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
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
......
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