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
5328e3b1
Commit
5328e3b1
authored
Nov 09, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make commit an optional arg for environments search
parent
45bd5391
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
31 deletions
+42
-31
app/models/merge_request.rb
app/models/merge_request.rb
+9
-6
app/models/project.rb
app/models/project.rb
+12
-11
app/services/ci/stop_environment_service.rb
app/services/ci/stop_environment_service.rb
+4
-8
spec/models/project_spec.rb
spec/models/project_spec.rb
+17
-6
No files found.
app/models/merge_request.rb
View file @
5328e3b1
...
@@ -692,12 +692,15 @@ class MergeRequest < ActiveRecord::Base
...
@@ -692,12 +692,15 @@ class MergeRequest < ActiveRecord::Base
def
environments
def
environments
return
[]
unless
diff_head_commit
return
[]
unless
diff_head_commit
@environments
||=
@environments
||=
begin
begin
target_envs
=
target_project
.
environments_for
(
envs
=
target_project
.
environments_for
(
target_branch
,
diff_head_commit
,
with_tags:
true
)
target_branch
,
commit:
diff_head_commit
,
with_tags:
true
)
envs
.
concat
(
source_project
.
environments_for
(
source_branch
,
diff_head_commit
))
if
source_project
envs
.
uniq
source_envs
=
source_project
.
environments_for
(
end
source_branch
,
commit:
diff_head_commit
)
if
source_project
(
target_envs
.
to_a
+
source_envs
.
to_a
).
uniq
end
end
end
def
state_human_name
def
state_human_name
...
...
app/models/project.rb
View file @
5328e3b1
...
@@ -1288,19 +1288,20 @@ class Project < ActiveRecord::Base
...
@@ -1288,19 +1288,20 @@ class Project < ActiveRecord::Base
Gitlab
::
Redis
.
with
{
|
redis
|
redis
.
del
(
pushes_since_gc_redis_key
)
}
Gitlab
::
Redis
.
with
{
|
redis
|
redis
.
del
(
pushes_since_gc_redis_key
)
}
end
end
def
environments_for
(
ref
,
commit
,
with_tags:
false
)
def
environments_for
(
ref
,
commit:
nil
,
with_tags:
false
)
environment_ids
=
deployments
.
group
(
:environment_id
).
environments_query
=
with_tags
?
'ref=? OR tag IS TRUE'
:
'ref=?'
select
(
:environment_id
)
environment_ids
=
environment_ids
=
deployments
if
with_tags
.
group
(
:environment_id
)
environment_ids
.
where
(
'ref=? OR tag IS TRUE'
,
ref
)
.
select
(
:environment_id
)
else
.
where
(
environments_query
,
ref
)
environment_ids
.
where
(
ref:
ref
)
end
environments
.
available
.
where
(
id:
environment_ids
).
select
do
|
environment
|
envs
=
environments
.
available
.
where
(
id:
environment_ids
)
environment
.
includes_commit?
(
commit
)
if
commit
envs
.
select
{
|
env
|
env
.
includes_commit?
(
commit
)
}
else
envs
.
to_a
end
end
end
end
...
...
app/services/ci/stop_environment_service.rb
View file @
5328e3b1
...
@@ -5,7 +5,7 @@ module Ci
...
@@ -5,7 +5,7 @@ module Ci
def
execute
(
branch_name
)
def
execute
(
branch_name
)
@ref
=
branch_name
@ref
=
branch_name
return
unless
has_ref
_commit_pair
?
return
unless
has_ref?
return
unless
has_environments?
return
unless
has_environments?
environments
.
each
do
|
environment
|
environments
.
each
do
|
environment
|
...
@@ -17,12 +17,8 @@ module Ci
...
@@ -17,12 +17,8 @@ module Ci
private
private
def
has_ref_commit_pair?
def
has_ref?
ref
&&
commit
@ref
.
present?
end
def
commit
@commit
||=
project
.
commit
(
ref
)
end
end
def
has_environments?
def
has_environments?
...
@@ -30,7 +26,7 @@ module Ci
...
@@ -30,7 +26,7 @@ module Ci
end
end
def
environments
def
environments
@environments
||=
project
.
environments_for
(
ref
,
commit
)
@environments
||=
project
.
environments_for
(
@ref
)
end
end
end
end
end
end
spec/models/project_spec.rb
View file @
5328e3b1
...
@@ -1646,15 +1646,18 @@ describe Project, models: true do
...
@@ -1646,15 +1646,18 @@ describe Project, models: true do
end
end
it
'returns environment when with_tags is set'
do
it
'returns environment when with_tags is set'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
,
with_tags:
true
)).
to
contain_exactly
(
environment
)
expect
(
project
.
environments_for
(
'master'
,
commit:
project
.
commit
,
with_tags:
true
))
.
to
contain_exactly
(
environment
)
end
end
it
'does not return environment when no with_tags is set'
do
it
'does not return environment when no with_tags is set'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
)).
to
be_empty
expect
(
project
.
environments_for
(
'master'
,
commit:
project
.
commit
))
.
to
be_empty
end
end
it
'does not return environment when commit is not part of deployment'
do
it
'does not return environment when commit is not part of deployment'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
(
'feature'
))).
to
be_empty
expect
(
project
.
environments_for
(
'master'
,
commit:
project
.
commit
(
'feature'
)))
.
to
be_empty
end
end
end
end
...
@@ -1664,15 +1667,23 @@ describe Project, models: true do
...
@@ -1664,15 +1667,23 @@ describe Project, models: true do
end
end
it
'returns environment when ref is set'
do
it
'returns environment when ref is set'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
)).
to
contain_exactly
(
environment
)
expect
(
project
.
environments_for
(
'master'
,
commit:
project
.
commit
))
.
to
contain_exactly
(
environment
)
end
end
it
'does not environment when ref is different'
do
it
'does not environment when ref is different'
do
expect
(
project
.
environments_for
(
'feature'
,
project
.
commit
)).
to
be_empty
expect
(
project
.
environments_for
(
'feature'
,
commit:
project
.
commit
))
.
to
be_empty
end
end
it
'does not return environment when commit is not part of deployment'
do
it
'does not return environment when commit is not part of deployment'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
(
'feature'
))).
to
be_empty
expect
(
project
.
environments_for
(
'master'
,
commit:
project
.
commit
(
'feature'
)))
.
to
be_empty
end
it
'returns environment when commit constraint is not set'
do
expect
(
project
.
environments_for
(
'master'
))
.
to
contain_exactly
(
environment
)
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