Add a JSON version of the `CycleAnalytics` page.

This commit is contained in:
Timothy Andrew 2016-09-08 15:03:38 +05:30
parent f5b9837c19
commit 9901c3df41
3 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,11 @@ class Projects::CycleAnalyticsController < Projects::ApplicationController
def show
@cycle_analytics = CycleAnalytics.new(@project, from: parse_start_date)
respond_to do |format|
format.html
format.json { render json: @cycle_analytics }
end
end
private

View File

@ -6,6 +6,13 @@ class CycleAnalytics
@from = from
end
def as_json(options = {})
{
issue: issue, plan: plan, code: code, test: test,
review: review, staging: staging, production: production
}
end
def issue
calculate_metric(Queries::issues(@project, created_after: @from),
-> (data_point) { data_point[:issue].created_at },

View File

@ -101,6 +101,7 @@ class ProjectPolicy < BasePolicy
can! :admin_pipeline
can! :admin_environment
can! :admin_deployment
can! :read_cycle_analytics
end
def public_access!