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
def
environments
return
[]
unless
diff_head_commit
@environments
||=
begin
envs
=
target_project
.
environments_for
(
target_branch
,
diff_head_commit
,
with_tags:
true
)
envs
.
concat
(
source_project
.
environments_for
(
source_branch
,
diff_head_commit
))
if
source_project
envs
.
uniq
end
@environments
||=
begin
target_envs
=
target_project
.
environments_for
(
target_branch
,
commit:
diff_head_commit
,
with_tags:
true
)
source_envs
=
source_project
.
environments_for
(
source_branch
,
commit:
diff_head_commit
)
if
source_project
(
target_envs
.
to_a
+
source_envs
.
to_a
).
uniq
end
end
def
state_human_name
...
...
app/models/project.rb
View file @
5328e3b1
...
...
@@ -1288,19 +1288,20 @@ class Project < ActiveRecord::Base
Gitlab
::
Redis
.
with
{
|
redis
|
redis
.
del
(
pushes_since_gc_redis_key
)
}
end
def
environments_for
(
ref
,
commit
,
with_tags:
false
)
environment_ids
=
deployments
.
group
(
:environment_id
).
select
(
:environment_id
)
def
environments_for
(
ref
,
commit:
nil
,
with_tags:
false
)
environments_query
=
with_tags
?
'ref=? OR tag IS TRUE'
:
'ref=?'
environment_ids
=
if
with_tags
environment_ids
.
where
(
'ref=? OR tag IS TRUE'
,
ref
)
else
environment_ids
.
where
(
ref:
ref
)
end
environment_ids
=
deployments
.
group
(
:environment_id
)
.
select
(
:environment_id
)
.
where
(
environments_query
,
ref
)
environments
.
available
.
where
(
id:
environment_ids
).
select
do
|
environment
|
environment
.
includes_commit?
(
commit
)
envs
=
environments
.
available
.
where
(
id:
environment_ids
)
if
commit
envs
.
select
{
|
env
|
env
.
includes_commit?
(
commit
)
}
else
envs
.
to_a
end
end
...
...
app/services/ci/stop_environment_service.rb
View file @
5328e3b1
...
...
@@ -5,7 +5,7 @@ module Ci
def
execute
(
branch_name
)
@ref
=
branch_name
return
unless
has_ref
_commit_pair
?
return
unless
has_ref?
return
unless
has_environments?
environments
.
each
do
|
environment
|
...
...
@@ -17,12 +17,8 @@ module Ci
private
def
has_ref_commit_pair?
ref
&&
commit
end
def
commit
@commit
||=
project
.
commit
(
ref
)
def
has_ref?
@ref
.
present?
end
def
has_environments?
...
...
@@ -30,7 +26,7 @@ module Ci
end
def
environments
@environments
||=
project
.
environments_for
(
ref
,
commit
)
@environments
||=
project
.
environments_for
(
@ref
)
end
end
end
spec/models/project_spec.rb
View file @
5328e3b1
...
...
@@ -1646,15 +1646,18 @@ describe Project, models: true do
end
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
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
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
...
...
@@ -1664,15 +1667,23 @@ describe Project, models: true do
end
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
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
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
...
...
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