From 16ba8fa077145f99dff98501770ed80d0a58fd58 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 22 Jan 2014 15:07:29 +0100 Subject: Display correct paths in markdown for reference style links. --- app/helpers/gitlab_markdown_helper.rb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 8894a01eaea..60f9d4e764a 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -69,10 +69,17 @@ module GitlabMarkdownHelper project_path_with_namespace = project.path_with_namespace paths = extract_paths(text) paths.each do |file_path| - new_path = rebuild_path(project_path_with_namespace, file_path, requested_path, ref) - # Replacing old string with a new one with brackets ]() to prevent replacing occurence of a word - # e.g. If we have a markdown like [test](test) this will replace ](test) and not the word test - text.gsub!("](#{file_path})", "](/#{new_path})") + original_file_path = extract(file_path) + new_path = rebuild_path(project_path_with_namespace, original_file_path, requested_path, ref) + if reference_path?(file_path) + # Replacing old string with a new one that contains updated path + # eg. [some document]: document.md will be replaced with [some document] /namespace/project/master/blob/document.md + text.gsub!(file_path, file_path.gsub(original_file_path, "/#{new_path}")) + else + # Replacing old string with a new one with brackets ]() to prevent replacing occurence of a word + # e.g. If we have a markdown like [test](test) this will replace ](test) and not the word test + text.gsub!("](#{file_path})", "](/#{new_path})") + end end text end @@ -83,9 +90,11 @@ module GitlabMarkdownHelper select_relative(paths) end - # Split the markdown text to each line and find all paths, this will match anything with - ]("some_text") + # Split the markdown text to each line and find all paths, this will match anything with - ]("some_text") and [some text]: file.md def pick_out_paths(markdown_text) - markdown_text.split("\n").map { |text| text.scan(/\]\(([^(]+)\)/) } + inline_paths = markdown_text.split("\n").map { |text| text.scan(/\]\(([^(]+)\)/) } + reference_paths = markdown_text.split("\n").map { |text| text.scan(/\[.*\]:.*/) } + inline_paths + reference_paths end # Removes any empty result produced by not matching the regexp @@ -93,12 +102,22 @@ module GitlabMarkdownHelper paths.reject{|l| l.empty? }.flatten end + # If a path is a reference style link we need to omit ]: + def extract(path) + path.split("]: ").last + end + # Reject any path that contains ignored protocol # eg. reject "https://gitlab.org} but accept "doc/api/README.md" def select_relative(paths) paths.reject{|path| ignored_protocols.map{|protocol| path.include?(protocol)}.any?} end + # Check whether a path is a reference-style link + def reference_path?(path) + path.include?("]: ") + end + def ignored_protocols ["http://","https://", "ftp://", "mailto:"] end -- cgit v1.2.1 From 462161a3b07369d0df68b0298929b3f89cf46c03 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 23 Jan 2014 10:43:04 +0100 Subject: Markdown helper spec for reference style relative links. --- spec/helpers/gitlab_markdown_helper_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 33e69d4326c..a3efdffeebc 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -431,6 +431,24 @@ describe GitlabMarkdownHelper do expected = "

Link

\n" markdown(actual).should match(expected) end + + it "should handle relative urls in reference links for a file in master" do + actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n" + expected = "

GitLab API doc

\n" + markdown(actual).should match(expected) + end + + it "should handle relative urls in reference links for a directory in master" do + actual = "[GitLab API doc directory][GitLab readmes]\n [GitLab readmes]: doc/api/\n" + expected = "

GitLab API doc directory

\n" + markdown(actual).should match(expected) + end + + it "should not handle malformed relative urls in reference links for a file in master" do + actual = "[GitLab readme]: doc/api/README.md\n" + expected = "" + markdown(actual).should match(expected) + end end describe "#render_wiki_content" do -- cgit v1.2.1 From c6b9767e74421bae7f0532ce7fab8753863e94f0 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 23 Jan 2014 11:08:57 +0100 Subject: Test if the views behave correctly with reference style relative links. --- features/project/source/markdown_render.feature | 12 ++++++++++++ features/steps/project/project_markdown_render.rb | 22 ++++++++++++++++++++++ spec/seed_project.tar.gz | Bin 9795570 -> 9795746 bytes 3 files changed, 34 insertions(+) diff --git a/features/project/source/markdown_render.feature b/features/project/source/markdown_render.feature index 8b4b89e85af..04467b66648 100644 --- a/features/project/source/markdown_render.feature +++ b/features/project/source/markdown_render.feature @@ -16,6 +16,18 @@ Feature: Project markdown render And I click on Rake tasks in README Then I should see correct directory rendered + Scenario: I view README in master branch to see reference links to directory + Then I should see files from repository in master + And I should see rendered README which contains correct links + And I click on GitLab API doc directory in README + Then I should see correct doc/api directory rendered + + Scenario: I view README in master branch to see reference links to file + Then I should see files from repository in master + And I should see rendered README which contains correct links + And I click on Maintenance in README + Then I should see correct maintenance file rendered + Scenario: I navigate to doc directory to view documentation in master And I navigate to the doc/api/README And I see correct file rendered diff --git a/features/steps/project/project_markdown_render.rb b/features/steps/project/project_markdown_render.rb index da044e46ebd..a74a8909140 100644 --- a/features/steps/project/project_markdown_render.rb +++ b/features/steps/project/project_markdown_render.rb @@ -21,6 +21,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps page.should have_link "GitLab API website" page.should have_link "Rake tasks" page.should have_link "backup and restore procedure" + page.should have_link "GitLab API doc directory" + page.should have_link "Maintenance" end And 'I click on Gitlab API in README' do @@ -42,6 +44,26 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps page.should have_content "maintenance.md" end + + And 'I click on GitLab API doc directory in README' do + click_link "GitLab API doc directory" + end + + Then 'I should see correct doc/api directory rendered' do + current_path.should == project_tree_path(@project, "master/doc/api") + page.should have_content "README.md" + page.should have_content "users.md" + end + + And 'I click on Maintenance in README' do + click_link "Maintenance" + end + + Then 'I should see correct maintenance file rendered' do + current_path.should == project_blob_path(@project, "doc/raketasks/maintenance.md") + page.should have_content "bundle exec rake gitlab:env:info RAILS_ENV=production" + end + And 'I navigate to the doc/api/README' do click_link "doc" click_link "api" diff --git a/spec/seed_project.tar.gz b/spec/seed_project.tar.gz index 7abb51ebdfd..b098a2c3b64 100644 Binary files a/spec/seed_project.tar.gz and b/spec/seed_project.tar.gz differ -- cgit v1.2.1 From 3bcfdf07cd81408105cb912ceb64532688e1e9cd Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 23 Jan 2014 13:06:44 +0100 Subject: Update last sha of the commit in the test seed repository. --- spec/models/project_spec.rb | 8 ++++---- spec/seed_project.tar.gz | Bin 9795746 -> 9825908 bytes 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 373accfe412..4aef70e90fe 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -137,17 +137,17 @@ describe Project do it "should close merge request if last commit from source branch was pushed to target branch" do @merge_request.reloaded_commits - @merge_request.last_commit.id.should == "b1e6a9dbf1c85e6616497a5e7bad9143a4bd0828" - project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "b1e6a9dbf1c85e6616497a5e7bad9143a4bd0828", "refs/heads/stable", @key.user) + @merge_request.last_commit.id.should == "69b34b7e9ad9f496f0ad10250be37d6265a03bba" + project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "69b34b7e9ad9f496f0ad10250be37d6265a03bba", "refs/heads/stable", @key.user) @merge_request.reload @merge_request.merged?.should be_true end it "should update merge request commits with new one if pushed to source branch" do @merge_request.last_commit.should == nil - project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "b1e6a9dbf1c85e6616497a5e7bad9143a4bd0828", "refs/heads/master", @key.user) + project.update_merge_requests("8716fc78f3c65bbf7bcf7b574febd583bc5d2812", "69b34b7e9ad9f496f0ad10250be37d6265a03bba", "refs/heads/master", @key.user) @merge_request.reload - @merge_request.last_commit.id.should == "b1e6a9dbf1c85e6616497a5e7bad9143a4bd0828" + @merge_request.last_commit.id.should == "69b34b7e9ad9f496f0ad10250be37d6265a03bba" end end diff --git a/spec/seed_project.tar.gz b/spec/seed_project.tar.gz index b098a2c3b64..a2daf383277 100644 Binary files a/spec/seed_project.tar.gz and b/spec/seed_project.tar.gz differ -- cgit v1.2.1 From d819d0d1f84946bcc0d2c871682c220db6dbd478 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 23 Jan 2014 13:47:54 +0100 Subject: Use the correct paths. --- features/steps/project/project_markdown_render.rb | 4 ++-- spec/lib/gitlab/satellite/merge_action_spec.rb | 2 +- spec/seed_project.tar.gz | Bin 9825908 -> 9833961 bytes 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/steps/project/project_markdown_render.rb b/features/steps/project/project_markdown_render.rb index a74a8909140..a6c13b41e91 100644 --- a/features/steps/project/project_markdown_render.rb +++ b/features/steps/project/project_markdown_render.rb @@ -50,7 +50,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps end Then 'I should see correct doc/api directory rendered' do - current_path.should == project_tree_path(@project, "master/doc/api") + current_path.should == project_tree_path(@project, "master/doc/api/") page.should have_content "README.md" page.should have_content "users.md" end @@ -60,7 +60,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps end Then 'I should see correct maintenance file rendered' do - current_path.should == project_blob_path(@project, "doc/raketasks/maintenance.md") + current_path.should == project_blob_path(@project, "master/doc/raketasks/maintenance.md") page.should have_content "bundle exec rake gitlab:env:info RAILS_ENV=production" end diff --git a/spec/lib/gitlab/satellite/merge_action_spec.rb b/spec/lib/gitlab/satellite/merge_action_spec.rb index d2f026f96e8..e144b7c43d1 100644 --- a/spec/lib/gitlab/satellite/merge_action_spec.rb +++ b/spec/lib/gitlab/satellite/merge_action_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe 'Gitlab::Satellite::MergeAction' do before(:each) do - @master = ['master', 'b1e6a9dbf1c85e6616497a5e7bad9143a4bd0828'] + @master = ['master', '69b34b7e9ad9f496f0ad10250be37d6265a03bba'] @one_after_stable = ['stable', '6ea87c47f0f8a24ae031c3fff17bc913889ecd00'] #this commit sha is one after stable @wiki_branch = ['wiki', '635d3e09b72232b6e92a38de6cc184147e5bcb41'] #this is the commit sha where the wiki branch goes off from master @conflicting_metior = ['metior', '313d96e42b313a0af5ab50fa233bf43e27118b3f'] #this branch conflicts with the wiki branch diff --git a/spec/seed_project.tar.gz b/spec/seed_project.tar.gz index a2daf383277..ee8c3f23c70 100644 Binary files a/spec/seed_project.tar.gz and b/spec/seed_project.tar.gz differ -- cgit v1.2.1