Commit 5248e37f authored by Tiago Botelho's avatar Tiago Botelho

Adds the option to override project description on export via API

and fixes the project description not being imported
parent a63d7470
...@@ -1519,8 +1519,8 @@ class Project < ActiveRecord::Base ...@@ -1519,8 +1519,8 @@ class Project < ActiveRecord::Base
@errors = original_errors @errors = original_errors
end end
def add_export_job(current_user:) def add_export_job(current_user:, params: {})
job_id = ProjectExportWorker.perform_async(current_user.id, self.id) job_id = ProjectExportWorker.perform_async(current_user.id, self.id, params)
if job_id if job_id
Rails.logger.info "Export job started for project ID #{self.id} with job ID #{job_id}" Rails.logger.info "Export job started for project ID #{self.id} with job ID #{job_id}"
......
...@@ -26,7 +26,7 @@ module Projects ...@@ -26,7 +26,7 @@ module Projects
end end
def project_tree_saver def project_tree_saver
Gitlab::ImportExport::ProjectTreeSaver.new(project: project, current_user: @current_user, shared: @shared) Gitlab::ImportExport::ProjectTreeSaver.new(project: project, current_user: @current_user, shared: @shared, params: @params)
end end
def uploads_saver def uploads_saver
......
...@@ -4,10 +4,11 @@ class ProjectExportWorker ...@@ -4,10 +4,11 @@ class ProjectExportWorker
sidekiq_options retry: 3 sidekiq_options retry: 3
def perform(current_user_id, project_id) def perform(current_user_id, project_id, params = {})
params = params.with_indifferent_access
current_user = User.find(current_user_id) current_user = User.find(current_user_id)
project = Project.find(project_id) project = Project.find(project_id)
::Projects::ImportExport::ExportService.new(project, current_user).execute ::Projects::ImportExport::ExportService.new(project, current_user, params).execute
end end
end end
---
title: Adds the option to the project export API to override the project description and display GitLab export description once imported
merge_request: 17744
author:
type: added
...@@ -15,9 +15,10 @@ POST /projects/:id/export ...@@ -15,9 +15,10 @@ POST /projects/:id/export
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | -------------- | -------- | ---------------------------------------- | | --------- | -------------- | -------- | ---------------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user | | `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `description` | string | no | Overrides the project description |
```console ```console
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/1/export curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" --form "description=Foo Bar" https://gitlab.example.com/api/v4/projects/1/export
``` ```
```json ```json
......
...@@ -31,8 +31,13 @@ module API ...@@ -31,8 +31,13 @@ module API
desc 'Start export' do desc 'Start export' do
detail 'This feature was introduced in GitLab 10.6.' detail 'This feature was introduced in GitLab 10.6.'
end end
params do
optional :description, type: String, desc: 'Override the project description'
end
post ':id/export' do post ':id/export' do
user_project.add_export_job(current_user: current_user) project_export_params = declared_params(include_missing: false)
user_project.add_export_job(current_user: current_user, params: project_export_params)
accepted! accepted!
end end
......
...@@ -35,6 +35,8 @@ module Gitlab ...@@ -35,6 +35,8 @@ module Gitlab
end end
def restored_project def restored_project
return @project unless @tree_hash
@restored_project ||= restore_project @restored_project ||= restore_project
end end
...@@ -81,9 +83,13 @@ module Gitlab ...@@ -81,9 +83,13 @@ module Gitlab
end end
def restore_project def restore_project
return @project unless @tree_hash params = project_params
if params[:description].present?
params[:description_html] = nil
end
@project.update_columns(project_params) @project.update_columns(params)
@project @project
end end
......
...@@ -5,7 +5,8 @@ module Gitlab ...@@ -5,7 +5,8 @@ module Gitlab
attr_reader :full_path attr_reader :full_path
def initialize(project:, current_user:, shared:) def initialize(project:, current_user:, shared:, params: {})
@params = params
@project = project @project = project
@current_user = current_user @current_user = current_user
@shared = shared @shared = shared
...@@ -25,6 +26,10 @@ module Gitlab ...@@ -25,6 +26,10 @@ module Gitlab
private private
def project_json_tree def project_json_tree
if @params[:description].present?
project_json['description'] = @params[:description]
end
project_json['project_members'] += group_members_json project_json['project_members'] += group_members_json
project_json.to_json project_json.to_json
......
...@@ -41,6 +41,7 @@ feature 'Import/Export - project import integration test', :js do ...@@ -41,6 +41,7 @@ feature 'Import/Export - project import integration test', :js do
project = Project.last project = Project.last
expect(project).not_to be_nil expect(project).not_to be_nil
expect(project.description).to eq("Foo Bar")
expect(project.issues).not_to be_empty expect(project.issues).not_to be_empty
expect(project.merge_requests).not_to be_empty expect(project.merge_requests).not_to be_empty
expect(project_hook_exists?(project)).to be true expect(project_hook_exists?(project)).to be true
......
...@@ -42,6 +42,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do ...@@ -42,6 +42,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::ENABLED) expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::ENABLED)
end end
it 'has the project description' do
expect(Project.find_by_path('project').description).to eq('Nisi et repellendus ut enim quo accusamus vel magnam.')
end
it 'has the project html description' do it 'has the project html description' do
expect(Project.find_by_path('project').description_html).to eq('description') expect(Project.find_by_path('project').description_html).to eq('description')
end end
......
...@@ -29,8 +29,17 @@ describe Gitlab::ImportExport::ProjectTreeSaver do ...@@ -29,8 +29,17 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
project_json(project_tree_saver.full_path) project_json(project_tree_saver.full_path)
end end
context 'with description override' do
let(:params) { { description: 'Foo Bar' } }
let(:project_tree_saver) { described_class.new(project: project, current_user: user, shared: shared, params: params) }
it 'overrides the project description' do
expect(saved_project_json).to include({ 'description' => params[:description] })
end
end
it 'saves the correct json' do it 'saves the correct json' do
expect(saved_project_json).to include({ "visibility_level" => 20 }) expect(saved_project_json).to include({ 'description' => 'description', 'visibility_level' => 20 })
end end
it 'has milestones' do it 'has milestones' do
...@@ -259,6 +268,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do ...@@ -259,6 +268,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
:issues_disabled, :issues_disabled,
:wiki_enabled, :wiki_enabled,
:builds_private, :builds_private,
description: 'description',
issues: [issue], issues: [issue],
snippets: [snippet], snippets: [snippet],
releases: [release], releases: [release],
......
...@@ -285,6 +285,17 @@ describe API::ProjectExport do ...@@ -285,6 +285,17 @@ describe API::ProjectExport do
context 'when user is not a member' do context 'when user is not a member' do
it_behaves_like 'post project export start not found' it_behaves_like 'post project export start not found'
end end
context 'when overriding description' do
it 'starts' do
params = { description: "Foo" }
expect_any_instance_of(Projects::ImportExport::ExportService).to receive(:execute)
post api(path, project.owner), params
expect(response).to have_gitlab_http_status(202)
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment