Commit e2190115 authored by Stan Hu's avatar Stan Hu

Merge branch 'graphs-branch-switching' into 'master'

Add ref switching support for graphs

It is now possible to view contributor and commit statistics for
refs beyond the default branch. While the Git ref already was part of
the path it has not been used before.

Additionally, the code in RefsController#switch has been slighliy
refactored since it would have become confusing with additional if-else
branches added.

See merge request !932
parents 17446ff0 2963e7fd
...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 7.13.0 (unreleased) v 7.13.0 (unreleased)
- Fix redirection to home page URL for unauthorized users (Daniel Gerhardt) - Fix redirection to home page URL for unauthorized users (Daniel Gerhardt)
- Add branch switching support for graphs (Daniel Gerhardt)
- Fix external issue tracker hook/test for HTTPS URLs (Daniel Gerhardt) - Fix external issue tracker hook/test for HTTPS URLs (Daniel Gerhardt)
- Remove link leading to a 404 error in Deploy Keys page (Stan Hu) - Remove link leading to a 404 error in Deploy Keys page (Stan Hu)
- Add support for unlocking users in admin settings (Stan Hu) - Add support for unlocking users in admin settings (Stan Hu)
......
class Projects::GraphsController < Projects::ApplicationController class Projects::GraphsController < Projects::ApplicationController
include ExtractsPath
# Authorize # Authorize
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :assign_ref_vars
before_action :authorize_download_code! before_action :authorize_download_code!
def show def show
...@@ -13,7 +16,7 @@ class Projects::GraphsController < Projects::ApplicationController ...@@ -13,7 +16,7 @@ class Projects::GraphsController < Projects::ApplicationController
end end
def commits def commits
@commits = @project.repository.commits(nil, nil, 2000, 0, true) @commits = @project.repository.commits(@ref, nil, 2000, 0, true)
@commits_graph = Gitlab::Graphs::Commits.new(@commits) @commits_graph = Gitlab::Graphs::Commits.new(@commits)
@commits_per_week_days = @commits_graph.commits_per_week_days @commits_per_week_days = @commits_graph.commits_per_week_days
@commits_per_time = @commits_graph.commits_per_time @commits_per_time = @commits_graph.commits_per_time
...@@ -23,7 +26,7 @@ class Projects::GraphsController < Projects::ApplicationController ...@@ -23,7 +26,7 @@ class Projects::GraphsController < Projects::ApplicationController
private private
def fetch_graph def fetch_graph
@commits = @project.repository.commits(nil, nil, 6000, 0, true) @commits = @project.repository.commits(@ref, nil, 6000, 0, true)
@log = [] @log = []
@commits.each do |commit| @commits.each do |commit|
......
...@@ -8,17 +8,21 @@ class Projects::RefsController < Projects::ApplicationController ...@@ -8,17 +8,21 @@ class Projects::RefsController < Projects::ApplicationController
def switch def switch
respond_to do |format| respond_to do |format|
format.html do format.html do
new_path = if params[:destination] == "tree" new_path =
namespace_project_tree_path(@project.namespace, @project, case params[:destination]
(@id)) when "tree"
elsif params[:destination] == "blob" namespace_project_tree_path(@project.namespace, @project, @id)
namespace_project_blob_path(@project.namespace, @project, when "blob"
(@id)) namespace_project_blob_path(@project.namespace, @project, @id)
elsif params[:destination] == "graph" when "graph"
namespace_project_network_path(@project.namespace, @project, @id, @options) namespace_project_network_path(@project.namespace, @project, @id, @options)
else when "graphs"
namespace_project_commits_path(@project.namespace, @project, @id) namespace_project_graph_path(@project.namespace, @project, @id)
end when "graphs_commits"
commits_namespace_project_graph_path(@project.namespace, @project, @id)
else
namespace_project_commits_path(@project.namespace, @project, @id)
end
redirect_to new_path redirect_to new_path
end end
......
- page_title "Commit statistics" - page_title "Commit statistics"
.tree-ref-holder
= render 'shared/ref_switcher', destination: 'graphs_commits'
= render 'head' = render 'head'
%p.lead %p.lead
Commit statistics for Commit statistics for
%strong #{@repository.root_ref} %strong #{@ref}
#{@commits_graph.start_date.strftime('%b %d')} - #{@commits_graph.end_date.strftime('%b %d')} #{@commits_graph.start_date.strftime('%b %d')} - #{@commits_graph.end_date.strftime('%b %d')}
.row .row
......
- page_title "Contributor statistics" - page_title "Contributor statistics"
.tree-ref-holder
= render 'shared/ref_switcher', destination: 'graphs'
= render 'head' = render 'head'
.loading-graph .loading-graph
.center .center
%h3.page-title %h3.page-title
...@@ -11,7 +14,7 @@ ...@@ -11,7 +14,7 @@
.header.clearfix .header.clearfix
%h3#date_header.page-title %h3#date_header.page-title
%p.light %p.light
Commits to #{@project.default_branch}, excluding merge commits. Limited by 6,000 commits Commits to #{@ref}, excluding merge commits. Limited by 6,000 commits
%input#brush_change{:type => "hidden"} %input#brush_change{:type => "hidden"}
.graphs .graphs
#contributors-master #contributors-master
...@@ -35,4 +38,3 @@ ...@@ -35,4 +38,3 @@
$(".stat-graph").fadeIn(); $(".stat-graph").fadeIn();
$(".loading-graph").hide(); $(".loading-graph").hide();
dataType: "json" dataType: "json"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment