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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
8d9d0f40
Commit
8d9d0f40
authored
Apr 07, 2022
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ios_specific_templates experiment yaml and experiment class
Used for the ios_specific_templates experiment
parent
4f6be856
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
147 additions
and
0 deletions
+147
-0
app/experiments/ios_specific_templates_experiment.rb
app/experiments/ios_specific_templates_experiment.rb
+30
-0
app/helpers/ci/pipelines_helper.rb
app/helpers/ci/pipelines_helper.rb
+6
-0
config/feature_flags/experiment/ios_specific_templates.yml
config/feature_flags/experiment/ios_specific_templates.yml
+8
-0
spec/experiments/ios_specific_templates_experiment_spec.rb
spec/experiments/ios_specific_templates_experiment_spec.rb
+62
-0
spec/helpers/ci/pipelines_helper_spec.rb
spec/helpers/ci/pipelines_helper_spec.rb
+41
-0
No files found.
app/experiments/ios_specific_templates_experiment.rb
0 → 100644
View file @
8d9d0f40
# frozen_string_literal: true
class
IosSpecificTemplatesExperiment
<
ApplicationExperiment
before_run
(
if: :skip_experiment
)
{
throw
(
:abort
)
}
# rubocop:disable Cop/BanCatchThrow
private
def
skip_experiment
actor_not_able_to_create_pipelines?
||
project_targets_non_ios_platforms?
||
project_has_gitlab_ci?
||
project_has_pipelines?
end
def
actor_not_able_to_create_pipelines?
!
context
.
actor
.
is_a?
(
User
)
||
!
context
.
actor
.
can?
(
:create_pipeline
,
context
.
project
)
end
def
project_targets_non_ios_platforms?
context
.
project
.
project_setting
.
target_platforms
.
exclude?
(
'ios'
)
end
def
project_has_gitlab_ci?
context
.
project
.
has_ci?
&&
context
.
project
.
builds_enabled?
end
def
project_has_pipelines?
context
.
project
.
all_pipelines
.
count
>
0
end
end
app/helpers/ci/pipelines_helper.rb
View file @
8d9d0f40
...
...
@@ -106,6 +106,12 @@ module Ci
e
.
candidate
{
data
[
:any_runners_available
]
=
project
.
active_runners
.
exists?
.
to_s
}
end
experiment
(
:ios_specific_templates
,
actor:
current_user
,
project:
project
,
sticky_to:
project
)
do
|
e
|
e
.
candidate
do
data
[
:registration_token
]
=
project
.
runners_token
if
can?
(
current_user
,
:register_project_runners
,
project
)
end
end
data
end
...
...
config/feature_flags/experiment/ios_specific_templates.yml
0 → 100644
View file @
8d9d0f40
---
name
:
ios_specific_templates
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84589
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/356398
milestone
:
"
14.10"
type
:
experiment
group
:
group::activation
default_enabled
:
false
spec/experiments/ios_specific_templates_experiment_spec.rb
0 → 100644
View file @
8d9d0f40
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
IosSpecificTemplatesExperiment
do
subject
do
described_class
.
new
(
actor:
user
,
project:
project
)
do
|
e
|
e
.
candidate
{
true
}
end
.
run
end
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:auto_devops_disabled
)
}
let!
(
:project_setting
)
{
create
(
:project_setting
,
project:
project
,
target_platforms:
target_platforms
)
}
let
(
:target_platforms
)
{
%w(ios)
}
before
do
stub_experiments
(
ios_specific_templates: :candidate
)
project
.
add_developer
(
user
)
if
user
end
it
{
is_expected
.
to
be
true
}
describe
'skipping the experiment'
do
context
'no actor'
do
let_it_be
(
:user
)
{
nil
}
it
{
is_expected
.
to
be_falsey
}
end
context
'actor cannot create pipelines'
do
before
do
project
.
add_guest
(
user
)
end
it
{
is_expected
.
to
be_falsey
}
end
context
'targeting a non iOS platform'
do
let
(
:target_platforms
)
{
[]
}
it
{
is_expected
.
to
be_falsey
}
end
context
'project has a ci.yaml file'
do
before
do
allow
(
project
).
to
receive
(
:has_ci?
).
and_return
(
true
)
end
it
{
is_expected
.
to
be_falsey
}
end
context
'project has pipelines'
do
before
do
create
(
:ci_pipeline
,
project:
project
)
end
it
{
is_expected
.
to
be_falsey
}
end
end
end
spec/helpers/ci/pipelines_helper_spec.rb
View file @
8d9d0f40
...
...
@@ -151,5 +151,46 @@ RSpec.describe Ci::PipelinesHelper do
end
end
end
describe
'the `registration_token` attribute'
do
subject
{
data
[
:registration_token
]
}
describe
'when the project is eligible for the `ios_specific_templates` experiment'
do
let_it_be
(
:project
)
{
create
(
:project
,
:auto_devops_disabled
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
helper
).
to
receive
(
:current_user
).
and_return
(
user
)
project
.
add_developer
(
user
)
create
(
:project_setting
,
project:
project
,
target_platforms:
%w(ios)
)
end
context
'when the `ios_specific_templates` experiment variant is control'
do
before
do
stub_experiments
(
ios_specific_templates: :control
)
end
it
{
is_expected
.
to
be_nil
}
end
context
'when the `ios_specific_templates` experiment variant is candidate'
do
before
do
stub_experiments
(
ios_specific_templates: :candidate
)
end
context
'when the user cannot register project runners'
do
before
do
allow
(
helper
).
to
receive
(
:can?
).
with
(
user
,
:register_project_runners
,
project
).
and_return
(
false
)
end
it
{
is_expected
.
to
be_nil
}
end
context
'when the user can register project runners'
do
it
{
is_expected
.
to
eq
(
project
.
runners_token
)
}
end
end
end
end
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