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
Boxiang Sun
gitlab-ce
Commits
82ed2a09
Commit
82ed2a09
authored
Sep 06, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve config source handling code
parent
8189347b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
21 deletions
+33
-21
app/models/ci/build.rb
app/models/ci/build.rb
+1
-0
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+10
-9
app/models/project.rb
app/models/project.rb
+7
-7
app/models/project_auto_devops.rb
app/models/project_auto_devops.rb
+6
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+9
-5
No files found.
app/models/ci/build.rb
View file @
82ed2a09
...
@@ -217,6 +217,7 @@ module Ci
...
@@ -217,6 +217,7 @@ module Ci
variables
+=
runner
.
predefined_variables
if
runner
variables
+=
runner
.
predefined_variables
if
runner
variables
+=
project
.
container_registry_variables
variables
+=
project
.
container_registry_variables
variables
+=
project
.
deployment_variables
if
has_environment?
variables
+=
project
.
deployment_variables
if
has_environment?
variables
+=
project
.
auto_devops_variables
variables
+=
yaml_variables
variables
+=
yaml_variables
variables
+=
user_variables
variables
+=
user_variables
variables
+=
project
.
group
.
secret_variables_for
(
ref
,
project
).
map
(
&
:to_runner_variable
)
if
project
.
group
variables
+=
project
.
group
.
secret_variables_for
(
ref
,
project
).
map
(
&
:to_runner_variable
)
if
project
.
group
...
...
app/models/ci/pipeline.rb
View file @
82ed2a09
...
@@ -325,14 +325,10 @@ module Ci
...
@@ -325,14 +325,10 @@ module Ci
end
end
def
set_config_source
def
set_config_source
self
.
config_source
=
if
ci_yaml_from_repo
if
project
self
.
config_source
=
:repository_source
case
elsif
implied_ci_yaml_file
when
ci_yaml_from_repo
then
:repository_source
self
.
config_source
=
:auto_devops_source
when
implied_ci_yaml_file
then
:auto_devops_source
end
else
:unknown_source
end
end
end
end
...
@@ -461,12 +457,17 @@ module Ci
...
@@ -461,12 +457,17 @@ module Ci
private
private
def
ci_yaml_from_repo
def
ci_yaml_from_repo
return
unless
project
return
unless
sha
project
.
repository
.
gitlab_ci_yml_for
(
sha
,
ci_yaml_file_path
)
project
.
repository
.
gitlab_ci_yml_for
(
sha
,
ci_yaml_file_path
)
rescue
GRPC
::
NotFound
,
Rugged
::
ReferenceError
,
GRPC
::
Internal
rescue
GRPC
::
NotFound
,
Rugged
::
ReferenceError
,
GRPC
::
Internal
nil
nil
end
end
def
implied_ci_yaml_file
def
implied_ci_yaml_file
return
unless
project
if
project
.
auto_devops_enabled?
if
project
.
auto_devops_enabled?
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
end
end
...
...
app/models/project.rb
View file @
82ed2a09
...
@@ -1390,7 +1390,7 @@ class Project < ActiveRecord::Base
...
@@ -1390,7 +1390,7 @@ class Project < ActiveRecord::Base
end
end
def
predefined_variables
def
predefined_variables
variables
=
[
[
{
key:
'CI_PROJECT_ID'
,
value:
id
.
to_s
,
public:
true
},
{
key:
'CI_PROJECT_ID'
,
value:
id
.
to_s
,
public:
true
},
{
key:
'CI_PROJECT_NAME'
,
value:
path
,
public:
true
},
{
key:
'CI_PROJECT_NAME'
,
value:
path
,
public:
true
},
{
key:
'CI_PROJECT_PATH'
,
value:
full_path
,
public:
true
},
{
key:
'CI_PROJECT_PATH'
,
value:
full_path
,
public:
true
},
...
@@ -1398,12 +1398,6 @@ class Project < ActiveRecord::Base
...
@@ -1398,12 +1398,6 @@ class Project < ActiveRecord::Base
{
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
,
public:
true
},
{
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
,
public:
true
},
{
key:
'CI_PROJECT_URL'
,
value:
web_url
,
public:
true
}
{
key:
'CI_PROJECT_URL'
,
value:
web_url
,
public:
true
}
]
]
if
auto_devops_enabled?
&&
auto_devops
&
.
domain
variables
<<
{
key:
'AUTO_DEVOPS_DOMAIN'
,
value:
auto_devops
.
domain
,
public:
true
}
end
variables
end
end
def
container_registry_variables
def
container_registry_variables
...
@@ -1440,6 +1434,12 @@ class Project < ActiveRecord::Base
...
@@ -1440,6 +1434,12 @@ class Project < ActiveRecord::Base
deployment_service
.
predefined_variables
deployment_service
.
predefined_variables
end
end
def
auto_devops_variables
return
[]
unless
auto_devops_enabled?
auto_devops
&
.
variables
||
[]
end
def
append_or_update_attribute
(
name
,
value
)
def
append_or_update_attribute
(
name
,
value
)
old_values
=
public_send
(
name
.
to_s
)
# rubocop:disable GitlabSecurity/PublicSend
old_values
=
public_send
(
name
.
to_s
)
# rubocop:disable GitlabSecurity/PublicSend
...
...
app/models/project_auto_devops.rb
View file @
82ed2a09
...
@@ -2,4 +2,10 @@ class ProjectAutoDevops < ActiveRecord::Base
...
@@ -2,4 +2,10 @@ class ProjectAutoDevops < ActiveRecord::Base
belongs_to
:project
belongs_to
:project
validates
:domain
,
presence:
true
,
hostname:
{
allow_numeric_hostname:
true
},
if: :enabled?
validates
:domain
,
presence:
true
,
hostname:
{
allow_numeric_hostname:
true
},
if: :enabled?
def
variables
variables
=
[]
variables
<<
{
key:
'AUTO_DEVOPS_DOMAIN'
,
value:
domain
,
public:
true
}
if
domain
.
present?
variables
end
end
end
spec/models/ci/pipeline_spec.rb
View file @
82ed2a09
...
@@ -832,10 +832,10 @@ describe Ci::Pipeline, :mailer do
...
@@ -832,10 +832,10 @@ describe Ci::Pipeline, :mailer do
describe
'#ci_yaml_file'
do
describe
'#ci_yaml_file'
do
let
(
:implied_yml
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
}
let
(
:implied_yml
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
}
before
{
pipeline
.
detect_ci_yaml_file
}
context
'the source is unknown'
do
context
'the source is unknown'
do
before
{
pipeline
.
unknown_source!
}
before
do
pipeline
.
unknown_source!
end
it
'returns the configuration if found'
do
it
'returns the configuration if found'
do
allow
(
pipeline
.
project
.
repository
).
to
receive
(
:gitlab_ci_yml_for
)
allow
(
pipeline
.
project
.
repository
).
to
receive
(
:gitlab_ci_yml_for
)
...
@@ -854,7 +854,9 @@ describe Ci::Pipeline, :mailer do
...
@@ -854,7 +854,9 @@ describe Ci::Pipeline, :mailer do
end
end
context
'the source is the repository'
do
context
'the source is the repository'
do
before
{
pipeline
.
repository_source!
}
before
do
pipeline
.
repository_source!
end
it
'returns the configuration if found'
do
it
'returns the configuration if found'
do
allow
(
pipeline
.
project
.
repository
).
to
receive
(
:gitlab_ci_yml_for
)
allow
(
pipeline
.
project
.
repository
).
to
receive
(
:gitlab_ci_yml_for
)
...
@@ -867,7 +869,9 @@ describe Ci::Pipeline, :mailer do
...
@@ -867,7 +869,9 @@ describe Ci::Pipeline, :mailer do
end
end
context
'when the source is auto_devops_source'
do
context
'when the source is auto_devops_source'
do
before
{
pipeline
.
auto_devops_source!
}
before
do
pipeline
.
auto_devops_source!
end
it
'finds the implied config'
do
it
'finds the implied config'
do
allow_any_instance_of
(
ApplicationSetting
)
allow_any_instance_of
(
ApplicationSetting
)
...
...
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