Commit 55e0065b authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-404-on-network-when-entering-a-nonexistent-git-revision' into 'master'

Network page appear with an error message when entering nonexistent git revision

Closes #2362

See merge request !7172
parents a6b49757 5569573a
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
(function() { (function() {
$(function() { $(function() {
if (!$(".network-graph").length) return;
var network_graph; var network_graph;
network_graph = new Network({ network_graph = new Network({
url: $(".network-graph").attr('data-url'), url: $(".network-graph").attr('data-url'),
......
...@@ -5,17 +5,29 @@ class Projects::NetworkController < Projects::ApplicationController ...@@ -5,17 +5,29 @@ class Projects::NetworkController < Projects::ApplicationController
before_action :require_non_empty_project before_action :require_non_empty_project
before_action :assign_ref_vars before_action :assign_ref_vars
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :assign_commit
def show def show
@url = namespace_project_network_path(@project.namespace, @project, @ref, @options.merge(format: :json)) @url = namespace_project_network_path(@project.namespace, @project, @ref, @options.merge(format: :json))
@commit_url = namespace_project_commit_path(@project.namespace, @project, 'ae45ca32').gsub("ae45ca32", "%s") @commit_url = namespace_project_commit_path(@project.namespace, @project, 'ae45ca32').gsub("ae45ca32", "%s")
respond_to do |format| respond_to do |format|
format.html format.html do
if @options[:extended_sha1] && !@commit
flash.now[:alert] = "Git revision '#{@options[:extended_sha1]}' does not exist."
end
end
format.json do format.json do
@graph = Network::Graph.new(project, @ref, @commit, @options[:filter_ref]) @graph = Network::Graph.new(project, @ref, @commit, @options[:filter_ref])
end end
end end
end end
def assign_commit
return if params[:extended_sha1].blank?
@options[:extended_sha1] = params[:extended_sha1]
@commit = @repo.commit(@options[:extended_sha1])
end
end end
...@@ -17,5 +17,6 @@ ...@@ -17,5 +17,6 @@
= check_box_tag :filter_ref, 1, @options[:filter_ref] = check_box_tag :filter_ref, 1, @options[:filter_ref]
%span Begin with the selected commit %span Begin with the selected commit
- if @commit
.network-graph{ data: { url: @url, commit_url: @commit_url, ref: @ref, commit_id: @commit.id } } .network-graph{ data: { url: @url, commit_url: @commit_url, ref: @ref, commit_id: @commit.id } }
= spinner nil, true = spinner nil, true
---
title: Fix 404 on network page when entering non-existent git revision
merge_request: 7172
author: Hiroyuki Sato
...@@ -43,4 +43,4 @@ Feature: Project Network Graph ...@@ -43,4 +43,4 @@ Feature: Project Network Graph
Scenario: I should fail to look for a commit Scenario: I should fail to look for a commit
When I look for a commit by ";" When I look for a commit by ";"
Then page status code should be 404 Then I should see non-existent git revision error message
...@@ -109,4 +109,8 @@ class Spinach::Features::ProjectNetworkGraph < Spinach::FeatureSteps ...@@ -109,4 +109,8 @@ class Spinach::Features::ProjectNetworkGraph < Spinach::FeatureSteps
find('button').click find('button').click
end end
end end
step 'I should see non-existent git revision error message' do
expect(page).to have_selector '.flash-alert', text: "Git revision ';' does not exist."
end
end end
...@@ -106,7 +106,7 @@ module ExtractsPath ...@@ -106,7 +106,7 @@ module ExtractsPath
# resolved (e.g., when a user inserts an invalid path or ref). # resolved (e.g., when a user inserts an invalid path or ref).
def assign_ref_vars def assign_ref_vars
# assign allowed options # assign allowed options
allowed_options = ["filter_ref", "extended_sha1"] allowed_options = ["filter_ref"]
@options = params.select {|key, value| allowed_options.include?(key) && !value.blank? } @options = params.select {|key, value| allowed_options.include?(key) && !value.blank? }
@options = HashWithIndifferentAccess.new(@options) @options = HashWithIndifferentAccess.new(@options)
...@@ -114,9 +114,6 @@ module ExtractsPath ...@@ -114,9 +114,6 @@ module ExtractsPath
@ref, @path = extract_ref(@id) @ref, @path = extract_ref(@id)
@repo = @project.repository @repo = @project.repository
if @options[:extended_sha1].present?
@commit = @repo.commit(@options[:extended_sha1])
else
@commit = @repo.commit(@ref) @commit = @repo.commit(@ref)
if @path.empty? && !@commit && @id.ends_with?('.atom') if @path.empty? && !@commit && @id.ends_with?('.atom')
...@@ -125,7 +122,6 @@ module ExtractsPath ...@@ -125,7 +122,6 @@ module ExtractsPath
request.format = :atom if @commit request.format = :atom if @commit
end end
end
raise InvalidPathError unless @commit raise InvalidPathError unless @commit
......
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