graphs_controller.rb 1.3 KB
Newer Older
1
class Projects::GraphsController < Projects::ApplicationController
2 3
  include ExtractsPath

4
  # Authorize
5
  before_action :require_non_empty_project
6
  before_action :assign_ref_vars
7
  before_action :authorize_download_code!
8

9
  def show
10 11
    respond_to do |format|
      format.html
D
Dmitriy Zaporozhets 已提交
12
      format.json do
D
Dmitriy Zaporozhets 已提交
13
        fetch_graph
14 15
      end
    end
16
  end
D
Dmitriy Zaporozhets 已提交
17

18
  def commits
19
    @commits = @project.repository.commits(@ref, nil, 2000, 0, true)
D
Dmitriy Zaporozhets 已提交
20 21 22 23
    @commits_graph = Gitlab::Graphs::Commits.new(@commits)
    @commits_per_week_days = @commits_graph.commits_per_week_days
    @commits_per_time = @commits_graph.commits_per_time
    @commits_per_month = @commits_graph.commits_per_month
24 25
  end

26 27 28 29 30 31 32 33 34 35
  def ci
    ci_project = @project.gitlab_ci_project

    @charts = {}
    @charts[:week] = Ci::Charts::WeekChart.new(ci_project)
    @charts[:month] = Ci::Charts::MonthChart.new(ci_project)
    @charts[:year] = Ci::Charts::YearChart.new(ci_project)
    @charts[:build_times] = Ci::Charts::BuildTime.new(ci_project)
  end

D
Dmitriy Zaporozhets 已提交
36 37 38
  private

  def fetch_graph
39
    @commits = @project.repository.commits(@ref, nil, 6000, 0, true)
D
Dmitriy Zaporozhets 已提交
40
    @log = []
D
Dmitriy Zaporozhets 已提交
41 42 43

    @commits.each do |commit|
      @log << {
44 45
        author_name: commit.author_name,
        author_email: commit.author_email,
D
Dmitriy Zaporozhets 已提交
46 47 48 49 50
        date: commit.committed_date.strftime("%Y-%m-%d")
      }
    end

    render json: @log.to_json
D
Dmitriy Zaporozhets 已提交
51
  end
52
end