Add option to add README when creating a project
This commit is contained in:
parent
7e9f46d0dc
commit
9561db7b8c
7 changed files with 68 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -347,6 +347,7 @@ class ProjectsController < Projects::ApplicationController
|
|||
:visibility_level,
|
||||
:template_name,
|
||||
:merge_method,
|
||||
:initialize_with_readme,
|
||||
|
||||
project_feature_attributes: %i[
|
||||
builds_access_level
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add option to add README when creating a project
|
||||
merge_request: 20335
|
||||
author:
|
||||
type: added
|
|
@ -48,6 +48,15 @@ feature 'New project' do
|
|||
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 'with user namespace' do
|
||||
before do
|
||||
|
|
|
@ -236,6 +236,18 @@ describe Projects::CreateService, '#execute' do
|
|||
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
|
||||
before do
|
||||
create(:service, project: nil, template: true, active: true)
|
||||
|
|
Loading…
Reference in a new issue