Commit f1e0d37b15914ce7f17a612c8afb4452a501ecd7
1 parent
64457799
Exists in
master
and in
4 other branches
Its better to load graph with ajax since it requires ~10 seconds for bigger projects to finish up
Showing
11 changed files
with
79 additions
and
161 deletions
Show diff stats
Gemfile
| ... | ... | @@ -23,7 +23,7 @@ gem 'omniauth-github' |
| 23 | 23 | |
| 24 | 24 | # Extracting information from a git repository |
| 25 | 25 | # Provide access to Gitlab::Git library |
| 26 | -gem 'gitlab_git', '~> 1.2.1' | |
| 26 | +gem 'gitlab_git', '~> 1.3.0' | |
| 27 | 27 | |
| 28 | 28 | # Ruby/Rack Git Smart-HTTP Server Handler |
| 29 | 29 | gem 'gitlab-grack', '~> 1.0.0', require: 'grack' |
| ... | ... | @@ -183,7 +183,7 @@ group :development, :test do |
| 183 | 183 | gem 'poltergeist', '~> 1.3.0' |
| 184 | 184 | |
| 185 | 185 | gem 'spork', '~> 1.0rc' |
| 186 | - gem 'jasmine' | |
| 186 | + gem 'jasmine' | |
| 187 | 187 | end |
| 188 | 188 | |
| 189 | 189 | group :test do | ... | ... |
Gemfile.lock
| ... | ... | @@ -164,7 +164,7 @@ GEM |
| 164 | 164 | gitlab-pygments.rb (0.3.2) |
| 165 | 165 | posix-spawn (~> 0.3.6) |
| 166 | 166 | yajl-ruby (~> 1.1.0) |
| 167 | - gitlab_git (1.2.1) | |
| 167 | + gitlab_git (1.3.0) | |
| 168 | 168 | activesupport (~> 3.2.13) |
| 169 | 169 | github-linguist (~> 2.3.4) |
| 170 | 170 | gitlab-grit (~> 2.5.1) |
| ... | ... | @@ -543,7 +543,7 @@ DEPENDENCIES |
| 543 | 543 | gitlab-gollum-lib (~> 1.0.0) |
| 544 | 544 | gitlab-grack (~> 1.0.0) |
| 545 | 545 | gitlab-pygments.rb (~> 0.3.2) |
| 546 | - gitlab_git (~> 1.2.1) | |
| 546 | + gitlab_git (~> 1.3.0) | |
| 547 | 547 | gitlab_meta (= 5.0) |
| 548 | 548 | gitlab_omniauth-ldap (= 1.0.2) |
| 549 | 549 | gon | ... | ... |
app/controllers/stat_graph_controller.rb
| 1 | 1 | class StatGraphController < ProjectResourceController |
| 2 | - | |
| 3 | 2 | # Authorize |
| 4 | 3 | before_filter :authorize_read_project! |
| 5 | 4 | before_filter :authorize_code_access! |
| 6 | 5 | before_filter :require_non_empty_project |
| 7 | - | |
| 6 | + | |
| 8 | 7 | def show |
| 9 | - @repo = @project.repository | |
| 10 | - @stats = Gitlab::GitStats.new(@repo.raw, @repo.root_ref) | |
| 11 | - @log = @stats.parsed_log.to_json | |
| 8 | + respond_to do |format| | |
| 9 | + format.html | |
| 10 | + format.js do | |
| 11 | + @repo = @project.repository | |
| 12 | + @stats = Gitlab::Git::GitStats.new(@repo.raw, @repo.root_ref) | |
| 13 | + @log = @stats.parsed_log.to_json | |
| 14 | + end | |
| 15 | + end | |
| 12 | 16 | end |
| 13 | - | |
| 14 | -end | |
| 15 | 17 | \ No newline at end of file |
| 18 | +end | ... | ... |
app/views/stat_graph/show.html.haml
| 1 | -.header.clearfix | |
| 2 | - .right | |
| 3 | - %select | |
| 4 | - %option{:value => "commits"} Commits | |
| 5 | - %option{:value => "additions"} Additions | |
| 6 | - %option{:value => "deletions"} Deletions | |
| 7 | - %h3#date_header | |
| 8 | - %input#brush_change{:type => "hidden"} | |
| 1 | +.loading-graph | |
| 2 | + %center | |
| 3 | + .loading | |
| 4 | + %h3.page_title Building repository graph. Please wait a moment. | |
| 9 | 5 | |
| 10 | -.graphs | |
| 11 | - #contributors-master | |
| 12 | - #contributors.clearfix | |
| 13 | - %ol.contributors-list.clearfix | |
| 6 | +.stat-graph | |
| 7 | + .header.clearfix | |
| 8 | + .right | |
| 9 | + %select | |
| 10 | + %option{:value => "commits"} Commits | |
| 11 | + %option{:value => "additions"} Additions | |
| 12 | + %option{:value => "deletions"} Deletions | |
| 13 | + %h3#date_header | |
| 14 | + %input#brush_change{:type => "hidden"} | |
| 15 | + .graphs | |
| 16 | + #contributors-master | |
| 17 | + #contributors.clearfix | |
| 18 | + %ol.contributors-list.clearfix | |
| 14 | 19 | |
| 15 | 20 | :javascript |
| 16 | - controller = new ContributorsStatGraph | |
| 17 | - controller.init(#{@log}) | |
| 21 | + $(".stat-graph").hide(); | |
| 18 | 22 | |
| 19 | - $("select").change( function () { | |
| 20 | - var field = $(this).val() | |
| 21 | - controller.set_current_field(field) | |
| 22 | - controller.redraw_master() | |
| 23 | - controller.redraw_authors() | |
| 24 | - }) | |
| 25 | - | |
| 26 | - $("#brush_change").change( function () { | |
| 27 | - controller.change_date_header() | |
| 28 | - controller.redraw_authors() | |
| 29 | - }) | |
| 30 | 23 | \ No newline at end of file |
| 24 | + $.ajax({ | |
| 25 | + type: "GET", | |
| 26 | + url: location.href, | |
| 27 | + complete: function() { | |
| 28 | + $(".loading-graph").hide(); | |
| 29 | + $(".stat-graph").show(); | |
| 30 | + }, | |
| 31 | + dataType: "script" | |
| 32 | + }); | ... | ... |
| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | +:plain | |
| 2 | + controller = new ContributorsStatGraph | |
| 3 | + controller.init(#{@log}) | |
| 4 | + | |
| 5 | + $("select").change( function () { | |
| 6 | + var field = $(this).val() | |
| 7 | + controller.set_current_field(field) | |
| 8 | + controller.redraw_master() | |
| 9 | + controller.redraw_authors() | |
| 10 | + }) | |
| 11 | + | |
| 12 | + $("#brush_change").change( function () { | |
| 13 | + controller.change_date_header() | |
| 14 | + controller.redraw_authors() | |
| 15 | + }) | |
| 16 | + | ... | ... |
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +class ProjectGraph < Spinach::FeatureSteps | |
| 2 | + include SharedAuthentication | |
| 3 | + include SharedProject | |
| 4 | + | |
| 5 | + Then 'page should have graphs' do | |
| 6 | + page.should have_selector ".stat-graph" | |
| 7 | + end | |
| 8 | + | |
| 9 | + When 'I visit project "Shop" graph page' do | |
| 10 | + project = Project.find_by_name("Shop") | |
| 11 | + visit project_stat_graph_path(project, "master") | |
| 12 | + end | |
| 13 | +end | ... | ... |
lib/gitlab/git_stats.rb
| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | -require 'gitlab/git_stats_log_parser' | |
| 2 | - | |
| 3 | -module Gitlab | |
| 4 | - class GitStats | |
| 5 | - attr_accessor :repo, :ref | |
| 6 | - | |
| 7 | - def initialize repo, ref | |
| 8 | - @repo, @ref = repo, ref | |
| 9 | - end | |
| 10 | - | |
| 11 | - def log | |
| 12 | - args = ['--format=%aN%x0a%ad', '--date=short', '--shortstat', '--no-merges'] | |
| 13 | - repo.git.run(nil, 'log', nil, {}, args) | |
| 14 | - end | |
| 15 | - | |
| 16 | - def parsed_log | |
| 17 | - LogParser.parse_log(log) | |
| 18 | - end | |
| 19 | - end | |
| 20 | -end |
lib/gitlab/git_stats_log_parser.rb
| ... | ... | @@ -1,32 +0,0 @@ |
| 1 | -class LogParser | |
| 2 | - #Parses the log file into a collection of commits | |
| 3 | - #Data model: {author, date, additions, deletions} | |
| 4 | - def self.parse_log log_from_git | |
| 5 | - log = log_from_git.split("\n") | |
| 6 | - | |
| 7 | - i = 0 | |
| 8 | - collection = [] | |
| 9 | - entry = {} | |
| 10 | - | |
| 11 | - while i <= log.size do | |
| 12 | - pos = i % 4 | |
| 13 | - case pos | |
| 14 | - when 0 | |
| 15 | - unless i == 0 | |
| 16 | - collection.push(entry) | |
| 17 | - entry = {} | |
| 18 | - end | |
| 19 | - entry[:author] = log[i].to_s | |
| 20 | - when 1 | |
| 21 | - entry[:date] = log[i].to_s | |
| 22 | - when 3 | |
| 23 | - changes = log[i].split(",") | |
| 24 | - entry[:additions] = changes[1].to_i unless changes[1].nil? | |
| 25 | - entry[:deletions] = changes[2].to_i unless changes[2].nil? | |
| 26 | - end | |
| 27 | - i += 1 | |
| 28 | - end | |
| 29 | - | |
| 30 | - collection | |
| 31 | - end | |
| 32 | -end | |
| 33 | 0 | \ No newline at end of file |
spec/lib/gitlab/git_stats_log_parser_spec.rb
| ... | ... | @@ -1,37 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | -require 'gitlab/git_stats_log_parser' | |
| 3 | - | |
| 4 | - | |
| 5 | -describe LogParser do | |
| 6 | - | |
| 7 | - describe "#self.parse_log" do | |
| 8 | - context "log_from_git is a valid log" do | |
| 9 | - it "returns the correct log" do | |
| 10 | - fake_log = "Karlo Soriano | |
| 11 | -2013-05-09 | |
| 12 | - | |
| 13 | - 14 files changed, 471 insertions(+) | |
| 14 | -Dmitriy Zaporozhets | |
| 15 | -2013-05-08 | |
| 16 | - | |
| 17 | - 1 file changed, 6 insertions(+), 1 deletion(-) | |
| 18 | -Dmitriy Zaporozhets | |
| 19 | -2013-05-08 | |
| 20 | - | |
| 21 | - 6 files changed, 19 insertions(+), 3 deletions(-) | |
| 22 | -Dmitriy Zaporozhets | |
| 23 | -2013-05-08 | |
| 24 | - | |
| 25 | - 3 files changed, 29 insertions(+), 3 deletions(-)"; | |
| 26 | - | |
| 27 | - lp = LogParser.parse_log(fake_log) | |
| 28 | - lp.should eq([ | |
| 29 | - {author: "Karlo Soriano", date: "2013-05-09", additions: 471}, | |
| 30 | - {author: "Dmitriy Zaporozhets", date: "2013-05-08", additions: 6, deletions: 1}, | |
| 31 | - {author: "Dmitriy Zaporozhets", date: "2013-05-08", additions: 19, deletions: 3}, | |
| 32 | - {author: "Dmitriy Zaporozhets", date: "2013-05-08", additions: 29, deletions: 3}]) | |
| 33 | - end | |
| 34 | - end | |
| 35 | - end | |
| 36 | - | |
| 37 | -end | |
| 38 | 0 | \ No newline at end of file |
spec/lib/gitlab/git_stats_spec.rb
| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | -require 'spec_helper' | |
| 2 | - | |
| 3 | -describe Gitlab::GitStats do | |
| 4 | - | |
| 5 | - describe "#parsed_log" do | |
| 6 | - let(:stats) { Gitlab::GitStats.new(nil, nil) } | |
| 7 | - before(:each) do | |
| 8 | - stats.stub(:log).and_return("anything") | |
| 9 | - end | |
| 10 | - | |
| 11 | - context "LogParser#parse_log returns 'test'" do | |
| 12 | - it "returns 'test'" do | |
| 13 | - LogParser.stub(:parse_log).and_return("test") | |
| 14 | - stats.parsed_log.should eq("test") | |
| 15 | - end | |
| 16 | - end | |
| 17 | - end | |
| 18 | - | |
| 19 | - describe "#log" do | |
| 20 | - let(:repo) { Repository.new(nil, nil) } | |
| 21 | - let(:gs) { Gitlab::GitStats.new(repo.raw, repo.root_ref) } | |
| 22 | - | |
| 23 | - before(:each) do | |
| 24 | - repo.stub(:raw).and_return(nil) | |
| 25 | - repo.stub(:root_ref).and_return(nil) | |
| 26 | - repo.raw.stub(:git) | |
| 27 | - end | |
| 28 | - | |
| 29 | - context "repo.git.run returns 'test'" do | |
| 30 | - it "returns 'test'" do | |
| 31 | - repo.raw.git.stub(:run).and_return("test") | |
| 32 | - gs.log.should eq("test") | |
| 33 | - end | |
| 34 | - end | |
| 35 | - end | |
| 36 | -end | |
| 37 | 0 | \ No newline at end of file |