Skip to content
代码片段 群组 项目
提交 d29a2e9b 编辑于 作者: jejacks0n's avatar jejacks0n 提交者: Michael Kozono
浏览文件

Add ability to enable SAST at project creation

This introduces a new checkbox on project creation, and cleans up the
new_project_sast_enabled experiment that tested the usefulness and
engagement of that checkbox.

Changelog: added
上级 372b9fe7
No related branches found
No related tags found
无相关合并请求
...@@ -82,13 +82,6 @@ def create ...@@ -82,13 +82,6 @@ def create
@project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute @project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute
if @project.saved? if @project.saved?
experiment(:new_project_sast_enabled, user: current_user).track(:created,
property: active_new_project_tab,
checked: Gitlab::Utils.to_boolean(project_params[:initialize_with_sast]),
project: @project,
namespace: @project.namespace
)
redirect_to( redirect_to(
project_path(@project, custom_import_params), project_path(@project, custom_import_params),
notice: _("Project '%{project_name}' was successfully created.") % { project_name: @project.name } notice: _("Project '%{project_name}' was successfully created.") % { project_name: @project.name }
......
# frozen_string_literal: true
class NewProjectSastEnabledExperiment < ApplicationExperiment
control { }
variant(:candidate) { }
variant(:free_indicator) { }
variant(:unchecked_candidate) { }
variant(:unchecked_free_indicator) { }
def publish(*args)
super
publish_to_database
end
end
...@@ -64,15 +64,14 @@ ...@@ -64,15 +64,14 @@
.form-text.text-muted .form-text.text-muted
= s_('ProjectsNew|Allows you to immediately clone this project’s repository. Skip this if you plan to push up an existing repository.') = s_('ProjectsNew|Allows you to immediately clone this project’s repository. Skip this if you plan to push up an existing repository.')
- experiment(:new_project_sast_enabled, user: current_user) do |e| .form-group
- e.variant(:candidate) do .form-check.gl-mb-3
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: true, with_free_badge: false = check_box_tag 'project[initialize_with_sast]', '1', false, class: 'form-check-input', data: { qa_selector: 'initialize_with_sast_checkbox', track_label: track_label, track_action: 'activate_form_input', track_property: 'init_with_sast' }
- e.variant(:unchecked_candidate) do = label_tag 'project[initialize_with_sast]', class: 'form-check-label' do
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: false, with_free_badge: false = s_('ProjectsNew|Enable Static Application Security Testing (SAST)')
- e.variant(:free_indicator) do .form-text.text-muted
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: true, with_free_badge: true = s_('ProjectsNew|Analyze your source code for known security vulnerabilities.')
- e.variant(:unchecked_free_indicator) do = link_to _('Learn more.'), help_page_path('user/application_security/sast/index'), target: '_blank', rel: 'noopener noreferrer', data: { track_action: 'followed' }
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: false, with_free_badge: true
= f.submit _('Create project'), class: "btn gl-button btn-confirm", data: { qa_selector: 'project_create_button', track_label: "#{track_label}", track_action: "click_button", track_property: "create_project", track_value: "" } = f.submit _('Create project'), class: "btn gl-button btn-confirm", data: { qa_selector: 'project_create_button', track_label: "#{track_label}", track_action: "click_button", track_property: "create_project", track_value: "" }
= link_to _('Cancel'), dashboard_projects_path, class: 'btn gl-button btn-default btn-cancel', data: { track_label: "#{track_label}", track_action: "click_button", track_property: "cancel", track_value: "" } = link_to _('Cancel'), dashboard_projects_path, class: 'btn gl-button btn-default btn-cancel', data: { track_label: "#{track_label}", track_action: "click_button", track_property: "cancel", track_value: "" }
- experiment_name = local_assigns.fetch(:experiment_name)
- track_label = local_assigns.fetch(:track_label)
- with_free_badge = local_assigns.fetch(:with_free_badge, false)
- checked = local_assigns.fetch(:checked, false)
.form-group
.form-check.gl-mb-3
= check_box_tag 'project[initialize_with_sast]', '1', checked, class: 'form-check-input', data: { qa_selector: 'initialize_with_sast_checkbox', track_experiment: experiment_name, track_label: track_label, track_action: 'activate_form_input', track_property: 'init_with_sast' }
= label_tag 'project[initialize_with_sast]', class: 'form-check-label' do
= s_('ProjectsNew|Enable Static Application Security Testing (SAST)')
- if with_free_badge
= gl_badge_tag _('Free'), variant: :info, size: :sm
.form-text.text-muted
= s_('ProjectsNew|Analyze your source code for known security vulnerabilities.')
= link_to _('Learn more.'), help_page_path('user/application_security/sast/index'), target: '_blank', rel: 'noopener noreferrer', data: { track_action: 'followed', track_experiment: experiment_name }
---
name: new_project_sast_enabled
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/70548
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/340929
milestone: '14.4'
type: experiment
group: group::adoption
default_enabled: false
...@@ -16131,9 +16131,6 @@ msgstr "" ...@@ -16131,9 +16131,6 @@ msgstr ""
msgid "Framework successfully deleted" msgid "Framework successfully deleted"
msgstr "" msgstr ""
   
msgid "Free"
msgstr ""
msgid "Free Trial of GitLab.com Ultimate" msgid "Free Trial of GitLab.com Ultimate"
msgstr "" msgstr ""
   
......
...@@ -13,6 +13,7 @@ class New < Page::Base ...@@ -13,6 +13,7 @@ class New < Page::Base
view 'app/views/projects/_new_project_fields.html.haml' do view 'app/views/projects/_new_project_fields.html.haml' do
element :initialize_with_readme_checkbox element :initialize_with_readme_checkbox
element :initialize_with_sast_checkbox
element :project_name element :project_name
element :project_path element :project_path
element :project_description element :project_description
...@@ -20,10 +21,6 @@ class New < Page::Base ...@@ -20,10 +21,6 @@ class New < Page::Base
element :visibility_radios element :visibility_radios
end end
view 'app/views/projects/_new_project_initialize_with_sast.html.haml' do
element :initialize_with_sast_checkbox
end
view 'app/views/projects/project_templates/_template.html.haml' do view 'app/views/projects/project_templates/_template.html.haml' do
element :use_template_button element :use_template_button
element :template_option_row element :template_option_row
......
...@@ -473,28 +473,6 @@ def get_show ...@@ -473,28 +473,6 @@ def get_show
end end
end end
end end
context 'with new_project_sast_enabled', :experiment do
let(:params) do
{
path: 'foo',
description: 'bar',
namespace_id: user.namespace.id,
initialize_with_sast: '1'
}
end
it 'tracks an event on project creation' do
expect(experiment(:new_project_sast_enabled)).to track(:created,
property: 'blank',
checked: true,
project: an_instance_of(Project),
namespace: user.namespace
).on_next_instance.with_context(user: user)
post :create, params: { project: params }
end
end
end end
describe 'GET edit' do describe 'GET edit' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe NewProjectSastEnabledExperiment do
it "defines the expected behaviors and variants" do
expect(subject.variant_names).to match_array([
:candidate,
:free_indicator,
:unchecked_candidate,
:unchecked_free_indicator
])
end
it "publishes to the database" do
expect(subject).to receive(:publish_to_database)
subject.publish
end
end
...@@ -33,29 +33,6 @@ ...@@ -33,29 +33,6 @@
end end
it 'creates a new project that is not blank' do it 'creates a new project that is not blank' do
stub_experiments(new_project_sast_enabled: 'candidate')
visit(new_project_path)
click_link 'Create blank project'
fill_in(:project_name, with: 'With initial commits')
expect(page).to have_checked_field 'Initialize repository with a README'
expect(page).to have_checked_field 'Enable Static Application Security Testing (SAST)'
click_button('Create project')
project = Project.last
expect(page).to have_current_path(project_path(project), ignore_query: true)
expect(page).to have_content('With initial commits')
expect(page).to have_content('Configure SAST in `.gitlab-ci.yml`, creating this file if it does not already exist')
expect(page).to have_content('README.md Initial commit')
end
it 'allows creating a new project when the new_project_sast_enabled is assigned the unchecked candidate' do
stub_experiments(new_project_sast_enabled: 'unchecked_candidate')
visit(new_project_path) visit(new_project_path)
click_link 'Create blank project' click_link 'Create blank project'
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册