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
Tatuya Kamada
gitlab-ce
Commits
fa58068b
Commit
fa58068b
authored
Oct 05, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ci_status on MergeRequestController
parent
8a1064d7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
45 deletions
+35
-45
app/assets/stylesheets/pages/merge_requests.scss
app/assets/stylesheets/pages/merge_requests.scss
+2
-2
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+20
-25
app/models/environment.rb
app/models/environment.rb
+3
-2
app/models/merge_request.rb
app/models/merge_request.rb
+8
-14
app/models/repository.rb
app/models/repository.rb
+2
-2
No files found.
app/assets/stylesheets/pages/merge_requests.scss
View file @
fa58068b
app/controllers/projects/merge_requests_controller.rb
View file @
fa58068b
...
@@ -393,18 +393,14 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -393,18 +393,14 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
end
end
environments
=
@merge_request
.
environments
environments
=
@merge_request
.
environments
.
map
do
|
environment
|
deployments
=
@merge_request
.
deployments
next
unless
can?
(
current_user
,
:read_environment
,
environment
)
if
environments
.
present?
environments
=
environments
.
select
{
|
e
|
can?
(
current_user
,
:read_environment
,
e
)
}.
map
do
|
environment
|
project
=
environment
.
project
deployment
=
deployments
.
find
{
|
d
|
d
.
environment
==
environment
}
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
environment
=
{
environment
=
{
name:
environment
.
name
,
name:
environment
.
name
,
id:
environment
.
id
,
id:
environment
.
id
,
url:
namespace_project_environment_path
(
project
.
namespace
,
project
,
environment
),
url:
namespace_project_environment_path
(
@project
.
namespace
,
@
project
,
environment
),
external_url:
environment
.
external_url
,
external_url:
environment
.
external_url
,
deployed_at:
deployment
?
deployment
.
created_at
:
nil
deployed_at:
deployment
?
deployment
.
created_at
:
nil
}
}
...
@@ -418,8 +414,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -418,8 +414,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
environment
environment
end
end
.
compact
end
response
=
{
response
=
{
title:
merge_request
.
title
,
title:
merge_request
.
title
,
...
...
app/models/environment.rb
View file @
fa58068b
...
@@ -48,12 +48,13 @@ class Environment < ActiveRecord::Base
...
@@ -48,12 +48,13 @@ class Environment < ActiveRecord::Base
self
.
name
==
"production"
self
.
name
==
"production"
end
end
def
deployment_id
_for
(
commit
)
def
first_deployment
_for
(
commit
)
ref
=
project
.
repository
.
ref_name_for_sha
(
ref_path
,
commit
.
sha
)
ref
=
project
.
repository
.
ref_name_for_sha
(
ref_path
,
commit
.
sha
)
return
nil
unless
ref
return
nil
unless
ref
ref
.
split
(
'/'
).
last
.
to_i
deployment_id
=
ref
.
split
(
'/'
).
last
.
to_i
deployments
.
find
(
deployment_id
)
end
end
def
ref_path
def
ref_path
...
...
app/models/merge_request.rb
View file @
fa58068b
...
@@ -685,18 +685,11 @@ class MergeRequest < ActiveRecord::Base
...
@@ -685,18 +685,11 @@ class MergeRequest < ActiveRecord::Base
!
pipeline
||
pipeline
.
success?
!
pipeline
||
pipeline
.
success?
end
end
def
deployments
deployment_ids
=
environments
.
map
do
|
environment
|
environment
.
deployment_id_for
(
diff_head_commit
)
end
.
compact
Deployment
.
find
(
deployment_ids
)
end
def
environments
def
environments
return
[]
unless
diff_head_commit
return
[]
unless
diff_head_commit
@environments
||=
begin
environments
=
source_project
.
environments_for
(
environments
=
source_project
.
environments_for
(
source_branch
,
diff_head_commit
)
source_branch
,
diff_head_commit
)
environments
+=
target_project
.
environments_for
(
environments
+=
target_project
.
environments_for
(
...
@@ -704,6 +697,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -704,6 +697,7 @@ class MergeRequest < ActiveRecord::Base
environments
.
uniq
environments
.
uniq
end
end
end
def
state_human_name
def
state_human_name
if
merged?
if
merged?
...
...
app/models/repository.rb
View file @
fa58068b
...
@@ -719,8 +719,8 @@ class Repository
...
@@ -719,8 +719,8 @@ class Repository
end
end
end
end
def
ref_name_for_sha
(
environment_
ref_path
,
sha
)
def
ref_name_for_sha
(
ref_path
,
sha
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
for-each-ref --count=1
#{
environment_
ref_path
}
--contains
#{
sha
}
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
for-each-ref --count=1
#{
ref_path
}
--contains
#{
sha
}
)
# Not found -> ["", 0]
# Not found -> ["", 0]
# Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]
# Found -> ["b8d95eb4969eefacb0a58f6a28f6803f8070e7b9 commit\trefs/environments/production/77\n", 0]
...
...
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