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
08e4d98c
Commit
08e4d98c
authored
Feb 06, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create master branch first if project is repository-less
parent
319dfd68
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
5 deletions
+90
-5
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+16
-4
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+16
-0
app/services/create_branch_service.rb
app/services/create_branch_service.rb
+14
-0
spec/controllers/projects/branches_controller_spec.rb
spec/controllers/projects/branches_controller_spec.rb
+44
-1
No files found.
app/controllers/projects/branches_controller.rb
View file @
08e4d98c
class
Projects::BranchesController
<
Projects
::
ApplicationController
class
Projects::BranchesController
<
Projects
::
ApplicationController
include
ActionView
::
Helpers
::
SanitizeHelper
include
ActionView
::
Helpers
::
SanitizeHelper
include
SortingHelper
include
SortingHelper
include
ProjectsHelper
# Authorize
# Authorize
before_action
:require_non_empty_project
before_action
:require_non_empty_project
,
except: :create
before_action
:authorize_download_code!
before_action
:authorize_download_code!
before_action
:authorize_push_code!
,
only:
[
:new
,
:create
,
:destroy
,
:destroy_all_merged
]
before_action
:authorize_push_code!
,
only:
[
:new
,
:create
,
:destroy
,
:destroy_all_merged
]
...
@@ -32,6 +34,8 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -32,6 +34,8 @@ class Projects::BranchesController < Projects::ApplicationController
branch_name
=
sanitize
(
strip_tags
(
params
[
:branch_name
]))
branch_name
=
sanitize
(
strip_tags
(
params
[
:branch_name
]))
branch_name
=
Addressable
::
URI
.
unescape
(
branch_name
)
branch_name
=
Addressable
::
URI
.
unescape
(
branch_name
)
is_redirect_to_autodeploy_needed
=
project
.
empty_repo?
&&
project
.
deployment_services
.
present?
result
=
CreateBranchService
.
new
(
project
,
current_user
).
result
=
CreateBranchService
.
new
(
project
,
current_user
).
execute
(
branch_name
,
ref
)
execute
(
branch_name
,
ref
)
...
@@ -42,8 +46,16 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -42,8 +46,16 @@ class Projects::BranchesController < Projects::ApplicationController
if
result
[
:status
]
==
:success
if
result
[
:status
]
==
:success
@branch
=
result
[
:branch
]
@branch
=
result
[
:branch
]
if
is_redirect_to_autodeploy_needed
redirect_to
(
url_to_autodeploy_setup
(
project
,
branch_name
),
notice:
"Branch
\"
#{
sanitize
(
branch_name
)
}
\"
was created. To set up auto deploy, \
choose a GitLab CI Yaml template and commit your changes.
#{
view_context
.
link_to_autodeploy_doc
}
"
.
html_safe
)
else
redirect_to
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
redirect_to
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
@branch
.
name
)
@branch
.
name
)
end
else
else
@error
=
result
[
:message
]
@error
=
result
[
:message
]
render
action:
'new'
render
action:
'new'
...
@@ -76,7 +88,7 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -76,7 +88,7 @@ class Projects::BranchesController < Projects::ApplicationController
ref_escaped
=
sanitize
(
strip_tags
(
params
[
:ref
]))
ref_escaped
=
sanitize
(
strip_tags
(
params
[
:ref
]))
Addressable
::
URI
.
unescape
(
ref_escaped
)
Addressable
::
URI
.
unescape
(
ref_escaped
)
else
else
@project
.
default_branch
@project
.
default_branch
||
'master'
end
end
end
end
end
end
app/helpers/projects_helper.rb
View file @
08e4d98c
...
@@ -150,6 +150,10 @@ module ProjectsHelper
...
@@ -150,6 +150,10 @@ module ProjectsHelper
).
html_safe
).
html_safe
end
end
def
link_to_autodeploy_doc
link_to
'About auto deploy'
,
help_page_path
(
'ci/autodeploy/index'
),
target:
'_blank'
end
private
private
def
repo_children_classes
(
field
)
def
repo_children_classes
(
field
)
...
@@ -268,6 +272,18 @@ module ProjectsHelper
...
@@ -268,6 +272,18 @@ module ProjectsHelper
)
)
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
def
add_koding_stack_path
(
project
)
def
add_koding_stack_path
(
project
)
namespace_project_new_blob_path
(
namespace_project_new_blob_path
(
project
.
namespace
,
project
.
namespace
,
...
...
app/services/create_branch_service.rb
View file @
08e4d98c
class
CreateBranchService
<
BaseService
class
CreateBranchService
<
BaseService
def
execute
(
branch_name
,
ref
)
def
execute
(
branch_name
,
ref
)
create_master_branch
if
project
.
empty_repo?
result
=
ValidateNewBranchService
.
new
(
project
,
current_user
)
result
=
ValidateNewBranchService
.
new
(
project
,
current_user
)
.
execute
(
branch_name
)
.
execute
(
branch_name
)
...
@@ -19,4 +21,16 @@ class CreateBranchService < BaseService
...
@@ -19,4 +21,16 @@ class CreateBranchService < BaseService
def
success
(
branch
)
def
success
(
branch
)
super
().
merge
(
branch:
branch
)
super
().
merge
(
branch:
branch
)
end
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
end
spec/controllers/projects/branches_controller_spec.rb
View file @
08e4d98c
...
@@ -68,7 +68,7 @@ describe Projects::BranchesController do
...
@@ -68,7 +68,7 @@ describe Projects::BranchesController do
describe
"created from the new branch button on issues"
do
describe
"created from the new branch button on issues"
do
let
(
:branch
)
{
"1-feature-branch"
}
let
(
:branch
)
{
"1-feature-branch"
}
let
!
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
...
@@ -95,6 +95,49 @@ describe Projects::BranchesController do
...
@@ -95,6 +95,49 @@ describe Projects::BranchesController do
issue_iid:
issue
.
iid
issue_iid:
issue
.
iid
end
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
.
create_kubernetes_service
(
active:
true
,
properties:
{
namespace:
project
.
path
,
api_url:
'https://kubernetes.example.com'
,
token:
'a'
*
40
,
}
)
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
))
end
end
context
'without issue feature access'
do
context
'without issue feature access'
do
before
do
before
do
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
project
.
update!
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
...
...
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