API: allow downloading of archive
Created by: nickygerritsen
It would be nice if the API would allow downloading of project archives.
The following code does this (but is maybe not the way "it" should be done):
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index a16243a..af91780 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -421,6 +421,22 @@ module Gitlab
present tree.data
end
+ # Get an archive of the project
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # ref_name (optional) - The name of a repository branch or tag
+ # Example Request:
+ # GET /projects/:id/repository/archive
+ get ":id/repository/archive" do
+ authorize! :download_code, user_project
+
+ ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
+ file_path = user_project.repository.archive_repo(ref)
+
+ present File.read(file_path)
+ end
+
end
end
end