Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-25 02:01:57 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-25 02:01:57 +0400
commitced4a37a186601b37121c19523955b96767d9af5 (patch)
tree8cc894df172aa59684a4d8ec0f723f0da437e06c
parentff07a5ab8487bce1d8c46f5c4b28ad54ce99d9cd (diff)
parent54bcb6cc2a863e10abdd76745d3a0d50c301ab77 (diff)
Merge branch 'reference_relative_links' into 'master'
Reference style links with relative links in markdown #996 ``` Adds relative links support to reference style links, eg: [GitLab API doc directory][GitLab API directory listing] [Maintenance][Maintenance rake task] \[GitLab API directory listing]: doc/api/ \[Maintenance rake task]: doc/raketasks/maintenance.md ```
-rw-r--r--app/helpers/gitlab_markdown_helper.rb31
-rw-r--r--features/project/source/markdown_render.feature12
-rw-r--r--features/steps/project/project_markdown_render.rb22
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb18
-rw-r--r--spec/lib/gitlab/satellite/merge_action_spec.rb2
-rw-r--r--spec/models/project_spec.rb8
-rw-r--r--spec/seed_project.tar.gzbin9795570 -> 9833961 bytes
7 files changed, 82 insertions, 11 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
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 0472cfef32d..1209aae6434 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, "master/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/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index 088a6a09bc8..c3429d5894d 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 = "<p><a href=\"/#{project.path_with_namespace}/wikis/test/link\">Link</a></p>\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 = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\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 = "<p><a href=\"/#{project.path_with_namespace}/tree/master/doc/api/\">GitLab API doc directory</a></p>\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
diff --git a/spec/lib/gitlab/satellite/merge_action_spec.rb b/spec/lib/gitlab/satellite/merge_action_spec.rb
index 25ddf87dc82..ef06c742846 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/models/project_spec.rb b/spec/models/project_spec.rb
index 8fe669487f5..6837e4c9196 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -137,16 +137,16 @@ describe Project do
it "should close merge request if last commit from source branch was pushed to target branch" do
@merge_request.reload_code
- @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
- 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 7abb51ebdfd..ee8c3f23c70 100644
--- a/spec/seed_project.tar.gz
+++ b/spec/seed_project.tar.gz
Binary files differ