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
0f78ceca
Commit
0f78ceca
authored
Oct 02, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add only/except pipeline build policy for `changes`
parent
740ee583
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
0 deletions
+90
-0
lib/gitlab/ci/build/policy/changes.rb
lib/gitlab/ci/build/policy/changes.rb
+21
-0
spec/lib/gitlab/ci/build/policy/changes_spec.rb
spec/lib/gitlab/ci/build/policy/changes_spec.rb
+69
-0
No files found.
lib/gitlab/ci/build/policy/changes.rb
0 → 100644
View file @
0f78ceca
module
Gitlab
module
Ci
module
Build
module
Policy
class
Changes
<
Policy
::
Specification
def
initialize
(
globs
)
@globs
=
Array
(
globs
)
end
def
satisfied_by?
(
pipeline
,
seed
)
return
true
unless
pipeline
.
branch_updated?
pipeline
.
modified_paths
.
any?
do
|
path
|
@globs
.
any?
{
|
glob
|
File
.
fnmatch?
(
glob
,
path
,
File
::
FNM_PATHNAME
)
}
end
end
end
end
end
end
end
spec/lib/gitlab/ci/build/policy/changes_spec.rb
0 → 100644
View file @
0f78ceca
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Policy
::
Changes
do
set
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
do
build
(
:ci_empty_pipeline
,
project:
project
,
ref:
'master'
,
source: :push
,
sha:
'1234abcd'
,
before_sha:
'0123aabb'
)
end
let
(
:ci_build
)
do
build
(
:ci_build
,
pipeline:
pipeline
,
project:
project
,
ref:
'master'
)
end
let
(
:seed
)
{
double
(
'build seed'
,
to_resource:
ci_build
)
}
before
do
allow
(
pipeline
).
to
receive
(
:modified_paths
)
do
%w[some/modified/ruby/file.rb some/other_file.txt]
end
end
describe
'#satisfied_by?'
do
it
'is satisfied by matching literal path'
do
policy
=
described_class
.
new
(
%w[some/other_file.txt]
)
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
seed
)
end
it
'is satisfied by matching simple pattern'
do
policy
=
described_class
.
new
(
%w[some/*.txt]
)
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
seed
)
end
it
'is satisfied by matching recusive pattern'
do
policy
=
described_class
.
new
(
%w[some/**/*.rb]
)
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
seed
)
end
it
'is not satisfied when pattern does not match path'
do
policy
=
described_class
.
new
(
%w[some/*.rb]
)
expect
(
policy
).
not_to
be_satisfied_by
(
pipeline
,
seed
)
end
it
'is not satisfied when pattern does not match'
do
policy
=
described_class
.
new
(
%w[invalid/*.md]
)
expect
(
policy
).
not_to
be_satisfied_by
(
pipeline
,
seed
)
end
context
'when pipelines does not run for a branch update'
do
before
do
pipeline
.
before_sha
=
Gitlab
::
Git
::
BLANK_SHA
end
it
'is always satisfied'
do
policy
=
described_class
.
new
(
%w[invalid/*]
)
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
seed
)
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