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