Commit c07251887c08553a2f734d7a18e6cfefad7a7084

Authored by Marin Jankovski
2 parents 46549992 4123c76e

Merge branch 'master' into relative_links_in_documentation

app/observers/project_observer.rb
@@ -14,6 +14,11 @@ class ProjectObserver < BaseObserver @@ -14,6 +14,11 @@ class ProjectObserver < BaseObserver
14 14
15 log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"") 15 log_info("#{project.owner.name} created a new project \"#{project.name_with_namespace}\"")
16 end 16 end
  17 +
  18 + if project.wiki_enabled?
  19 + # force the creation of a wiki,
  20 + GollumWiki.new(project, project.owner).wiki
  21 + end
17 end 22 end
18 23
19 def after_update(project) 24 def after_update(project)
doc/api/repositories.md
@@ -356,3 +356,16 @@ Parameters: @@ -356,3 +356,16 @@ Parameters:
356 + `id` (required) - The ID of a project 356 + `id` (required) - The ID of a project
357 + `sha` (required) - The commit or branch name 357 + `sha` (required) - The commit or branch name
358 + `filepath` (required) - The path the file 358 + `filepath` (required) - The path the file
  359 +
  360 +
  361 +## Get file archive
  362 +
  363 +Get a an archive of the repository
  364 +
  365 +```
  366 +GET /projects/:id/repository/archive
  367 +```
  368 +
  369 +Parameters:
  370 ++ `id` (required) - The ID of a project
  371 ++ `sha` (optional) - The commit sha to download defaults to the tip of the default branch
359 \ No newline at end of file 372 \ No newline at end of file
lib/api/repositories.rb
@@ -144,7 +144,7 @@ module API @@ -144,7 +144,7 @@ module API
144 trees = [] 144 trees = []
145 145
146 %w(trees blobs submodules).each do |type| 146 %w(trees blobs submodules).each do |type|
147 - trees += tree.send(type).map { |t| { name: t.name, type: type.singularize, mode: t.mode, id: t.id } } 147 + trees += tree.send(type).map { |t| {name: t.name, type: type.singularize, mode: t.mode, id: t.id} }
148 end 148 end
149 149
150 trees 150 trees
@@ -176,6 +176,34 @@ module API @@ -176,6 +176,34 @@ module API
176 content_type blob.mime_type 176 content_type blob.mime_type
177 present blob.data 177 present blob.data
178 end 178 end
  179 +
  180 + # Get a an archive of the repository
  181 + #
  182 + # Parameters:
  183 + # id (required) - The ID of a project
  184 + # sha (optional) - the commit sha to download defaults to the tip of the default branch
  185 + # Example Request:
  186 + # GET /projects/:id/repository/archive
  187 + get ":id/repository/archive" do
  188 + authorize! :download_code, user_project
  189 + repo = user_project.repository
  190 + ref = params[:sha]
  191 + storage_path = Rails.root.join("tmp", "repositories")
  192 +
  193 + file_path = repo.archive_repo(ref, storage_path)
  194 + if file_path && File.exists?(file_path)
  195 + data = File.open(file_path, 'rb').read
  196 +
  197 + header "Content-Disposition:", " infile; filename=\"#{File.basename(file_path)}\""
  198 + content_type 'application/x-gzip'
  199 +
  200 + env['api.format'] = :binary
  201 +
  202 + present data
  203 + else
  204 + not_found!
  205 + end
  206 + end
179 end 207 end
180 end 208 end
181 end 209 end
spec/observers/users_project_observer_spec.rb
@@ -65,4 +65,30 @@ describe UsersProjectObserver do @@ -65,4 +65,30 @@ describe UsersProjectObserver do
65 @users_project.destroy 65 @users_project.destroy
66 end 66 end
67 end 67 end
68 -end 68 +
  69 + describe "#after_create" do
  70 + context 'wiki_enabled creates repository directory' do
  71 + context 'wiki_enabled true creates wiki repository directory' do
  72 + before do
  73 + @project = create(:project, wiki_enabled: true)
  74 + @path = GollumWiki.new(@project, user).send(:path_to_repo)
  75 + end
  76 +
  77 + after do
  78 + FileUtils.rm_rf(@path)
  79 + end
  80 +
  81 + it { File.exists?(@path).should be_true }
  82 + end
  83 +
  84 + context 'wiki_enabled false does not create wiki repository directory' do
  85 + before do
  86 + @project = create(:project, wiki_enabled: false)
  87 + @path = GollumWiki.new(@project, user).send(:path_to_repo)
  88 + end
  89 +
  90 + it { File.exists?(@path).should be_false }
  91 + end
  92 + end
  93 + end
  94 +end
69 \ No newline at end of file 95 \ No newline at end of file
spec/requests/api/repositories_spec.rb
@@ -225,4 +225,16 @@ describe API::API do @@ -225,4 +225,16 @@ describe API::API do
225 end 225 end
226 end 226 end
227 227
  228 + describe "GET /projects/:id/repository/archive/:sha" do
  229 + it "should get the archive" do
  230 + get api("/projects/#{project.id}/repository/archive", user)
  231 + response.status.should == 200
  232 + response.content_type.should == 'application/x-gzip'
  233 + end
  234 +
  235 + it "should return 404 for invalid sha" do
  236 + get api("/projects/#{project.id}/repository/archive/?sha=xxx", user)
  237 + response.status.should == 404
  238 + end
  239 + end
228 end 240 end