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
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
Hide 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
...
...
@@ -122,8 +122,8 @@
}
.js-deployment-link
{
display
:
inline-block
;
}
display
:
inline-block
;
}
.mr-widget-body
{
h4
{
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
fa58068b
...
...
@@ -393,33 +393,28 @@ class Projects::MergeRequestsController < Projects::ApplicationController
end
end
environments
=
@merge_request
.
environments
deployments
=
@merge_request
.
deployments
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
}
environment
=
{
name:
environment
.
name
,
id:
environment
.
id
,
url:
namespace_project_environment_path
(
project
.
namespace
,
project
,
environment
),
external_url:
environment
.
external_url
,
deployed_at:
deployment
?
deployment
.
created_at
:
nil
}
if
environment
[
:external_url
]
environment
[
:external_url_formatted
]
=
environment
[
:external_url
].
gsub
(
/\A.*?:\/\//
,
''
)
end
if
environment
[
:deployed_at
]
environment
[
:deployed_at_formatted
]
=
environment
[
:deployed_at
].
to_time
.
in_time_zone
.
to_s
(
:medium
)
end
environments
=
@merge_request
.
environments
.
map
do
|
environment
|
next
unless
can?
(
current_user
,
:read_environment
,
environment
)
deployment
=
environment
.
first_deployment_for
(
@merge_request
.
diff_head_commit
)
environment
=
{
name:
environment
.
name
,
id:
environment
.
id
,
url:
namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
),
external_url:
environment
.
external_url
,
deployed_at:
deployment
?
deployment
.
created_at
:
nil
}
if
environment
[
:external_url
]
environment
[
:external_url_formatted
]
=
environment
[
:external_url
].
gsub
(
/\A.*?:\/\//
,
''
)
end
environment
if
environment
[
:deployed_at
]
environment
[
:deployed_at_formatted
]
=
environment
[
:deployed_at
].
to_time
.
in_time_zone
.
to_s
(
:medium
)
end
end
environment
end
.
compact
response
=
{
title:
merge_request
.
title
,
...
...
app/models/environment.rb
View file @
fa58068b
...
...
@@ -48,12 +48,13 @@ class Environment < ActiveRecord::Base
self
.
name
==
"production"
end
def
deployment_id
_for
(
commit
)
def
first_deployment
_for
(
commit
)
ref
=
project
.
repository
.
ref_name_for_sha
(
ref_path
,
commit
.
sha
)
return
nil
unless
ref
ref
.
split
(
'/'
).
last
.
to_i
deployment_id
=
ref
.
split
(
'/'
).
last
.
to_i
deployments
.
find
(
deployment_id
)
end
def
ref_path
...
...
app/models/merge_request.rb
View file @
fa58068b
...
...
@@ -685,24 +685,18 @@ class MergeRequest < ActiveRecord::Base
!
pipeline
||
pipeline
.
success?
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
return
[]
unless
diff_head_commit
environments
=
source_project
.
environments_for
(
source_branch
,
diff_head_commit
)
environments
+=
target_project
.
environments_for
(
target_branch
,
diff_head_commit
,
with_tags:
true
)
@environments
||=
begin
environments
=
source_project
.
environments_for
(
source_branch
,
diff_head_commit
)
environments
+=
target_project
.
environments_for
(
target_branch
,
diff_head_commit
,
with_tags:
true
)
environments
.
uniq
environments
.
uniq
end
end
def
state_human_name
...
...
app/models/repository.rb
View file @
fa58068b
...
...
@@ -719,8 +719,8 @@ class Repository
end
end
def
ref_name_for_sha
(
environment_
ref_path
,
sha
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
for-each-ref --count=1
#{
environment_
ref_path
}
--contains
#{
sha
}
)
def
ref_name_for_sha
(
ref_path
,
sha
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
for-each-ref --count=1
#{
ref_path
}
--contains
#{
sha
}
)
# Not found -> ["", 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