Last active
December 14, 2015 13:59
-
-
Save d3m3vilurr/5097354 to your computer and use it in GitHub Desktop.
Add public archive download link for GITLAP 6.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/controllers/public/repositories_controller.rb b/app/controllers/public/repositories_controller.rb | |
new file mode 100644 | |
index 0000000..d088a2c | |
--- /dev/null | |
+++ b/app/controllers/public/repositories_controller.rb | |
@@ -0,0 +1,41 @@ | |
+class Public::RepositoriesController < ApplicationController | |
+ include Gitlab::VisibilityLevel | |
+ | |
+ skip_before_filter :authenticate_user!, :reject_blocked, :set_current_user_for_observers, :add_abilities | |
+ | |
+ layout 'public' | |
+ | |
+ def archive | |
+ if repository | |
+ storage_path = Rails.root.join("tmp", "repositories") | |
+ | |
+ file_path = @repository.archive_repo(params[:ref], storage_path) | |
+ | |
+ if file_path | |
+ send_file file_path | |
+ return | |
+ end | |
+ end | |
+ render_404 | |
+ end | |
+ | |
+ private | |
+ | |
+ def public_project | |
+ id = params[:project_id] || params[:id] | |
+ @project = Project.find_with_namespace(id) | |
+ | |
+ if @project && @project.visibility_level == PUBLIC | |
+ @project | |
+ else | |
+ @project = nil | |
+ render_404 | |
+ end | |
+ end | |
+ | |
+ def repository | |
+ @repository ||= public_project.repository | |
+ rescue Grit::NoSuchPathError | |
+ nil | |
+ end | |
+end | |
diff --git a/app/models/project.rb b/app/models/project.rb | |
index da5f25f..cc25142 100644 | |
--- a/app/models/project.rb | |
+++ b/app/models/project.rb | |
@@ -420,6 +420,10 @@ class Project < ActiveRecord::Base | |
[Gitlab.config.gitlab.url, "/", path_with_namespace, ".git"].join('') | |
end | |
+ def http_url_to_public_archive | |
+ http_url = [Gitlab.config.gitlab.url, "/public/", path_with_namespace, "/archive"].join('') | |
+ end | |
+ | |
# Check if current branch name is marked as protected in the system | |
def protected_branch? branch_name | |
protected_branches_names.include?(branch_name) | |
diff --git a/app/views/public/projects/index.html.haml b/app/views/public/projects/index.html.haml | |
index 2fc93c5..a5df4d5 100644 | |
--- a/app/views/public/projects/index.html.haml | |
+++ b/app/views/public/projects/index.html.haml | |
@@ -46,6 +46,10 @@ | |
= internal_icon | |
Internal | |
.pull-right | |
+ = link_to public_archive_path(project), class: "btn-small btn" do | |
+ %i.icon-download-alt | |
+ Download | |
+ .pull-right | |
%pre.public-clone git clone #{project.http_url_to_repo} | |
- if project.description.present? | |
diff --git a/config/routes.rb b/config/routes.rb | |
index 315c339..cb19385 100644 | |
--- a/config/routes.rb | |
+++ b/config/routes.rb | |
@@ -56,7 +56,9 @@ Gitlab::Application.routes.draw do | |
# Public namespace | |
# | |
namespace :public do | |
- resources :projects, only: [:index] | |
+ | |
+ resources :projects, constraints: { project_id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/ }, only: [:index] | |
+ get "/:project_id/archive" => "repositories#archive", constraints: { project_id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/ }, :as => 'archive' | |
root to: "projects#index" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment