graphs_controller.rb 1021 字节
Newer Older
1
class Projects::GraphsController < Projects::ApplicationController
2 3
  # Authorize
  before_filter :require_non_empty_project
4
  before_filter :authorize_download_code!
5

6
  def show
7 8
    respond_to do |format|
      format.html
D
Dmitriy Zaporozhets 已提交
9
      format.json do
D
Dmitriy Zaporozhets 已提交
10
        fetch_graph
11 12
      end
    end
13
  end
D
Dmitriy Zaporozhets 已提交
14

15 16
  def commits
    @commits = @project.repository.commits(nil, nil, 2000, 0, true)
D
Dmitriy Zaporozhets 已提交
17 18 19 20
    @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
21 22
  end

D
Dmitriy Zaporozhets 已提交
23 24 25
  private

  def fetch_graph
D
Dmitriy Zaporozhets 已提交
26
    @commits = @project.repository.commits(nil, nil, 6000, 0, true)
D
Dmitriy Zaporozhets 已提交
27
    @log = []
D
Dmitriy Zaporozhets 已提交
28 29 30 31 32 33 34 35 36 37

    @commits.each do |commit|
      @log << {
        author_name: commit.author_name.force_encoding('UTF-8'),
        author_email: commit.author_email.force_encoding('UTF-8'),
        date: commit.committed_date.strftime("%Y-%m-%d")
      }
    end

    render json: @log.to_json
D
Dmitriy Zaporozhets 已提交
38
  end
39
end