Commit f4cb04da authored by Douwe Maan's avatar Douwe Maan

Merge branch 'branches-ending-with-json' into 'master'

Allow branch names ending with .json for graph and network page

## What does this MR do?

Allow branch names to end with `.json` for graph and network page.

## Why was this MR needed?

Displaying branches ending on `.json` in repository view crashes because links to graph and network page can not be determined.

## What are the relevant issue numbers?

fixes #20462, #19585

See merge request !5579
parents 90c277aa e1832914
...@@ -37,6 +37,7 @@ v 8.11.0 (unreleased) ...@@ -37,6 +37,7 @@ v 8.11.0 (unreleased)
- Gitlab::Metrics.current_transaction needs to be public for RailsQueueDuration - Gitlab::Metrics.current_transaction needs to be public for RailsQueueDuration
- Fix search for notes which belongs to deleted objects - Fix search for notes which belongs to deleted objects
- Add GitLab Workhorse version to admin dashboard (Katarzyna Kobierska Ula Budziszewska) - Add GitLab Workhorse version to admin dashboard (Katarzyna Kobierska Ula Budziszewska)
- Allow branch names ending with .json for graph and network page !5579 (winniehell)
- Add the `sprockets-es6` gem - Add the `sprockets-es6` gem
- Multiple trigger variables show in separate lines (Katarzyna Kobierska Ula Budziszewska) - Multiple trigger variables show in separate lines (Katarzyna Kobierska Ula Budziszewska)
- Profile requests when a header is passed - Profile requests when a header is passed
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
:javascript :javascript
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: location.href, url: "#{namespace_project_graph_path(@project.namespace, @project, current_ref, format: :json)}",
dataType: "json", dataType: "json",
success: function (data) { success: function (data) {
var graph = new ContributorsStatGraph(); var graph = new ContributorsStatGraph();
......
...@@ -626,13 +626,17 @@ Rails.application.routes.draw do ...@@ -626,13 +626,17 @@ Rails.application.routes.draw do
get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ } get '/compare/:from...:to', to: 'compare#show', as: 'compare', constraints: { from: /.+/, to: /.+/ }
resources :network, only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ } # Don't use format parameter as file extension (old 3.0.x behavior)
# See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments
resources :graphs, only: [:show], constraints: { id: /(?:[^.]|\.(?!json$))+/, format: /json/ } do scope format: false do
member do resources :network, only: [:show], constraints: { id: Gitlab::Regex.git_reference_regex }
get :commits
get :ci resources :graphs, only: [:show], constraints: { id: Gitlab::Regex.git_reference_regex } do
get :languages member do
get :commits
get :ci
get :languages
end
end end
end end
......
...@@ -20,7 +20,11 @@ describe BranchesFinder do ...@@ -20,7 +20,11 @@ describe BranchesFinder do
result = branches_finder.execute result = branches_finder.execute
expect(result.first.name).to eq('crlf-diff') recently_updated_branch = repository.branches.max do |a, b|
repository.commit(a.target).committed_date <=> repository.commit(b.target).committed_date
end
expect(result.first.name).to eq(recently_updated_branch.name)
end end
it 'sorts by last_updated' do it 'sorts by last_updated' do
......
...@@ -479,13 +479,16 @@ end ...@@ -479,13 +479,16 @@ end
describe Projects::NetworkController, 'routing' do describe Projects::NetworkController, 'routing' do
it 'to #show' do it 'to #show' do
expect(get('/gitlab/gitlabhq/network/master')).to route_to('projects/network#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master') expect(get('/gitlab/gitlabhq/network/master')).to route_to('projects/network#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master')
expect(get('/gitlab/gitlabhq/network/master.json')).to route_to('projects/network#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master', format: 'json') expect(get('/gitlab/gitlabhq/network/ends-with.json')).to route_to('projects/network#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'ends-with.json')
expect(get('/gitlab/gitlabhq/network/master?format=json')).to route_to('projects/network#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master', format: 'json')
end end
end end
describe Projects::GraphsController, 'routing' do describe Projects::GraphsController, 'routing' do
it 'to #show' do it 'to #show' do
expect(get('/gitlab/gitlabhq/graphs/master')).to route_to('projects/graphs#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master') expect(get('/gitlab/gitlabhq/graphs/master')).to route_to('projects/graphs#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master')
expect(get('/gitlab/gitlabhq/graphs/ends-with.json')).to route_to('projects/graphs#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'ends-with.json')
expect(get('/gitlab/gitlabhq/graphs/master?format=json')).to route_to('projects/graphs#show', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master', format: 'json')
end end
end end
......
...@@ -6,6 +6,7 @@ module TestEnv ...@@ -6,6 +6,7 @@ module TestEnv
# When developing the seed repository, comment out the branch you will modify. # When developing the seed repository, comment out the branch you will modify.
BRANCH_SHA = { BRANCH_SHA = {
'empty-branch' => '7efb185', 'empty-branch' => '7efb185',
'ends-with.json' => '98b0d8b3',
'flatten-dir' => 'e56497b', 'flatten-dir' => 'e56497b',
'feature' => '0b4bc9a', 'feature' => '0b4bc9a',
'feature_conflict' => 'bb5206f', 'feature_conflict' => 'bb5206f',
......
require 'spec_helper'
describe 'projects/tree/show' do
include Devise::TestHelpers
let(:project) { create(:project) }
let(:repository) { project.repository }
before do
assign(:project, project)
assign(:repository, repository)
allow(view).to receive(:can?).and_return(true)
allow(view).to receive(:can_collaborate_with_project?).and_return(true)
end
context 'for branch names ending on .json' do
let(:ref) { 'ends-with.json' }
let(:commit) { repository.commit(ref) }
let(:path) { '' }
let(:tree) { repository.tree(commit.id, path) }
before do
assign(:ref, ref)
assign(:commit, commit)
assign(:id, commit.id)
assign(:tree, tree)
assign(:path, path)
end
it 'displays correctly' do
render
expect(rendered).to have_css('.js-project-refs-dropdown .dropdown-toggle-text', text: ref)
expect(rendered).to have_css('.readme-holder .file-content', text: ref)
end
end
end
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