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
c5b29ed6
Commit
c5b29ed6
authored
Feb 23, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'create_branch_repo_less' into 'master'
Create master branch first if project is repository-less Closes #26687 See merge request !9009
parents
2fb3fcf0
d52ef5ef
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
5 deletions
+101
-5
branches_controller.rb
app/controllers/projects/branches_controller.rb
+26
-4
projects_helper.rb
app/helpers/projects_helper.rb
+9
-0
create_branch_service.rb
app/services/create_branch_service.rb
+14
-0
create_branch_repo_less.yml
changelogs/unreleased/create_branch_repo_less.yml
+4
-0
branches_controller_spec.rb
spec/controllers/projects/branches_controller_spec.rb
+38
-1
services.rb
spec/factories/services.rb
+10
-0
No files found.
app/controllers/projects/branches_controller.rb
View file @
c5b29ed6
class
Projects
::
BranchesController
<
Projects
::
ApplicationController
include
ActionView
::
Helpers
::
SanitizeHelper
include
SortingHelper
# Authorize
before_action
:require_non_empty_project
before_action
:require_non_empty_project
,
except: :create
before_action
:authorize_download_code!
before_action
:authorize_push_code!
,
only:
[
:new
,
:create
,
:destroy
,
:destroy_all_merged
]
...
...
@@ -32,6 +33,8 @@ class Projects::BranchesController < Projects::ApplicationController
branch_name
=
sanitize
(
strip_tags
(
params
[
:branch_name
]))
branch_name
=
Addressable
::
URI
.
unescape
(
branch_name
)
redirect_to_autodeploy
=
project
.
empty_repo?
&&
project
.
deployment_services
.
present?
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
branch_name
,
ref
)
...
...
@@ -42,8 +45,15 @@ class Projects::BranchesController < Projects::ApplicationController
if
result
[
:status
]
==
:success
@branch
=
result
[
:branch
]
redirect_to
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@branch
.
name
)
if
redirect_to_autodeploy
redirect_to
(
url_to_autodeploy_setup
(
project
,
branch_name
),
notice:
view_context
.
autodeploy_flash_notice
(
branch_name
))
else
redirect_to
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@branch
.
name
)
end
else
@error
=
result
[
:message
]
render
action:
'new'
...
...
@@ -76,7 +86,19 @@ class Projects::BranchesController < Projects::ApplicationController
ref_escaped
=
sanitize
(
strip_tags
(
params
[
:ref
]))
Addressable
::
URI
.
unescape
(
ref_escaped
)
else
@project
.
default_branch
@project
.
default_branch
||
'master'
end
end
def
url_to_autodeploy_setup
(
project
,
branch_name
)
namespace_project_new_blob_path
(
project
.
namespace
,
project
,
branch_name
,
file_name:
'.gitlab-ci.yml'
,
commit_message:
'Set up auto deploy'
,
target_branch:
branch_name
,
context:
'autodeploy'
)
end
end
app/helpers/projects_helper.rb
View file @
c5b29ed6
...
...
@@ -150,6 +150,15 @@ module ProjectsHelper
).
html_safe
end
def
link_to_autodeploy_doc
link_to
'About auto deploy'
,
help_page_path
(
'ci/autodeploy/index'
),
target:
'_blank'
end
def
autodeploy_flash_notice
(
branch_name
)
"Branch <strong>
#{
truncate
(
sanitize
(
branch_name
))
}
</strong> was created. To set up auto deploy, \
choose a GitLab CI Yaml template and commit your changes.
#{
link_to_autodeploy_doc
}
"
.
html_safe
end
private
def
repo_children_classes
(
field
)
...
...
app/services/create_branch_service.rb
View file @
c5b29ed6
class
CreateBranchService
<
BaseService
def
execute
(
branch_name
,
ref
)
create_master_branch
if
project
.
empty_repo?
result
=
ValidateNewBranchService
.
new
(
project
,
current_user
)
.
execute
(
branch_name
)
...
...
@@ -19,4 +21,16 @@ class CreateBranchService < BaseService
def
success
(
branch
)
super
().
merge
(
branch:
branch
)
end
private
def
create_master_branch
project
.
repository
.
commit_file
(
current_user
,
'/README.md'
,
''
,
message:
'Add README.md'
,
branch_name:
'master'
,
update:
false
)
end
end
changelogs/unreleased/create_branch_repo_less.yml
0 → 100644
View file @
c5b29ed6
---
title
:
Creating a new branch from an issue will automatically initialize a repository if one doesn't already exist.
merge_request
:
author
:
spec/controllers/projects/branches_controller_spec.rb
View file @
c5b29ed6
...
...
@@ -68,7 +68,7 @@ describe Projects::BranchesController do
describe
"created from the new branch button on issues"
do
let
(
:branch
)
{
"1-feature-branch"
}
let
!
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
before
do
sign_in
(
user
)
...
...
@@ -95,6 +95,43 @@ describe Projects::BranchesController do
issue_iid:
issue
.
iid
end
context
'repository-less project'
do
let
(
:project
)
{
create
:empty_project
}
it
'redirects to newly created branch'
do
result
=
{
status: :success
,
branch:
double
(
name:
branch
)
}
expect_any_instance_of
(
CreateBranchService
).
to
receive
(
:execute
).
and_return
(
result
)
expect
(
SystemNoteService
).
to
receive
(
:new_issue_branch
).
and_return
(
true
)
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
branch_name:
branch
,
issue_iid:
issue
.
iid
expect
(
response
).
to
redirect_to
namespace_project_tree_path
(
project
.
namespace
,
project
,
branch
)
end
it
'redirects to autodeploy setup page'
do
result
=
{
status: :success
,
branch:
double
(
name:
branch
)
}
project
.
services
<<
build
(
:kubernetes_service
)
expect_any_instance_of
(
CreateBranchService
).
to
receive
(
:execute
).
and_return
(
result
)
expect
(
SystemNoteService
).
to
receive
(
:new_issue_branch
).
and_return
(
true
)
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
branch_name:
branch
,
issue_iid:
issue
.
iid
expect
(
response
.
location
).
to
include
(
namespace_project_new_blob_path
(
project
.
namespace
,
project
,
branch
))
expect
(
response
).
to
have_http_status
(
302
)
end
end
context
'without issue feature access'
do
before
do
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
...
...
spec/factories/services.rb
View file @
c5b29ed6
...
...
@@ -2,4 +2,14 @@ FactoryGirl.define do
factory
:service
do
project
factory: :empty_project
end
factory
:kubernetes_service
do
project
factory: :empty_project
active
true
properties
({
namespace:
'somepath'
,
api_url:
'https://kubernetes.example.com'
,
token:
'a'
*
40
,
})
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