BigW Consortium Gitlab

Commit 5248e37f by 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
@errors = original_errors
end
def add_export_job(current_user:)
job_id = ProjectExportWorker.perform_async(current_user.id, self.id)
def add_export_job(current_user:, params: {})
job_id = ProjectExportWorker.perform_async(current_user.id, self.id, params)
if job_id
Rails.logger.info "Export job started for project ID #{self.id} with job ID #{job_id}"
......
......@@ -26,7 +26,7 @@ module Projects
end
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
def uploads_saver
......
......@@ -4,10 +4,11 @@ class ProjectExportWorker
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)
project = Project.find(project_id)
::Projects::ImportExport::ExportService.new(project, current_user).execute
::Projects::ImportExport::ExportService.new(project, current_user, params).execute
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
| 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 |
| `description` | string | no | Overrides the project description |
```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
......
......@@ -31,8 +31,13 @@ module API
desc 'Start export' do
detail 'This feature was introduced in GitLab 10.6.'
end
params do
optional :description, type: String, desc: 'Override the project description'
end
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!
end
......
......@@ -35,6 +35,8 @@ module Gitlab
end
def restored_project
return @project unless @tree_hash
@restored_project ||= restore_project
end
......@@ -81,9 +83,13 @@ module Gitlab
end
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
end
......
......@@ -5,7 +5,8 @@ module Gitlab
attr_reader :full_path
def initialize(project:, current_user:, shared:)
def initialize(project:, current_user:, shared:, params: {})
@params = params
@project = project
@current_user = current_user
@shared = shared
......@@ -25,6 +26,10 @@ module Gitlab
private
def project_json_tree
if @params[:description].present?
project_json['description'] = @params[:description]
end
project_json['project_members'] += group_members_json
project_json.to_json
......
......@@ -41,6 +41,7 @@ feature 'Import/Export - project import integration test', :js do
project = Project.last
expect(project).not_to be_nil
expect(project.description).to eq("Foo Bar")
expect(project.issues).not_to be_empty
expect(project.merge_requests).not_to be_empty
expect(project_hook_exists?(project)).to be true
......
......@@ -42,6 +42,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(project.project_feature.merge_requests_access_level).to eq(ProjectFeature::ENABLED)
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
expect(Project.find_by_path('project').description_html).to eq('description')
end
......
......@@ -29,8 +29,17 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
project_json(project_tree_saver.full_path)
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
expect(saved_project_json).to include({ "visibility_level" => 20 })
expect(saved_project_json).to include({ 'description' => 'description', 'visibility_level' => 20 })
end
it 'has milestones' do
......@@ -259,6 +268,7 @@ describe Gitlab::ImportExport::ProjectTreeSaver do
:issues_disabled,
:wiki_enabled,
:builds_private,
description: 'description',
issues: [issue],
snippets: [snippet],
releases: [release],
......
......@@ -285,6 +285,17 @@ describe API::ProjectExport do
context 'when user is not a member' do
it_behaves_like 'post project export start not found'
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
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