Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #3206

Closed
Open
Created Mar 13, 2013 by Administrator@rootOwner

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
Assignee
Assign to
Time tracking