Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
9561db7b
Commit
9561db7b
authored
Jul 03, 2018
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to add README when creating a project
parent
7e9f46d0
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
1 deletion
+68
-1
app/assets/stylesheets/pages/settings.scss
app/assets/stylesheets/pages/settings.scss
+16
-0
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+1
-0
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+15
-1
app/views/projects/_new_project_fields.html.haml
app/views/projects/_new_project_fields.html.haml
+10
-0
changelogs/unreleased/19468-add_readme_when_creating_project.yml
...ogs/unreleased/19468-add_readme_when_creating_project.yml
+5
-0
spec/features/projects/new_project_spec.rb
spec/features/projects/new_project_spec.rb
+9
-0
spec/services/projects/create_service_spec.rb
spec/services/projects/create_service_spec.rb
+12
-0
No files found.
app/assets/stylesheets/pages/settings.scss
View file @
9561db7b
...
@@ -191,6 +191,22 @@
...
@@ -191,6 +191,22 @@
}
}
}
}
.initialize-with-readme-setting
{
.form-check
{
margin-bottom
:
10px
;
.option-title
{
font-weight
:
$gl-font-weight-normal
;
display
:
inline-block
;
color
:
$gl-text-color
;
}
.option-description
{
color
:
$project-option-descr-color
;
}
}
}
.prometheus-metrics-monitoring
{
.prometheus-metrics-monitoring
{
.card
{
.card
{
.card-toggle
{
.card-toggle
{
...
...
app/controllers/projects_controller.rb
View file @
9561db7b
...
@@ -347,6 +347,7 @@ class ProjectsController < Projects::ApplicationController
...
@@ -347,6 +347,7 @@ class ProjectsController < Projects::ApplicationController
:visibility_level
,
:visibility_level
,
:template_name
,
:template_name
,
:merge_method
,
:merge_method
,
:initialize_with_readme
,
project_feature_attributes:
%i[
project_feature_attributes:
%i[
builds_access_level
builds_access_level
...
...
app/services/projects/create_service.rb
View file @
9561db7b
...
@@ -2,6 +2,8 @@ module Projects
...
@@ -2,6 +2,8 @@ module Projects
class
CreateService
<
BaseService
class
CreateService
<
BaseService
def
initialize
(
user
,
params
)
def
initialize
(
user
,
params
)
@current_user
,
@params
=
user
,
params
.
dup
@current_user
,
@params
=
user
,
params
.
dup
@skip_wiki
=
@params
.
delete
(
:skip_wiki
)
@initialize_with_readme
=
Gitlab
::
Utils
.
to_boolean
(
@params
.
delete
(
:initialize_with_readme
))
end
end
def
execute
def
execute
...
@@ -11,7 +13,6 @@ module Projects
...
@@ -11,7 +13,6 @@ module Projects
forked_from_project_id
=
params
.
delete
(
:forked_from_project_id
)
forked_from_project_id
=
params
.
delete
(
:forked_from_project_id
)
import_data
=
params
.
delete
(
:import_data
)
import_data
=
params
.
delete
(
:import_data
)
@skip_wiki
=
params
.
delete
(
:skip_wiki
)
@project
=
Project
.
new
(
params
)
@project
=
Project
.
new
(
params
)
...
@@ -102,6 +103,8 @@ module Projects
...
@@ -102,6 +103,8 @@ module Projects
setup_authorizations
setup_authorizations
current_user
.
invalidate_personal_projects_count
current_user
.
invalidate_personal_projects_count
create_readme
if
@initialize_with_readme
end
end
# Refresh the current user's authorizations inline (so they can access the
# Refresh the current user's authorizations inline (so they can access the
...
@@ -116,6 +119,17 @@ module Projects
...
@@ -116,6 +119,17 @@ module Projects
end
end
end
end
def
create_readme
commit_attrs
=
{
branch_name:
'master'
,
commit_message:
'Initial commit'
,
file_path:
'README.md'
,
file_content:
"#
#{
@project
.
name
}
\n\n
#{
@project
.
description
}
"
}
Files
::
CreateService
.
new
(
@project
,
current_user
,
commit_attrs
).
execute
end
def
skip_wiki?
def
skip_wiki?
!
@project
.
feature_available?
(
:wiki
,
current_user
)
||
@skip_wiki
!
@project
.
feature_available?
(
:wiki
,
current_user
)
||
@skip_wiki
end
end
...
...
app/views/projects/_new_project_fields.html.haml
View file @
9561db7b
...
@@ -40,5 +40,15 @@
...
@@ -40,5 +40,15 @@
=
link_to
icon
(
'question-circle'
),
help_page_path
(
"public_access/public_access"
),
aria:
{
label:
'Documentation for Visibility Level'
},
target:
'_blank'
,
rel:
'noopener noreferrer'
=
link_to
icon
(
'question-circle'
),
help_page_path
(
"public_access/public_access"
),
aria:
{
label:
'Documentation for Visibility Level'
},
target:
'_blank'
,
rel:
'noopener noreferrer'
=
render
'shared/visibility_level'
,
f:
f
,
visibility_level:
visibility_level
.
to_i
,
can_change_visibility_level:
true
,
form_model:
@project
,
with_label:
false
=
render
'shared/visibility_level'
,
f:
f
,
visibility_level:
visibility_level
.
to_i
,
can_change_visibility_level:
true
,
form_model:
@project
,
with_label:
false
.form-group.row.initialize-with-readme-setting
%div
{
:class
=>
"col-sm-12"
}
.form-check
=
check_box_tag
'project[initialize_with_readme]'
,
'1'
,
false
,
class:
'form-check-input'
=
label_tag
'project[initialize_with_readme]'
,
class:
'form-check-label'
do
.option-title
%strong
Initialize repository with a README
.option-description
Allows you to immediately clone this project’s repository. Skip this if you plan to push up an existing repository.
=
f
.
submit
'Create project'
,
class:
"btn btn-create project-submit"
,
tabindex:
4
=
f
.
submit
'Create project'
,
class:
"btn btn-create project-submit"
,
tabindex:
4
=
link_to
'Cancel'
,
dashboard_projects_path
,
class:
'btn btn-cancel'
=
link_to
'Cancel'
,
dashboard_projects_path
,
class:
'btn btn-cancel'
changelogs/unreleased/19468-add_readme_when_creating_project.yml
0 → 100644
View file @
9561db7b
---
title
:
Add option to add README when creating a project
merge_request
:
20335
author
:
type
:
added
spec/features/projects/new_project_spec.rb
View file @
9561db7b
...
@@ -48,6 +48,15 @@ feature 'New project' do
...
@@ -48,6 +48,15 @@ feature 'New project' do
end
end
end
end
context
'Readme selector'
do
it
'shows the initialize with Readme checkbox'
do
visit
new_project_path
expect
(
page
).
to
have_css
(
'input#project_initialize_with_readme'
)
expect
(
page
).
to
have_content
(
'Initialize repository with a README'
)
end
end
context
'Namespace selector'
do
context
'Namespace selector'
do
context
'with user namespace'
do
context
'with user namespace'
do
before
do
before
do
...
...
spec/services/projects/create_service_spec.rb
View file @
9561db7b
...
@@ -236,6 +236,18 @@ describe Projects::CreateService, '#execute' do
...
@@ -236,6 +236,18 @@ describe Projects::CreateService, '#execute' do
end
end
end
end
context
'when readme initialization is requested'
do
it
'creates README.md'
do
opts
[
:initialize_with_readme
]
=
'1'
project
=
create_project
(
user
,
opts
)
expect
(
project
.
repository
.
commit_count
).
to
be
(
1
)
expect
(
project
.
repository
.
readme
.
name
).
to
eql
(
'README.md'
)
expect
(
project
.
repository
.
readme
.
data
).
to
include
(
'# GitLab'
)
end
end
context
'when there is an active service template'
do
context
'when there is an active service template'
do
before
do
before
do
create
(
:service
,
project:
nil
,
template:
true
,
active:
true
)
create
(
:service
,
project:
nil
,
template:
true
,
active:
true
)
...
...
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