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
adf003a9
Commit
adf003a9
authored
Feb 28, 2019
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix inconsistent `branch?` behavior
between Ci::Pipeline and Ci::Build Add spec Add more tests ok
parent
c994484d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
5 deletions
+146
-5
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+0
-4
app/models/concerns/has_ref.rb
app/models/concerns/has_ref.rb
+1
-1
spec/factories/merge_requests.rb
spec/factories/merge_requests.rb
+9
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+116
-0
spec/models/concerns/has_ref_spec.rb
spec/models/concerns/has_ref_spec.rb
+20
-0
No files found.
app/models/ci/pipeline.rb
View file @
adf003a9
...
...
@@ -417,10 +417,6 @@ module Ci
@commit
||=
Commit
.
lazy
(
project
,
sha
)
end
def
branch?
super
&&
!
merge_request?
end
def
stuck?
pending_builds
.
any?
(
&
:stuck?
)
end
...
...
app/models/concerns/has_ref.rb
View file @
adf003a9
...
...
@@ -4,7 +4,7 @@ module HasRef
extend
ActiveSupport
::
Concern
def
branch?
!
tag?
!
tag?
&&
!
merge_request?
end
def
git_ref
...
...
spec/factories/merge_requests.rb
View file @
adf003a9
...
...
@@ -101,6 +101,15 @@ FactoryBot.define do
end
end
trait
:with_merge_request_pipeline
do
after
(
:build
)
do
|
merge_request
|
merge_request
.
merge_request_pipelines
<<
build
(
:ci_pipeline
,
source: :merge_request
,
merge_request:
merge_request
,
project:
merge_request
.
source_project
)
end
end
trait
:deployed_review_app
do
target_branch
'pages-deploy-target'
...
...
spec/models/ci/build_spec.rb
View file @
adf003a9
...
...
@@ -2734,6 +2734,122 @@ describe Ci::Build do
end
end
describe
'#secret_group_variables'
do
subject
{
build
.
secret_group_variables
}
let!
(
:variable
)
{
create
(
:ci_group_variable
,
protected:
true
,
group:
group
)
}
context
'when ref is branch'
do
let
(
:build
)
{
create
(
:ci_build
,
ref:
'master'
,
tag:
false
,
project:
project
)
}
context
'when ref is protected'
do
before
do
create
(
:protected_branch
,
:developers_can_merge
,
name:
'master'
,
project:
project
)
end
it
{
is_expected
.
to
include
(
variable
)
}
end
context
'when ref is not protected'
do
it
{
is_expected
.
not_to
include
(
variable
)
}
end
end
context
'when ref is tag'
do
let
(
:build
)
{
create
(
:ci_build
,
ref:
'v1.1.0'
,
tag:
true
,
project:
project
)
}
context
'when ref is protected'
do
before
do
create
(
:protected_tag
,
project:
project
,
name:
'v*'
)
end
it
{
is_expected
.
to
include
(
variable
)
}
end
context
'when ref is not protected'
do
it
{
is_expected
.
not_to
include
(
variable
)
}
end
end
context
'when ref is merge request'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
:with_merge_request_pipeline
)
}
let
(
:pipeline
)
{
merge_request
.
merge_request_pipelines
.
first
}
let
(
:build
)
{
create
(
:ci_build
,
ref:
merge_request
.
source_branch
,
tag:
false
,
pipeline:
pipeline
,
project:
project
)
}
context
'when ref is protected'
do
before
do
create
(
:protected_branch
,
:developers_can_merge
,
name:
merge_request
.
source_branch
,
project:
project
)
end
it
'does not return protected variables as it is not supported for merge request pipelines'
do
is_expected
.
not_to
include
(
variable
)
end
end
context
'when ref is not protected'
do
it
{
is_expected
.
not_to
include
(
variable
)
}
end
end
end
describe
'#secret_project_variables'
do
subject
{
build
.
secret_project_variables
}
let!
(
:variable
)
{
create
(
:ci_variable
,
protected:
true
,
project:
project
)
}
context
'when ref is branch'
do
let
(
:build
)
{
create
(
:ci_build
,
ref:
'master'
,
tag:
false
,
project:
project
)
}
context
'when ref is protected'
do
before
do
create
(
:protected_branch
,
:developers_can_merge
,
name:
'master'
,
project:
project
)
end
it
{
is_expected
.
to
include
(
variable
)
}
end
context
'when ref is not protected'
do
it
{
is_expected
.
not_to
include
(
variable
)
}
end
end
context
'when ref is tag'
do
let
(
:build
)
{
create
(
:ci_build
,
ref:
'v1.1.0'
,
tag:
true
,
project:
project
)
}
context
'when ref is protected'
do
before
do
create
(
:protected_tag
,
project:
project
,
name:
'v*'
)
end
it
{
is_expected
.
to
include
(
variable
)
}
end
context
'when ref is not protected'
do
it
{
is_expected
.
not_to
include
(
variable
)
}
end
end
context
'when ref is merge request'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
:with_merge_request_pipeline
)
}
let
(
:pipeline
)
{
merge_request
.
merge_request_pipelines
.
first
}
let
(
:build
)
{
create
(
:ci_build
,
ref:
merge_request
.
source_branch
,
tag:
false
,
pipeline:
pipeline
,
project:
project
)
}
context
'when ref is protected'
do
before
do
create
(
:protected_branch
,
:developers_can_merge
,
name:
merge_request
.
source_branch
,
project:
project
)
end
it
'does not return protected variables as it is not supported for merge request pipelines'
do
is_expected
.
not_to
include
(
variable
)
end
end
context
'when ref is not protected'
do
it
{
is_expected
.
not_to
include
(
variable
)
}
end
end
end
describe
'#scoped_variables_hash'
do
context
'when overriding CI variables'
do
before
do
...
...
spec/models/concerns/has_ref_spec.rb
View file @
adf003a9
...
...
@@ -16,6 +16,16 @@ describe HasRef do
it
'return true when tag is set to false'
do
is_expected
.
to
be_truthy
end
context
'when it was triggered by merge request'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
:with_merge_request_pipeline
)
}
let
(
:pipeline
)
{
merge_request
.
merge_request_pipelines
.
first
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
it
'returns false'
do
is_expected
.
to
be_falsy
end
end
end
context
'is not a tag'
do
...
...
@@ -55,5 +65,15 @@ describe HasRef do
is_expected
.
to
start_with
(
Gitlab
::
Git
::
BRANCH_REF_PREFIX
)
end
end
context
'when it is triggered by a merge request'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
:with_merge_request_pipeline
)
}
let
(
:pipeline
)
{
merge_request
.
merge_request_pipelines
.
first
}
let
(
:build
)
{
create
(
:ci_build
,
tag:
false
,
pipeline:
pipeline
)
}
it
'returns nil'
do
is_expected
.
to
be_nil
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