BigW Consortium Gitlab

Commit d52ef5ef by Valery Sizov

Fixes after review

parent ef27b4be
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, except: :create before_action :require_non_empty_project, except: :create
...@@ -34,7 +33,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -34,7 +33,7 @@ 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? redirect_to_autodeploy = 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)
...@@ -47,11 +46,10 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -47,11 +46,10 @@ 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 if redirect_to_autodeploy
redirect_to( redirect_to(
url_to_autodeploy_setup(project, branch_name), url_to_autodeploy_setup(project, branch_name),
notice: "Branch \"#{sanitize(branch_name)}\" was created. To set up auto deploy, \ notice: view_context.autodeploy_flash_notice(branch_name))
choose a GitLab CI Yaml template and commit your changes. #{view_context.link_to_autodeploy_doc}".html_safe)
else else
redirect_to namespace_project_tree_path(@project.namespace, @project, redirect_to namespace_project_tree_path(@project.namespace, @project,
@branch.name) @branch.name)
...@@ -91,4 +89,16 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -91,4 +89,16 @@ class Projects::BranchesController < Projects::ApplicationController
@project.default_branch || 'master' @project.default_branch || 'master'
end end
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 end
...@@ -154,6 +154,11 @@ module ProjectsHelper ...@@ -154,6 +154,11 @@ module ProjectsHelper
link_to 'About auto deploy', help_page_path('ci/autodeploy/index'), target: '_blank' link_to 'About auto deploy', help_page_path('ci/autodeploy/index'), target: '_blank'
end 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 private
def repo_children_classes(field) def repo_children_classes(field)
...@@ -272,18 +277,6 @@ module ProjectsHelper ...@@ -272,18 +277,6 @@ 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,
......
--- ---
title: Create new branch from issue for repo-less project using new branch button title: Creating a new branch from an issue will automatically initialize a repository if one doesn't already exist.
merge_request: merge_request:
author: author:
...@@ -116,14 +116,7 @@ describe Projects::BranchesController do ...@@ -116,14 +116,7 @@ describe Projects::BranchesController do
it 'redirects to autodeploy setup page' do it 'redirects to autodeploy setup page' do
result = { status: :success, branch: double(name: branch) } result = { status: :success, branch: double(name: branch) }
project.create_kubernetes_service( project.services << build(: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_any_instance_of(CreateBranchService).to receive(:execute).and_return(result)
expect(SystemNoteService).to receive(:new_issue_branch).and_return(true) expect(SystemNoteService).to receive(:new_issue_branch).and_return(true)
...@@ -135,6 +128,7 @@ describe Projects::BranchesController do ...@@ -135,6 +128,7 @@ describe Projects::BranchesController do
issue_iid: issue.iid issue_iid: issue.iid
expect(response.location).to include(namespace_project_new_blob_path(project.namespace, project, branch)) expect(response.location).to include(namespace_project_new_blob_path(project.namespace, project, branch))
expect(response).to have_http_status(302)
end end
end end
......
...@@ -2,4 +2,14 @@ FactoryGirl.define do ...@@ -2,4 +2,14 @@ FactoryGirl.define do
factory :service do factory :service do
project factory: :empty_project project factory: :empty_project
end 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 end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment