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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
1bf58068
Commit
1bf58068
authored
Nov 10, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use full ref when possible to avoid ambiguity
parent
b278d886
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
8 deletions
+70
-8
app/models/ci/build.rb
app/models/ci/build.rb
+3
-2
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+2
-1
app/models/concerns/has_ref.rb
app/models/concerns/has_ref.rb
+21
-0
lib/gitlab/ci/pipeline/chain/command.rb
lib/gitlab/ci/pipeline/chain/command.rb
+1
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+8
-4
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+4
-0
spec/models/concerns/has_ref_spec.rb
spec/models/concerns/has_ref_spec.rb
+31
-0
No files found.
app/models/ci/build.rb
View file @
1bf58068
...
@@ -10,6 +10,7 @@ module Ci
...
@@ -10,6 +10,7 @@ module Ci
include
Importable
include
Importable
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Utils
::
StrongMemoize
include
Deployable
include
Deployable
include
HasRef
belongs_to
:project
,
inverse_of: :builds
belongs_to
:project
,
inverse_of: :builds
belongs_to
:runner
belongs_to
:runner
...
@@ -640,11 +641,11 @@ module Ci
...
@@ -640,11 +641,11 @@ module Ci
def
secret_group_variables
def
secret_group_variables
return
[]
unless
project
.
group
return
[]
unless
project
.
group
project
.
group
.
ci_variables_for
(
ref
,
project
)
project
.
group
.
ci_variables_for
(
git_
ref
,
project
)
end
end
def
secret_project_variables
(
environment:
persisted_environment
)
def
secret_project_variables
(
environment:
persisted_environment
)
project
.
ci_variables_for
(
ref:
ref
,
environment:
environment
)
project
.
ci_variables_for
(
ref:
git_
ref
,
environment:
environment
)
end
end
def
steps
def
steps
...
...
app/models/ci/pipeline.rb
View file @
1bf58068
...
@@ -11,6 +11,7 @@ module Ci
...
@@ -11,6 +11,7 @@ module Ci
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Utils
::
StrongMemoize
include
AtomicInternalId
include
AtomicInternalId
include
EnumWithNil
include
EnumWithNil
include
HasRef
belongs_to
:project
,
inverse_of: :all_pipelines
belongs_to
:project
,
inverse_of: :all_pipelines
belongs_to
:user
belongs_to
:user
...
@@ -588,7 +589,7 @@ module Ci
...
@@ -588,7 +589,7 @@ module Ci
end
end
def
protected_ref?
def
protected_ref?
strong_memoize
(
:protected_ref
)
{
project
.
protected_for?
(
ref
)
}
strong_memoize
(
:protected_ref
)
{
project
.
protected_for?
(
git_
ref
)
}
end
end
def
legacy_trigger
def
legacy_trigger
...
...
app/models/concerns/has_ref.rb
0 → 100644
View file @
1bf58068
# frozen_string_literal: true
module
HasRef
extend
ActiveSupport
::
Concern
def
branch?
!
tag?
end
private
def
git_ref
if
branch?
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
.
to_s
elsif
tag?
Gitlab
::
Git
::
TAG_REF_PREFIX
+
ref
.
to_s
else
raise
ArgumentError
,
'Invalid pipeline type!'
end
end
end
lib/gitlab/ci/pipeline/chain/command.rb
View file @
1bf58068
...
@@ -54,7 +54,7 @@ module Gitlab
...
@@ -54,7 +54,7 @@ module Gitlab
def
protected_ref?
def
protected_ref?
strong_memoize
(
:protected_ref
)
do
strong_memoize
(
:protected_ref
)
do
project
.
protected_for?
(
ref
)
project
.
protected_for?
(
origin_
ref
)
end
end
end
end
end
end
...
...
spec/models/ci/build_spec.rb
View file @
1bf58068
...
@@ -2385,6 +2385,8 @@ describe Ci::Build do
...
@@ -2385,6 +2385,8 @@ describe Ci::Build do
end
end
context
'when protected variable is defined'
do
context
'when protected variable is defined'
do
let
(
:ref
)
{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
build
.
ref
}
let
(
:protected_variable
)
do
let
(
:protected_variable
)
do
{
key:
'PROTECTED_KEY'
,
value:
'protected_value'
,
public:
false
}
{
key:
'PROTECTED_KEY'
,
value:
'protected_value'
,
public:
false
}
end
end
...
@@ -2397,7 +2399,7 @@ describe Ci::Build do
...
@@ -2397,7 +2399,7 @@ describe Ci::Build do
context
'when the branch is protected'
do
context
'when the branch is protected'
do
before
do
before
do
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
build
.
ref
).
and_return
(
true
)
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
ref
).
and_return
(
true
)
end
end
it
{
is_expected
.
to
include
(
protected_variable
)
}
it
{
is_expected
.
to
include
(
protected_variable
)
}
...
@@ -2405,7 +2407,7 @@ describe Ci::Build do
...
@@ -2405,7 +2407,7 @@ describe Ci::Build do
context
'when the tag is protected'
do
context
'when the tag is protected'
do
before
do
before
do
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
build
.
ref
).
and_return
(
true
)
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
ref
).
and_return
(
true
)
end
end
it
{
is_expected
.
to
include
(
protected_variable
)
}
it
{
is_expected
.
to
include
(
protected_variable
)
}
...
@@ -2430,6 +2432,8 @@ describe Ci::Build do
...
@@ -2430,6 +2432,8 @@ describe Ci::Build do
end
end
context
'when group protected variable is defined'
do
context
'when group protected variable is defined'
do
let
(
:ref
)
{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
build
.
ref
}
let
(
:protected_variable
)
do
let
(
:protected_variable
)
do
{
key:
'PROTECTED_KEY'
,
value:
'protected_value'
,
public:
false
}
{
key:
'PROTECTED_KEY'
,
value:
'protected_value'
,
public:
false
}
end
end
...
@@ -2442,7 +2446,7 @@ describe Ci::Build do
...
@@ -2442,7 +2446,7 @@ describe Ci::Build do
context
'when the branch is protected'
do
context
'when the branch is protected'
do
before
do
before
do
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
build
.
ref
).
and_return
(
true
)
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
ref
).
and_return
(
true
)
end
end
it
{
is_expected
.
to
include
(
protected_variable
)
}
it
{
is_expected
.
to
include
(
protected_variable
)
}
...
@@ -2450,7 +2454,7 @@ describe Ci::Build do
...
@@ -2450,7 +2454,7 @@ describe Ci::Build do
context
'when the tag is protected'
do
context
'when the tag is protected'
do
before
do
before
do
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
build
.
ref
).
and_return
(
true
)
allow
(
build
.
project
).
to
receive
(
:protected_for?
).
with
(
ref
).
and_return
(
true
)
end
end
it
{
is_expected
.
to
include
(
protected_variable
)
}
it
{
is_expected
.
to
include
(
protected_variable
)
}
...
...
spec/models/ci/pipeline_spec.rb
View file @
1bf58068
...
@@ -397,6 +397,10 @@ describe Ci::Pipeline, :mailer do
...
@@ -397,6 +397,10 @@ describe Ci::Pipeline, :mailer do
end
end
describe
'#protected_ref?'
do
describe
'#protected_ref?'
do
before
do
pipeline
.
project
=
create
(
:project
,
:repository
)
end
it
'delegates method to project'
do
it
'delegates method to project'
do
expect
(
pipeline
).
not_to
be_protected_ref
expect
(
pipeline
).
not_to
be_protected_ref
end
end
...
...
spec/models/concerns/has_ref_spec.rb
0 → 100644
View file @
1bf58068
# frozen_string_literal: true
require
'spec_helper'
describe
HasRef
do
describe
'#branch?'
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
subject
{
pipeline
.
branch?
}
context
'is not a tag'
do
before
do
pipeline
.
tag
=
false
end
it
'return true when tag is set to false'
do
is_expected
.
to
be_truthy
end
end
context
'is not a tag'
do
before
do
pipeline
.
tag
=
true
end
it
'return false when tag is set to true'
do
is_expected
.
to
be_falsey
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