From 02822f74dac710504f171e67f26ee64e063a2ff6 Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Mon, 30 Dec 2013 10:34:27 -0500 Subject: Added support for Go's repository retrieval. - Simply adds the releavant meta link in the project's show action. - Information about this meta tag can be found here: http://golang.org/cmd/go/#hdr-Remote_import_paths --- app/views/layouts/_head.html.haml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 0775abea3dd..d4ac9287202 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,5 +1,10 @@ %head %meta{charset: "utf-8"} + + -# Go repository retrieval support. + - if controller_name == 'projects' && action_name == 'show' + %meta{name: "go-import", content: "#{Gitlab.config.gitlab.host}/#{@project.namespace.path}/#{@project.path} git http://#{Gitlab.config.gitlab.host}/#{@project.namespace.path}/#{@project.path}.git"} + %title = "#{title} | " if defined?(title) GitLab -- cgit v1.2.1 From 9393809066c10d1568e75372a8c99c3a67bed489 Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Mon, 30 Dec 2013 15:14:15 -0500 Subject: Use project methods instead of attributes. - This should work correctly in all cases now. - Added a new project method that returns the web url for a project without the scheme prefix. --- app/models/project.rb | 4 ++++ app/views/layouts/_head.html.haml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index a55f7a65b0b..1384165231c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -201,6 +201,10 @@ class Project < ActiveRecord::Base [Gitlab.config.gitlab.url, path_with_namespace].join("/") end + def web_url_without_scheme + [Gitlab.config.gitlab.host, path_with_namespace].join("/") + end + def build_commit_note(commit) notes.new(commit_id: commit.id, noteable_type: "Commit") end diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index d4ac9287202..97f7e343fad 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -3,7 +3,7 @@ -# Go repository retrieval support. - if controller_name == 'projects' && action_name == 'show' - %meta{name: "go-import", content: "#{Gitlab.config.gitlab.host}/#{@project.namespace.path}/#{@project.path} git http://#{Gitlab.config.gitlab.host}/#{@project.namespace.path}/#{@project.path}.git"} + %meta{name: "go-import", content: "#{@project.web_url_without_scheme} git #{@project.web_url}.git"} %title = "#{title} | " if defined?(title) -- cgit v1.2.1 From ee3046f9a9f496b84b6b1e5e0d17dc69cecc72ff Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Mon, 30 Dec 2013 17:44:11 -0500 Subject: Use web_url for web_url_without_scheme. - Previus version was still incorrect as it ignored cases where GitLab would be installed in a custom location. - This assumes that if this method can be calle, web_url will return a valid URL. --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 1384165231c..add54eb898b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -202,7 +202,7 @@ class Project < ActiveRecord::Base end def web_url_without_scheme - [Gitlab.config.gitlab.host, path_with_namespace].join("/") + web_url.split("://")[1] end def build_commit_note(commit) -- cgit v1.2.1 From b75401d5910af3744596d54dba36ba4de87aae4e Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Mon, 20 Jan 2014 05:45:17 -0500 Subject: Move Go specific meta tag after the atom feed code. --- app/views/layouts/_head.html.haml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 97f7e343fad..2fe31486608 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,10 +1,5 @@ %head %meta{charset: "utf-8"} - - -# Go repository retrieval support. - - if controller_name == 'projects' && action_name == 'show' - %meta{name: "go-import", content: "#{@project.web_url_without_scheme} git #{@project.web_url}.git"} - %title = "#{title} | " if defined?(title) GitLab @@ -25,3 +20,8 @@ = auto_discovery_link_tag(:atom, project_commits_url(@project, @ref, format: :atom, private_token: current_user.private_token), title: "Recent commits to #{@project.name}:#{@ref}") - if current_controller?(:issues) = auto_discovery_link_tag(:atom, project_issues_url(@project, :atom, private_token: current_user.private_token), title: "#{@project.name} issues") + + -# Go repository retrieval support. + - if controller_name == 'projects' && action_name == 'show' + %meta{name: "go-import", content: "#{@project.web_url_without_scheme} git #{@project.web_url}.git"} + -- cgit v1.2.1 From fb782476f9b68641019d91cf6de9899333518ab5 Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Mon, 20 Jan 2014 06:26:34 -0500 Subject: Change web_url_without scheme to web_url_without_protocol. --- app/models/project.rb | 2 +- app/views/layouts/_head.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index add54eb898b..b022bb4ebb2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -201,7 +201,7 @@ class Project < ActiveRecord::Base [Gitlab.config.gitlab.url, path_with_namespace].join("/") end - def web_url_without_scheme + def web_url_without_protocol web_url.split("://")[1] end diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index 2fe31486608..6d8139a0bbb 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -23,5 +23,5 @@ -# Go repository retrieval support. - if controller_name == 'projects' && action_name == 'show' - %meta{name: "go-import", content: "#{@project.web_url_without_scheme} git #{@project.web_url}.git"} + %meta{name: "go-import", content: "#{@project.web_url_without_protocol} git #{@project.web_url}.git"} -- cgit v1.2.1 From e77694bff3e0867f226be28108b814895d32d354 Mon Sep 17 00:00:00 2001 From: Bruno Albuquerque Date: Mon, 20 Jan 2014 08:00:50 -0500 Subject: Added a simple test to web_url_without_protocol. --- spec/models/project_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 8aa4c7fed1a..373accfe412 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -99,6 +99,11 @@ describe Project do project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere" end + it "returns the web URL without the protocol for this repo" do + project = Project.new(path: "somewhere") + project.web_url_without_protocol.should == "#{Gitlab.config.gitlab.host}/somewhere" + end + describe "last_activity methods" do let(:project) { create(:project) } let(:last_event) { double(created_at: Time.now) } -- cgit v1.2.1