BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
5248e37f
Commit
5248e37f
authored
Mar 14, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds the option to override project description on export via API
and fixes the project description not being imported
parent
a63d7470
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
60 additions
and
11 deletions
+60
-11
project.rb
app/models/project.rb
+2
-2
export_service.rb
app/services/projects/import_export/export_service.rb
+1
-1
project_export_worker.rb
app/workers/project_export_worker.rb
+3
-2
41902-add-api-option-to-overwrite-project-description-on-project-export.yml
...on-to-overwrite-project-description-on-project-export.yml
+5
-0
project_import_export.md
doc/api/project_import_export.md
+2
-1
project_export.rb
lib/api/project_export.rb
+6
-1
project_tree_restorer.rb
lib/gitlab/import_export/project_tree_restorer.rb
+8
-2
project_tree_saver.rb
lib/gitlab/import_export/project_tree_saver.rb
+6
-1
import_file_spec.rb
spec/features/projects/import_export/import_file_spec.rb
+1
-0
test_project_export.tar.gz
...eatures/projects/import_export/test_project_export.tar.gz
+0
-0
project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+4
-0
project_tree_saver_spec.rb
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
+11
-1
project_export_spec.rb
spec/requests/api/project_export_spec.rb
+11
-0
No files found.
app/models/project.rb
View file @
5248e37f
...
...
@@ -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
}
"
...
...
app/services/projects/import_export/export_service.rb
View file @
5248e37f
...
...
@@ -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
...
...
app/workers/project_export_worker.rb
View file @
5248e37f
...
...
@@ -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
changelogs/unreleased/41902-add-api-option-to-overwrite-project-description-on-project-export.yml
0 → 100644
View file @
5248e37f
---
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
doc/api/project_import_export.md
View file @
5248e37f
...
...
@@ -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
...
...
lib/api/project_export.rb
View file @
5248e37f
...
...
@@ -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
...
...
lib/gitlab/import_export/project_tree_restorer.rb
View file @
5248e37f
...
...
@@ -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
(
p
roject_p
arams
)
@project
.
update_columns
(
params
)
@project
end
...
...
lib/gitlab/import_export/project_tree_saver.rb
View file @
5248e37f
...
...
@@ -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
...
...
spec/features/projects/import_export/import_file_spec.rb
View file @
5248e37f
...
...
@@ -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
...
...
spec/features/projects/import_export/test_project_export.tar.gz
View file @
5248e37f
No preview for this file type
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
5248e37f
...
...
@@ -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
...
...
spec/lib/gitlab/import_export/project_tree_saver_spec.rb
View file @
5248e37f
...
...
@@ -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
],
...
...
spec/requests/api/project_export_spec.rb
View file @
5248e37f
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment