Commit c98c7465 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'jejacks0n/experiment/new_project_sast_enabled_cleanup' into 'master'

Add ability to enable SAST at project creation

See merge request gitlab-org/gitlab!83138
parents a456f0cb d29a2e9b
......@@ -82,13 +82,6 @@ class ProjectsController < Projects::ApplicationController
@project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute
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(
project_path(@project, custom_import_params),
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 @@
.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.')
- experiment(:new_project_sast_enabled, user: current_user) do |e|
- e.variant(:candidate) do
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: true, with_free_badge: false
- e.variant(:unchecked_candidate) do
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: false, with_free_badge: false
- e.variant(:free_indicator) do
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: true, with_free_badge: true
- e.variant(:unchecked_free_indicator) do
= render 'new_project_initialize_with_sast', experiment_name: e.name, track_label: track_label, checked: false, with_free_badge: true
.form-group
.form-check.gl-mb-3
= 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' }
= label_tag 'project[initialize_with_sast]', class: 'form-check-label' do
= s_('ProjectsNew|Enable Static Application Security Testing (SAST)')
.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' }
= 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: "" }
- 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
......@@ -16146,9 +16146,6 @@ msgstr ""
msgid "Framework successfully deleted"
msgstr ""
msgid "Free"
msgstr ""
msgid "Free Trial of GitLab.com Ultimate"
msgstr ""
......
......@@ -13,6 +13,7 @@ module QA
view 'app/views/projects/_new_project_fields.html.haml' do
element :initialize_with_readme_checkbox
element :initialize_with_sast_checkbox
element :project_name
element :project_path
element :project_description
......@@ -20,10 +21,6 @@ module QA
element :visibility_radios
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
element :use_template_button
element :template_option_row
......
......@@ -473,28 +473,6 @@ RSpec.describe ProjectsController do
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
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 @@ RSpec.describe 'User creates a project', :js do
end
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)
click_link 'Create blank project'
......
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