fix issue with commits and also updated routes
This commit is contained in:
parent
633ddc9ed9
commit
cbc9f0cd1a
|
@ -1,4 +1,6 @@
|
||||||
class Projects::CycleAnalytics::EventsController < Projects::ApplicationController
|
module Projects
|
||||||
|
module CycleAnalytics
|
||||||
|
class EventsController < Projects::ApplicationController
|
||||||
include CycleAnalyticsParams
|
include CycleAnalyticsParams
|
||||||
|
|
||||||
before_action :authorize_read_cycle_analytics!
|
before_action :authorize_read_cycle_analytics!
|
||||||
|
@ -60,4 +62,6 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
|
||||||
def authorize_builds!
|
def authorize_builds!
|
||||||
return access_denied! unless current_user.can?(:read_build, project)
|
return access_denied! unless current_user.can?(:read_build, project)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -154,7 +154,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only:
|
||||||
resource :cycle_analytics, only: [:show]
|
resource :cycle_analytics, only: [:show]
|
||||||
|
|
||||||
namespace :cycle_analytics do
|
namespace :cycle_analytics do
|
||||||
scope :events, controller: '/projects/cycle_analytics/events' do
|
scope :events, controller: 'events' do
|
||||||
get :issue
|
get :issue
|
||||||
get :plan
|
get :plan
|
||||||
get :code
|
get :code
|
||||||
|
|
|
@ -12,9 +12,11 @@ module Gitlab
|
||||||
|
|
||||||
def plan_events
|
def plan_events
|
||||||
@fetcher.fetch(stage: :plan).map do |event|
|
@fetcher.fetch(stage: :plan).map do |event|
|
||||||
commit = first_time_reference_commit(event.delete('commits'), event)
|
st_commit = first_time_reference_commit(event.delete('commits'), event)
|
||||||
|
|
||||||
AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit).as_json
|
next unless st_commit
|
||||||
|
|
||||||
|
serialize_commit(event, st_commit)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,11 +55,17 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def first_time_reference_commit(commits, event)
|
def first_time_reference_commit(commits, event)
|
||||||
st_commit = YAML.load(commits).detect do |commit|
|
YAML.load(commits).find do |commit|
|
||||||
commit['created_at'] == event['first_mentioned_in_commit_at']
|
next unless commit[:committed_date] && event['first_mentioned_in_commit_at']
|
||||||
|
|
||||||
|
commit[:committed_date].to_i == DateTime.parse(event['first_mentioned_in_commit_at']).to_i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Commit.new(Gitlab::Git::Commit.new(st_commit), @project)
|
def serialize_commit(event, st_commit)
|
||||||
|
commit = Commit.new(Gitlab::Git::Commit.new(st_commit), @project)
|
||||||
|
|
||||||
|
AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def interval_in_words(diff)
|
def interval_in_words(diff)
|
||||||
|
|
|
@ -33,7 +33,8 @@ 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
|
||||||
|
|
||||||
|
|
|
@ -142,5 +142,7 @@ describe 'cycle analytics events' do
|
||||||
create(:ci_build, pipeline: pipeline, status: :success, author: user)
|
create(:ci_build, pipeline: pipeline, status: :success, author: user)
|
||||||
|
|
||||||
merge_merge_requests_closing_issue(issue)
|
merge_merge_requests_closing_issue(issue)
|
||||||
|
|
||||||
|
Issue::Metrics.update_all(first_mentioned_in_commit_at: mr.commits.last.committed_date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue