diff options
author | Imre Farkas <ifarkas@gitlab.com> | 2018-07-03 15:09:58 +0200 |
---|---|---|
committer | Imre Farkas <ifarkas@gitlab.com> | 2018-07-04 17:35:23 +0200 |
commit | 9561db7b8c89586b5a163535a86ce2b5e0342343 (patch) | |
tree | 463cb0e466e718d9ac6ce8c3071c7b8a6ad6274f /app | |
parent | 7e9f46d0dc1ed34d7e7cb7b6ee31d08f53f2deaf (diff) | |
download | gitlab-ce-9561db7b8c89586b5a163535a86ce2b5e0342343.tar.gz |
Add option to add README when creating a project
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/stylesheets/pages/settings.scss | 16 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 1 | ||||
-rw-r--r-- | app/services/projects/create_service.rb | 16 | ||||
-rw-r--r-- | app/views/projects/_new_project_fields.html.haml | 10 |
4 files changed, 42 insertions, 1 deletions
diff --git a/app/assets/stylesheets/pages/settings.scss b/app/assets/stylesheets/pages/settings.scss index e264b06c4b2..839ac5ba59b 100644 --- a/app/assets/stylesheets/pages/settings.scss +++ b/app/assets/stylesheets/pages/settings.scss @@ -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 { .card { .card-toggle { diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c2492a137fb..ec3a5788ba1 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -347,6 +347,7 @@ class ProjectsController < Projects::ApplicationController :visibility_level, :template_name, :merge_method, + :initialize_with_readme, project_feature_attributes: %i[ builds_access_level diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index a02a9052fb2..172497b8e67 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -2,6 +2,8 @@ module Projects class CreateService < BaseService def initialize(user, params) @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 def execute @@ -11,7 +13,6 @@ module Projects forked_from_project_id = params.delete(:forked_from_project_id) import_data = params.delete(:import_data) - @skip_wiki = params.delete(:skip_wiki) @project = Project.new(params) @@ -102,6 +103,8 @@ module Projects setup_authorizations current_user.invalidate_personal_projects_count + + create_readme if @initialize_with_readme end # Refresh the current user's authorizations inline (so they can access the @@ -116,6 +119,17 @@ module Projects 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? !@project.feature_available?(:wiki, current_user) || @skip_wiki end diff --git a/app/views/projects/_new_project_fields.html.haml b/app/views/projects/_new_project_fields.html.haml index 6f957533287..f4994f5459b 100644 --- a/app/views/projects/_new_project_fields.html.haml +++ b/app/views/projects/_new_project_fields.html.haml @@ -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' = 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 = link_to 'Cancel', dashboard_projects_path, class: 'btn btn-cancel' |