From d513ca584aaed7ca2a1de2d2fbd2192422f13d81 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 24 Feb 2015 16:48:22 +0100 Subject: Revert "Merge branch 'go-get-workaround-nginx' of https://github.com/mattes/gitlabhq into mattes-go-get-workaround-nginx" This reverts commit 51349ca3c83c56e072f87253d375316f7164b49a, reversing changes made to b180476bd69bdf99b1727b041116fa8447c0201f. --- app/views/layouts/_head.html.haml | 7 +++++++ lib/support/nginx/gitlab | 10 ---------- lib/support/nginx/gitlab-ssl | 10 ---------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index d12145651af..bece8061fb9 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,5 +1,12 @@ %head %meta{charset: "utf-8"} + + -# Go repository retrieval support + -# Need to be the fist thing in the head + -# Since Go is using an XML parser to process HTML5 + -# https://github.com/gitlabhq/gitlabhq/pull/5958#issuecomment-45397555 + - if controller_name == 'projects' && action_name == 'show' + %meta{name: "go-import", content: "#{@project.web_url_without_protocol} git #{@project.web_url}.git"} %meta{content: "GitLab Community Edition", name: "description"} %title diff --git a/lib/support/nginx/gitlab b/lib/support/nginx/gitlab index fd5b2664786..62a4276536c 100644 --- a/lib/support/nginx/gitlab +++ b/lib/support/nginx/gitlab @@ -77,16 +77,6 @@ server { proxy_pass http://gitlab; } - ## If ``go get`` detected, return go-import meta tag. - ## This works for public and for private repositories. - ## See also http://golang.org/cmd/go/#hdr-Remote_import_paths - if ($http_user_agent ~* "Go") { - return 200 " - - - "; - } - ## If a file, which is not found in the root folder is requested, ## then the proxy passes the request to the upsteam (gitlab unicorn). location @gitlab { diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl index a9699bac611..2aefc944698 100644 --- a/lib/support/nginx/gitlab-ssl +++ b/lib/support/nginx/gitlab-ssl @@ -123,16 +123,6 @@ server { proxy_pass http://gitlab; } - ## If ``go get`` detected, return go-import meta tag. - ## This works for public and for private repositories. - ## See also http://golang.org/cmd/go/#hdr-Remote_import_paths - if ($http_user_agent ~* "Go") { - return 200 " - - - "; - } - ## If a file, which is not found in the root folder is requested, ## then the proxy passes the request to the upsteam (gitlab unicorn). location @gitlab { -- cgit v1.2.1 From 3702c4ad80614d71fc5ac3ea1af7c3789ec8146d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 24 Feb 2015 17:02:11 +0100 Subject: Render go-import meta tag for private repos. --- app/controllers/projects_controller.rb | 11 +++++++++++ app/views/layouts/_head.html.haml | 7 ------- app/views/projects/go_import.html.haml | 5 +++++ spec/controllers/projects_controller_spec.rb | 16 ++++++++++++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 app/views/projects/go_import.html.haml diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5486a97e51d..82b8a1cc13a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,4 +1,5 @@ class ProjectsController < ApplicationController + prepend_before_filter :render_go_import, only: [:show] skip_before_filter :authenticate_user!, only: [:show] before_filter :project, except: [:new, :create] before_filter :repository, except: [:new, :create] @@ -184,4 +185,14 @@ class ProjectsController < ApplicationController end end end + + def render_go_import + return unless params["go-get"] == "1" + + @namespace = params[:namespace_id] + @id = params[:project_id] || params[:id] + @id = @id.gsub(/\.git\Z/, "") + + render "go_import", layout: false + end end diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml index bece8061fb9..d12145651af 100644 --- a/app/views/layouts/_head.html.haml +++ b/app/views/layouts/_head.html.haml @@ -1,12 +1,5 @@ %head %meta{charset: "utf-8"} - - -# Go repository retrieval support - -# Need to be the fist thing in the head - -# Since Go is using an XML parser to process HTML5 - -# https://github.com/gitlabhq/gitlabhq/pull/5958#issuecomment-45397555 - - if controller_name == 'projects' && action_name == 'show' - %meta{name: "go-import", content: "#{@project.web_url_without_protocol} git #{@project.web_url}.git"} %meta{content: "GitLab Community Edition", name: "description"} %title diff --git a/app/views/projects/go_import.html.haml b/app/views/projects/go_import.html.haml new file mode 100644 index 00000000000..87ac75a350f --- /dev/null +++ b/app/views/projects/go_import.html.haml @@ -0,0 +1,5 @@ +!!! 5 +%html + %head + - web_url = [Gitlab.config.gitlab.url, @namespace, @id].join('/') + %meta{name: "go-import", content: "#{web_url.split('://')[1]} git #{web_url}.git"} diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 89bb35de8fc..a1b82a32150 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -7,6 +7,22 @@ describe ProjectsController do let(:jpg) { fixture_file_upload(Rails.root + 'spec/fixtures/rails_sample.jpg', 'image/jpg') } let(:txt) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') } + describe "GET show" do + + context "when requested by `go get`" do + render_views + + it "renders the go-import meta tag" do + get :show, "go-get" => "1", namespace_id: "bogus_namespace", id: "bogus_project" + + expect(response.body).to include("name='go-import'") + + content = "localhost/bogus_namespace/bogus_project git http://localhost/bogus_namespace/bogus_project.git" + expect(response.body).to include("content='#{content}'") + end + end + end + describe "POST #toggle_star" do it "toggles star if user is signed in" do sign_in(user) -- cgit v1.2.1